Add test @rondo/scripts package for CLI
This commit is contained in:
parent
dde96b41d3
commit
e79008cf0f
2018
package-lock.json
generated
2018
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -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
4
packages/scripts/package-lock.json
generated
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "@rondo/scripts",
|
||||
"lockfileVersion": 1
|
||||
}
|
||||
@ -7,6 +7,9 @@
|
||||
"compile": "tsc",
|
||||
"clean": "rm -rf lib/"
|
||||
},
|
||||
"bin": {
|
||||
"rondo": "./lib/index.js"
|
||||
},
|
||||
"dependencies": {},
|
||||
"types": "lib/index.d.ts",
|
||||
"devDependencies": {},
|
||||
|
||||
1
packages/scripts/src/TCommand.ts
Normal file
1
packages/scripts/src/TCommand.ts
Normal file
@ -0,0 +1 @@
|
||||
export type TCommand = (...argv: string[]) => Promise<void>
|
||||
8
packages/scripts/src/commands/build.ts
Normal file
8
packages/scripts/src/commands/build.ts
Normal 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',
|
||||
})
|
||||
}
|
||||
3
packages/scripts/src/commands/help.ts
Normal file
3
packages/scripts/src/commands/help.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export async function help() {
|
||||
console.log('Usage help')
|
||||
}
|
||||
2
packages/scripts/src/commands/index.ts
Normal file
2
packages/scripts/src/commands/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './help'
|
||||
export * from './build'
|
||||
@ -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))
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user