forked from openT2T/opent2t-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pack-onboarder.js
55 lines (44 loc) · 1.43 KB
/
pack-onboarder.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
#!/usr/bin/env node
var fs = require("fs");
var path = require("path");
var program = require('commander');
program
.version("0.1.0")
.usage("onboarder name>")
.parse(process.argv);
if (program.args.length != 1) {
program.outputHelp();
}
else {
packOnboarder(program.args[0]);
}
/**
* Adds relative paths to the appropriate onboarding package.json
*/
function packOnboarder(name) {
const onboardPrefix = "org.opent2t.onboarding.";
var onboarderPackageName = name.startsWith(onboardPrefix) ? name : onboardPrefix + name;
var packageFile = path.join(onboarderPackageName, "js", "package.json");
var outfile = "./package.json";
fs.readFile(packageFile, 'utf8', (err, data) => {
if (err) {
return console.log(err);
}
var package = JSON.parse(data);
var nameParts = package.name.split('-');
var filepath = onboardPrefix + nameParts[nameParts.length - 1];
package.main = filepath + "/js/thingOnboarding.js";
package.files = [
filepath + "/*",
filepath + "/js/*"
];
var contents = JSON.stringify(package, null, 2);
fs.writeFile(outfile, contents, 'utf8', (err) => {
if (err) {
return console.log(err);
}
console.log("Generated ./package.json file for " + package.name + ".\n" +
"Ready for npm pack or npm publish.");
});
});
}