Use @rondo/argparse for build script

This commit is contained in:
Jerko Steiner 2019-08-05 22:25:28 +07:00
parent cea9bc0dd1
commit 7ea1c34428
6 changed files with 34 additions and 28 deletions

3
package-lock.json generated
View File

@ -2112,6 +2112,9 @@
"url-template": "^2.0.8" "url-template": "^2.0.8"
} }
}, },
"@rondo/argparse": {
"version": "file:packages/argparse"
},
"@rondo/client": { "@rondo/client": {
"version": "file:packages/client" "version": "file:packages/client"
}, },

View File

@ -10,5 +10,5 @@
"dependencies": {}, "dependencies": {},
"types": "lib/index.d.ts", "types": "lib/index.d.ts",
"devDependencies": {}, "devDependencies": {},
"module": "lib/index.js" "main": "lib/index.js"
} }

View File

@ -1,30 +1,30 @@
import {run} from '../run'
import {join} from 'path'
import {findNodeModules} from '../modules'
import * as fs from 'fs' import * as fs from 'fs'
import * as p from 'path' 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' const tsc = 'ttsc'
export async function build(path: string = '.') { export async function build(...argv: string[]) {
await run(tsc, ['--build', path]) const {esm, project, watch} = argparse({
} project: {
type: 'string',
export async function buildEsm(path: string = '.') { alias: 'p',
await run(tsc, ['--build', join(path, 'tsconfig.esm.json')]) default: '.',
} },
esm: {
export async function watch(path: string = '.') { type: 'boolean',
await run(tsc, ['--build', '--watch', '--preserveWatchOutput', path]) },
} watch: {
type: 'boolean',
export async function watchEsm(path: string = '.') { alias: 'w',
await run(tsc, [ },
'--build', })(argv)
'--watch', const path = esm ? join(project, 'tsconfig.esm.json') : project
'--preserveWatchOutput', const watchArgs = watch ? ['--watch', '--preserveWatchOutput'] : []
join(path, 'tsconfig.esm.json'), await run(tsc, ['--build', path, ...watchArgs])
])
} }
export async function test(...args: string[]) { export async function test(...args: string[]) {
@ -90,7 +90,7 @@ export async function uglify(path: string = '.') {
} }
export async function js(path: string = '.') { export async function js(path: string = '.') {
await buildEsm(path) await build(...['-p', path, '--esm'])
await browserify(path) await browserify(path)
await uglify(path) await uglify(path)
} }
@ -134,9 +134,9 @@ export async function watchCss(path = '.') {
} }
export async function frontend(path = '.') { export async function frontend(path = '.') {
await buildEsm(path) await build(...['-p', path, '--esm'])
const promises = [ const promises = [
watchEsm(path), build(...['-p', path, '--watch', '--esm']),
watchJs(path), watchJs(path),
watchCss(path), watchCss(path),
] ]

View File

@ -17,7 +17,7 @@ async function run(...argv: string[]) {
if (typeof require !== 'undefined' && require.main === module) { if (typeof require !== 'undefined' && require.main === module) {
run(...process.argv.slice(2)) run(...process.argv.slice(2))
.catch(err => { .catch(err => {
console.log('> ' + err.message) console.log('> ' + err.stack)
process.exit(1) process.exit(1)
}) })
} }

View File

@ -3,5 +3,7 @@
"compilerOptions": { "compilerOptions": {
"outDir": "esm" "outDir": "esm"
}, },
"references": [] "references": [
{"path": "../argparse/tsconfig.esm.json"}
]
} }

View File

@ -5,5 +5,6 @@
"rootDir": "src" "rootDir": "src"
}, },
"references": [ "references": [
{"path": "../argparse"}
] ]
} }