diff --git a/package-lock.json b/package-lock.json index ef37ee8..8807ce5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2112,6 +2112,9 @@ "url-template": "^2.0.8" } }, + "@rondo/argparse": { + "version": "file:packages/argparse" + }, "@rondo/client": { "version": "file:packages/client" }, diff --git a/packages/argparse/package.json b/packages/argparse/package.json index e4ba783..3df6863 100644 --- a/packages/argparse/package.json +++ b/packages/argparse/package.json @@ -10,5 +10,5 @@ "dependencies": {}, "types": "lib/index.d.ts", "devDependencies": {}, - "module": "lib/index.js" + "main": "lib/index.js" } diff --git a/packages/scripts/src/commands/build.ts b/packages/scripts/src/commands/build.ts index cfe5908..cc2985b 100644 --- a/packages/scripts/src/commands/build.ts +++ b/packages/scripts/src/commands/build.ts @@ -1,30 +1,30 @@ -import {run} from '../run' -import {join} from 'path' -import {findNodeModules} from '../modules' import * as fs from 'fs' import * as p from 'path' +import {argparse} from '@rondo/argparse' +import {findNodeModules} from '../modules' +import {join} from 'path' +import {run} from '../run' const tsc = 'ttsc' -export async function build(path: string = '.') { - await run(tsc, ['--build', path]) -} - -export async function buildEsm(path: string = '.') { - await run(tsc, ['--build', join(path, 'tsconfig.esm.json')]) -} - -export async function watch(path: string = '.') { - await run(tsc, ['--build', '--watch', '--preserveWatchOutput', path]) -} - -export async function watchEsm(path: string = '.') { - await run(tsc, [ - '--build', - '--watch', - '--preserveWatchOutput', - join(path, 'tsconfig.esm.json'), - ]) +export async function build(...argv: string[]) { + const {esm, project, watch} = argparse({ + project: { + type: 'string', + alias: 'p', + default: '.', + }, + esm: { + type: 'boolean', + }, + watch: { + type: 'boolean', + alias: 'w', + }, + })(argv) + const path = esm ? join(project, 'tsconfig.esm.json') : project + const watchArgs = watch ? ['--watch', '--preserveWatchOutput'] : [] + await run(tsc, ['--build', path, ...watchArgs]) } export async function test(...args: string[]) { @@ -90,7 +90,7 @@ export async function uglify(path: string = '.') { } export async function js(path: string = '.') { - await buildEsm(path) + await build(...['-p', path, '--esm']) await browserify(path) await uglify(path) } @@ -134,9 +134,9 @@ export async function watchCss(path = '.') { } export async function frontend(path = '.') { - await buildEsm(path) + await build(...['-p', path, '--esm']) const promises = [ - watchEsm(path), + build(...['-p', path, '--watch', '--esm']), watchJs(path), watchCss(path), ] diff --git a/packages/scripts/src/index.ts b/packages/scripts/src/index.ts index 94e560e..015e533 100644 --- a/packages/scripts/src/index.ts +++ b/packages/scripts/src/index.ts @@ -17,7 +17,7 @@ async function run(...argv: string[]) { if (typeof require !== 'undefined' && require.main === module) { run(...process.argv.slice(2)) .catch(err => { - console.log('> ' + err.message) + console.log('> ' + err.stack) process.exit(1) }) } diff --git a/packages/scripts/tsconfig.esm.json b/packages/scripts/tsconfig.esm.json index 915284d..8ebdd05 100644 --- a/packages/scripts/tsconfig.esm.json +++ b/packages/scripts/tsconfig.esm.json @@ -3,5 +3,7 @@ "compilerOptions": { "outDir": "esm" }, - "references": [] + "references": [ + {"path": "../argparse/tsconfig.esm.json"} + ] } diff --git a/packages/scripts/tsconfig.json b/packages/scripts/tsconfig.json index 94e864b..2680de9 100644 --- a/packages/scripts/tsconfig.json +++ b/packages/scripts/tsconfig.json @@ -5,5 +5,6 @@ "rootDir": "src" }, "references": [ + {"path": "../argparse"} ] }