This repository has been archived by the owner on Apr 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbuild-jscad.js
56 lines (48 loc) · 1.85 KB
/
build-jscad.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
const fs = require("fs");
const path = require("path");
const includify = require('jscad-includify');
const readlineSync = require('readline-sync');
const child_process = require('child_process');
const package_json = require("../package.json");
const org = '@jscad-gallery';
const jscadfile = process.argv[2];
function getFileNameWithoutExtension() {
const ext = path.extname(jscadfile);
return path.basename(jscadfile, ext);
}
const designTitle = getFileNameWithoutExtension();
const jscad_modulesDir = path.resolve(__dirname, '../node_modules', org);
if (!fs.existsSync(jscad_modulesDir)) {
fs.mkdirSync(jscad_modulesDir);
}
const dirOut = path.resolve(jscad_modulesDir, designTitle);
if (!fs.existsSync(dirOut)) {
fs.mkdirSync(dirOut);
}
console.log(`jscad file is ${jscadfile}`);
console.log(`module name is ${designTitle}`);
const author = process.argv[3] || readlineSync.question('author:');
const description = process.argv[4] || readlineSync.question('description:');
var jscad_package_json = {
"name": designTitle,
"version": "1.0.0",
"description": description,
"main": "index.js",
"dependencies": {
"@jscad/scad-api": package_json.devDependencies["@jscad/scad-api"]
},
"author": author,
"license": "MIT"
}
includify.runFile(jscadfile, (error, includes, code) => {
if (error) {
console.log(`ERROR: ${error}`);
return;
}
const moduleTemplatePath = path.resolve(__dirname, 'jscad-module-template.js');
const moduleTemplate = fs.readFileSync(moduleTemplatePath, 'utf8');
const js = moduleTemplate.replace('//CONTENT', code);
fs.writeFileSync(path.resolve(dirOut, 'index.js'), js);
fs.writeFileSync(path.resolve(dirOut, 'package.json'), JSON.stringify(jscad_package_json, null, 2));
child_process.fork(path.resolve(__dirname, './build-design.js'), [`${org}/${designTitle}`]);
});