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-16 22:24:46 +02:00
|
|
|
const points_lib = require('../helpers/points')
|
|
|
|
|
const outline_lib = require('./outline')
|
2020-05-30 15:17:53 +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,
|
|
|
|
|
describe: 'Config yaml file',
|
|
|
|
|
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-05-28 22:18:41 +02:00
|
|
|
default: false,
|
2020-05-30 15:17:53 +02:00
|
|
|
hidden: true,
|
|
|
|
|
type: 'boolean'
|
|
|
|
|
})
|
|
|
|
|
.option('outline', {
|
|
|
|
|
default: true,
|
2020-05-28 22:18:41 +02:00
|
|
|
describe: 'Generate 2D outlines',
|
|
|
|
|
type: 'boolean'
|
|
|
|
|
})
|
|
|
|
|
.option('pcb', {
|
|
|
|
|
default: false,
|
|
|
|
|
describe: 'Generate PCB draft',
|
|
|
|
|
type: 'boolean'
|
|
|
|
|
})
|
|
|
|
|
.option('case', {
|
|
|
|
|
default: false,
|
|
|
|
|
describe: 'Generate case files',
|
|
|
|
|
type: 'boolean'
|
|
|
|
|
})
|
2020-06-07 13:40:26 +02:00
|
|
|
.argv
|
|
|
|
|
|
2020-05-28 22:18:41 +02:00
|
|
|
if (!args.outline && !args.pcb && !args.case) {
|
2020-05-30 15:17:53 +02:00
|
|
|
yargs.showHelp('log')
|
2020-05-28 22:18:41 +02:00
|
|
|
console.log('Nothing to do...')
|
|
|
|
|
process.exit(0)
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-07 13:40:26 +02:00
|
|
|
const config = yaml.load(fs.readFileSync(args.c).toString())
|
2020-05-30 15:17:53 +02:00
|
|
|
const points = points_lib.parse(config)
|
|
|
|
|
|
|
|
|
|
if (args.debug) {
|
|
|
|
|
points_lib.dump(points)
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-31 22:59:51 +02:00
|
|
|
if (args.outline) {
|
|
|
|
|
outline_lib.draw(points, config)
|
|
|
|
|
}
|
2020-06-07 13:40:26 +02:00
|
|
|
|
2020-06-16 22:24:46 +02:00
|
|
|
console.log('Done.')
|
|
|
|
|
|
|
|
|
|
// exports.dump_model = (model, file='model', json=false) => {
|
|
|
|
|
// const assembly = m.model.originate({
|
|
|
|
|
// models: deepcopy(model),
|
|
|
|
|
// units: 'mm'
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
// if (json) fs.writeFileSync(`${file}.json`, JSON.stringify(assembly, null, ' '))
|
|
|
|
|
// fs.writeFileSync(`${file}.dxf`, m.exporter.toDXF(assembly))
|
|
|
|
|
// }
|