-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
93 lines (72 loc) · 2.84 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
'use strict'
;
const args = require('./args').args
const fs = require('fs')
const Converter = require('./converter').Converter
const path = require('path')
const svgoConfig = require('./svgoConfig').svgoConfig
const SVGO = require('./node_modules/svgo/lib/svgo.js')
;
let settingsGCODE = require('./settingsGcode').getSettings()
;
console.log('hello');
(async () => {
let inputFolder = settingsGCODE.inputFolder
let outputFolder = settingsGCODE.exportFolder
let svgFile = inputFolder + args.file
let outFile = args.output
let travelSpeed = args.travelSpeed
let printingSpeed = args.printingSpeed
let zOffset = args.zOffset
let useSvgo = args.useSvgo
// console.log(zOffset)
// validateInputs()
// TODO : make a validation of the inputs
// if (svgFile.search('.svg') == -1) {
settingsGCODE.inputFile = svgFile
settingsGCODE.outputFile = outFile
settingsGCODE.seekRate = travelSpeed
settingsGCODE.feedRate = printingSpeed
settingsGCODE.colorCommandOff4 = settingsGCODE.colorCommandOff4.replace('{{Zoff}}', zOffset.toString())
settingsGCODE.start = settingsGCODE.start.replace('{{Zoff}}', zOffset.toString())
settingsGCODE.useSvgo = useSvgo
// implementation svgo
if (settingsGCODE.useSvgo === true) {
console.log('[+] using svgo to optimize the svg file ...')
const mSvgo = new SVGO({
floatPrecision: 8,
plugins: svgoConfig,
pretty: true
})
// convert the input file
const filepath = path.resolve(settingsGCODE.inputFolder, settingsGCODE.inputFile)
console.log(filepath)
fs.readFile(filepath, 'utf8', function (err, data) {
if (err) throw err
console.log('reading')
mSvgo.optimize(data, { path: filepath }).then(function (result) {
let svgoFileOutput = path.resolve(settingsGCODE.inputFolder, settingsGCODE.inputFile + "_temp")
fs.writeFile(svgoFileOutput, result.data, (err) => {
if (err) return console.log(err)
console.log('svgo conversion success')
settingsGCODE.inputFile = svgFile + "_temp"
launchConversion(settingsGCODE)
})
})
})
} else {
launchConversion(settingsGCODE)
}
})()
async function launchConversion(settingsGCODE) {
// settingsGCODE.inputFile = 'test/shapes/rectBig.svg'
let converter = new Converter(settingsGCODE)
let gcodeArray = await converter.convert()
for (let i = 0; i < gcodeArray.length; i++) {
if (settingsGCODE.showOutput) converter.showStringifyGcode(gcodeArray[i])
if (settingsGCODE.writeOutput) {
converter.writeOutputFile(settingsGCODE.exportFolder, gcodeArray[i], i)
}
}
console.log('[+] Finished !\n')
}