UNPKG

1.84 kBJavaScriptView Raw
1// Import process for deno compat
2import process from 'process'
3// Import caterpillar [Caterpillar](https://github.com/bevry/caterpillar) for logging
4import { Logger } from 'caterpillar'
5import Filter from 'caterpillar-filter'
6import Human from 'caterpillar-human'
7// Import the package used to get the value of CLI arguments
8import getarg from 'get-cli-arg'
9// Import out projectz utility
10import { Projectz } from './index.js'
11async function main() {
12 // Compile
13 if (process.argv.includes('compile')) {
14 // fetch
15 const p = getarg('path')
16 const d = getarg('verbose')
17 // bc upgrade
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 // Prepare our logging configuration
31 const level = d ? 7 : 6
32 // Setup our logging
33 const logger = new Logger({ level })
34 const filter = new Filter()
35 const human = new Human()
36 // Pipe logger output to filter, then filter output to stdout
37 logger.pipe(filter).pipe(human).pipe(process.stdout)
38 // Compile
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 // error
47 logger.log('err', err.stack)
48 return process.exit(1)
49 }
50 // Done
51 logger.log('info', 'Completed successfully')
52 } else {
53 // output help
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}
64main()