-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcli.js
executable file
·42 lines (39 loc) · 1.07 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env node
const path = require('path')
const { init, klap, read, log, error, info } = require('./dist/index.js')
const { name, version } = require('./package.json')
const command = process.argv[2]
const defaultEnvironment = {
build: 'production',
prod: 'production',
watch: 'development',
start: 'development',
}
;(async (pkg) => {
switch (command) {
case 'init':
log(`${name}@${version} - Initializing your package...`)
await init(command)
break
case 'build':
case 'prod':
case 'watch':
case 'start':
log(`${name}@${version} - Working on ${command}...`)
process.env.NODE_ENV = process.env.NODE_ENV || defaultEnvironment[command]
pkg = JSON.parse(await read(path.join(process.cwd(), 'package.json')))
await klap(command, pkg)
break
case 'help':
info(`
${name}@${version} - Usage
klap init - create a new package.
klap build - bundle your package, in production mode.
klap watch - bundle your package and watch for changes.
klap start - start a development server.
`)
break
default:
error('No Such Command !!')
}
})()