ergogen/src/cli.js

68 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-06-26 21:00:10 +02:00
#!/usr/bin/env node
2020-06-28 22:35:53 +02:00
// libs
2020-06-07 13:40:26 +02:00
const fs = require('fs-extra')
const path = require('path')
const yaml = require('js-yaml')
2020-05-28 22:18:41 +02:00
const yargs = require('yargs')
2020-06-07 13:40:26 +02:00
2020-06-28 22:35:53 +02:00
// internals
2020-06-26 21:00:10 +02:00
const u = require('./utils')
2020-06-28 22:35:53 +02:00
const io = require('./io')
2020-06-26 21:00:10 +02:00
const points_lib = require('./points')
2020-06-28 22:35:53 +02:00
const outline_lib = require('./outline')
2020-05-30 15:17:53 +02:00
2020-06-28 22:35:53 +02:00
// command line args
2020-06-26 21:00:10 +02:00
2020-05-28 22:18:41 +02:00
const args = yargs
2020-06-07 13:40:26 +02:00
.option('config', {
alias: 'c',
demandOption: true,
2020-06-28 22:35:53 +02:00
describe: 'Config yaml/json file',
2020-06-07 13:40:26 +02:00
type: 'string'
})
.option('output', {
alias: 'o',
default: path.resolve('output'),
describe: 'Output folder',
type: 'string'
})
2020-05-30 15:17:53 +02:00
.option('debug', {
2020-06-28 22:35:53 +02:00
alias: 'd',
2020-05-28 22:18:41 +02:00
default: false,
2020-06-28 22:35:53 +02:00
describe: 'Debug mode',
2020-05-30 15:17:53 +02:00
type: 'boolean'
})
2020-06-07 13:40:26 +02:00
.argv
2020-06-26 21:00:10 +02:00
fs.mkdirpSync(args.o)
2020-05-28 22:18:41 +02:00
2020-06-26 21:00:10 +02:00
const config_parser = args.c.endsWith('.yaml') ? yaml.load : JSON.parse
2020-06-28 22:35:53 +02:00
let config
try {
config = config_parser(fs.readFileSync(args.c).toString())
} catch (err) {
throw new Error(`Malformed input "${args.c}": ${err}`)
}
// points
2020-05-30 15:17:53 +02:00
2020-06-28 22:35:53 +02:00
console.log('Parsing points...')
2020-06-26 21:00:10 +02:00
const points = points_lib.parse(config.points)
2020-05-30 15:17:53 +02:00
if (args.debug) {
2020-06-26 21:00:10 +02:00
fs.writeJSONSync(path.join(args.o, 'points.json'), points, {spaces: 4})
2020-06-28 22:35:53 +02:00
const rect = u.rect(18, 18, [-9, -9])
const points_demo = points_lib.position(points, rect)
io.dump_model(points_demo, path.join(args.o, 'points_demo'), args.debug)
2020-05-31 22:59:51 +02:00
}
2020-06-07 13:40:26 +02:00
2020-06-28 22:35:53 +02:00
// outlines
// console.log('Generating outlines...')
// goodbye
2020-06-16 22:24:46 +02:00
console.log('Done.')