This repository has been archived by the owner on May 11, 2024. It is now read-only.
forked from liriliri/luna
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathluna.js
executable file
·121 lines (99 loc) · 3.14 KB
/
luna.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env node
const program = require('commander')
const fs = require('licia/fs')
const {
runScript,
wrap,
resolve,
readComponentConfig,
stringify,
createWebpackConfig,
createKarmaConf,
} = require('../lib/util')
const doc = require('../lib/doc')
const build = require('../lib/build')
const format = wrap(async function (component) {
await runScript('lsla', [
'prettier',
`src/${component}/**/*.{ts,tsx,js,html,json,css,scss}`,
'--write',
])
})
const dev = wrap(async function (component) {
await createWebpackConfig(component)
await runScript('webpack', [
'--config',
`./src/${component}/webpack.config.js`,
'--mode=development',
'--watch',
])
})
const test = wrap(async function (component, options) {
await createWebpackConfig(component)
await createKarmaConf(component)
const args = ['start', `./src/${component}/karma.conf.js`]
if (options.headless !== false) {
args.push('--headless')
}
await runScript('karma', args)
}, 'test')
const install = wrap(async function (component) {
await runScript('npm', ['install'], {
cwd: resolve(`../src/${component}/`),
})
}, 'install')
const lint = wrap(async function (component) {
await runScript('eslint', [`src/${component}/**/*.ts`])
})
const genIcon = wrap(async function (component) {
await runScript('lsla', [
'genIcon',
'--input',
`src/${component}/icon`,
'--output',
`src/${component}/icon.css`,
'--name',
`luna-${component}-icon`,
])
await runScript('lsla', ['prettier', `src/${component}/icon.css`, '--write'])
}, 'icon')
const update = async function () {
const dirs = await fs.readdir(resolve('../src'))
const index = {}
const tsConfig = JSON.parse(await fs.readFile(resolve('../tsconfig.json')))
for (let i = 0, len = dirs.length; i < len; i++) {
const dir = dirs[i]
if (await fs.exists(resolve(`../src/${dir}/package.json`))) {
index[dir] = readComponentConfig(dir)
tsConfig.compilerOptions.paths[`luna-${dir}`] = [`src/${dir}/index`]
}
}
const INDEX_OUTPUT_PATH = resolve('../index.json')
await fs.writeFile(INDEX_OUTPUT_PATH, stringify(index), 'utf8')
console.log('Index file generated: ' + INDEX_OUTPUT_PATH)
await fs.writeFile(resolve('../tsconfig.json'), stringify(tsConfig), 'utf8')
console.log('Tsconfig file updated')
}
program.command('format [component]').description('format code').action(format)
program
.command('dev <component>')
.description('start webpack-dev-server')
.action(dev)
program.command('build [component]').description('build package').action(build)
program.command('lint [component]').description('lint code').action(lint)
program
.command('genIcon [component]')
.description('generate icon file')
.action(genIcon)
program
.command('test [component]')
.option('--no-headless', 'do not use headless mode')
.description('run test')
.action(test)
program
.command('install [component]')
.description('install dependencies')
.action(install)
program.command('update').description('update index.json').action(update)
program.command('doc [component]').description('generate readme').action(doc)
program.parse(process.argv)