1 |
|
2 | import process from 'process'
|
3 |
|
4 | import { Logger } from 'caterpillar'
|
5 | import Filter from 'caterpillar-filter'
|
6 | import Human from 'caterpillar-human'
|
7 |
|
8 | import getarg from 'get-cli-arg'
|
9 |
|
10 | import { Projectz } from './index.js'
|
11 | async function main() {
|
12 |
|
13 | if (process.argv.includes('compile')) {
|
14 |
|
15 | const p = getarg('path')
|
16 | const d = getarg('verbose')
|
17 |
|
18 | if (process.argv.includes('-p')) {
|
19 | console.log(
|
20 | 'projecz now requires -p argument to be specifie via --path=value'
|
21 | )
|
22 | return process.exit(1)
|
23 | }
|
24 | if (process.argv.includes('-d')) {
|
25 | console.log(
|
26 | 'projecz now requires -d argument to be specifie via --verbose'
|
27 | )
|
28 | return process.exit(1)
|
29 | }
|
30 |
|
31 | const level = d ? 7 : 6
|
32 |
|
33 | const logger = new Logger({ level })
|
34 | const filter = new Filter()
|
35 | const human = new Human()
|
36 |
|
37 | logger.pipe(filter).pipe(human).pipe(process.stdout)
|
38 |
|
39 | try {
|
40 | const project = new Projectz({
|
41 | log: logger.log.bind(logger),
|
42 | cwd: p || null,
|
43 | })
|
44 | await project.compile()
|
45 | } catch (err) {
|
46 |
|
47 | logger.log('err', err.stack)
|
48 | return process.exit(1)
|
49 | }
|
50 |
|
51 | logger.log('info', 'Completed successfully')
|
52 | } else {
|
53 |
|
54 | console.log(
|
55 | 'projectz compile: merge our data files and compile our meta files'
|
56 | )
|
57 | console.log('\t--verbose\tOutputs verbose logging')
|
58 | console.log(
|
59 | '\t--path=value\tPath to the project that you wish to work with, defaults to the current working directory'
|
60 | )
|
61 | return process.exit(1)
|
62 | }
|
63 | }
|
64 | main()
|