Skip to content

Commit

Permalink
Closes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
Konard committed Mar 24, 2024
1 parent 66db652 commit 1f31d63
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
27 changes: 20 additions & 7 deletions automation/build.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import * as fs from 'fs';
import * as fs from 'fs/promises';
import pkg from '../deep.json' assert { type: 'json' };

const encoding = 'utf8';

const [installCode] = pkg.data.filter(l => l.id === "installCode");
installCode.value.value = fs.readFileSync('handlers/install-code.ts', encoding);
async function handlers2deepJson() {
const operations = [];
const installCode = pkg.data.find(l => l.id === "installCode");
if (installCode && installCode.value) {
operations.push((async () => {
installCode.value.value = await fs.readFile('handlers/install-code.ts', encoding);
})());
}
const publishCode = pkg.data.find(l => l.id === "publishCode");
if (publishCode && publishCode.value) {
operations.push((async () => {
publishCode.value.value = await fs.readFile('handlers/publish-code.ts', encoding);
})());
}
await Promise.all(operations);

const [publishCode] = pkg.data.filter(l => l.id === "publishCode");
publishCode.value.value = fs.readFileSync('handlers/publish-code.ts', encoding);
await fs.writeFile('deep.json', JSON.stringify(pkg, null, 2), encoding);

fs.writeFileSync('deep.json', JSON.stringify(pkg, null, 2), encoding);
console.log('deep.json build complete (code of handlers from `./handlers` is embedded into deep.json)');
}

console.log('deep.json build complete');
handlers2deepJson().catch(console.error);
21 changes: 21 additions & 0 deletions automation/unbuild.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as fs from 'fs/promises';
import pkg from '../deep.json' assert { type: 'json' };

const encoding = 'utf8';

async function deepJson2handlers() {
const operations = [];
const installCode = pkg.data.find(l => l.id === "installCode");
if (installCode && installCode.value) {
operations.push(fs.writeFile('handlers/install-code.ts', installCode.value.value, encoding));
}
const publishCode = pkg.data.find(l => l.id === "publishCode");
if (publishCode && publishCode.value) {
operations.push(fs.writeFile('handlers/publish-code.ts', publishCode.value.value, encoding));
}
await Promise.all(operations);

console.log('`deep.json` unbuild complete (handlers are extracted from `deep.json` to `./handlers`)');
}

deepJson2handlers().catch(console.error);

0 comments on commit 1f31d63

Please sign in to comment.