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