diff --git a/packages/psm-tool/app/.npmignore b/packages/psm-tool/app/.npmignore new file mode 100644 index 00000000000..48f089089fe --- /dev/null +++ b/packages/psm-tool/app/.npmignore @@ -0,0 +1 @@ +.clasp.json diff --git a/packages/psm-tool/package.json b/packages/psm-tool/package.json index 4b10952f353..e3684e75b48 100644 --- a/packages/psm-tool/package.json +++ b/packages/psm-tool/package.json @@ -27,7 +27,9 @@ "./package.json": "./package.json" }, "scripts": { - "build": "mkdir -p app/build; sed 's/^export .*//' src/psm-lib.js >app/build/psm-lib.js", + "build": "yarn build:script && yarn build:app", + "build:script": "mkdir -p dist; node scripts/pasteImports.js dist/psm-tool src/psm-lib.js scripts/psm-tool.js", + "build:app": "mkdir -p app/build; sed 's/^export .*//' src/psm-lib.js >app/build/psm-lib.js", "clasp:push": "yarn build && cd app; clasp push", "test": "ava", "lint-fix": "yarn lint:eslint --fix", @@ -45,13 +47,17 @@ "*.ts", "LICENSE*", "app", + "dist", "src" ], "publishConfig": { "access": "public" }, "eslintConfig": { - "ignorePatterns": "build/*" + "ignorePatterns": [ + "dist/*", + "build/*" + ] }, "ava": { "files": [ diff --git a/packages/psm-tool/scripts/pasteImports.js b/packages/psm-tool/scripts/pasteImports.js new file mode 100644 index 00000000000..e54f1c9d07e --- /dev/null +++ b/packages/psm-tool/scripts/pasteImports.js @@ -0,0 +1,33 @@ +// @ts-check + +const dieTrying = () => { + throw Error(); +}; + +/** + * + * @param {string[]} argv + * @param {object} io + * @param {typeof import('fs').promises.readFile} io.readFile + * @param {typeof import('fs').promises.writeFile} io.writeFile + */ +const main = async (argv, { readFile, writeFile }) => { + const dest = argv.shift() || dieTrying(); + const mainFn = argv.pop() || dieTrying(); + const parts = []; + for await (const fn of argv) { + const txt = await readFile(fn, 'utf-8'); + parts.push(txt.replace(/^export /gm, '')); + } + const txt = await readFile(mainFn, 'utf-8'); + const script = txt.replace(/import {[^}]*} from [^;]+;/m, parts.join('\n')); + + await writeFile(dest, script); + console.info('built', dest, 'from', mainFn, 'with', argv); +}; + +(async () => { + // eslint-disable-next-line no-undef + const { argv } = process; + import('fs').then(fs => main(argv.slice(2), fs.promises)); +})().catch(err => console.error(err));