UNPKG

1.83 kBPlain TextView Raw
1// Import process for deno compat
2import process from 'process'
3
4// Import caterpillar [Caterpillar](https://github.com/bevry/caterpillar) for logging
5import { Logger, Filter, Human } from 'caterpillar'
6
7// Import the package used to get the value of CLI arguments
8import getarg from 'get-cli-arg'
9
10// Import out projectz utility
11import { Projectz } from './index.js'
12
13async function main(): Promise<void> {
14 // Compile
15 if (process.argv.includes('compile')) {
16 // fetch
17 const p = getarg('path')
18 const d = getarg('verbose')
19
20 // bc upgrade
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 // Prepare our logging configuration
35 const level = d ? 7 : 6
36
37 // Setup our logging
38 const logger = new Logger({ lineLevel: level })
39 const filter = new Filter({ filterLevel: level })
40 const human = new Human()
41
42 // Pipe logger output to filter, then filter output to stdout
43 logger.pipe(filter).pipe(human).pipe(process.stdout)
44
45 // Compile
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 // error
54 logger.log('err', err.stack)
55 return process.exit(1)
56 }
57
58 // Done
59 logger.log('info', 'Completed successfully')
60 } else {
61 // output help
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
73main()