Add test @rondo/scripts package for CLI

This commit is contained in:
Jerko Steiner 2019-07-31 10:50:27 +08:00
parent dde96b41d3
commit e79008cf0f
9 changed files with 1339 additions and 718 deletions

2018
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -50,7 +50,7 @@
"esmify": "git+https://github.com/jeremija/esmify.git",
"history": "^4.9.0",
"jest": "^24.5.0",
"lerna": "^3.14.1",
"lerna": "^3.16.4",
"loose-envify": "^1.4.0",
"marked": "^0.7.0",
"mysql": "^2.16.0",

4
packages/scripts/package-lock.json generated Normal file
View File

@ -0,0 +1,4 @@
{
"name": "@rondo/scripts",
"lockfileVersion": 1
}

View File

@ -7,6 +7,9 @@
"compile": "tsc",
"clean": "rm -rf lib/"
},
"bin": {
"rondo": "./lib/index.js"
},
"dependencies": {},
"types": "lib/index.d.ts",
"devDependencies": {},

View File

@ -0,0 +1 @@
export type TCommand = (...argv: string[]) => Promise<void>

View File

@ -0,0 +1,8 @@
import * as childProcess from 'child_process'
export async function build(path: string) {
// TODO fix this
await childProcess.spawn('npx', ['ttsc', '--build', path], {
stdio: 'inherit',
})
}

View File

@ -0,0 +1,3 @@
export async function help() {
console.log('Usage help')
}

View File

@ -0,0 +1,2 @@
export * from './help'
export * from './build'

View File

@ -0,0 +1,16 @@
#!/usr/bin/env node
import * as commands from './commands'
import {TCommand} from './TCommand'
async function run(...argv: string[]) {
const commandName = argv[0] || 'help'
if (!(commandName in commands)) {
throw new Error('Command not found:' + commandName)
}
const command = (commands as any)[commandName] as TCommand
await command(...argv.slice(1))
}
if (typeof require !== 'undefined' && require.main === module) {
run(...process.argv.slice(2))
}