-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (35 loc) · 1.4 KB
/
index.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
#!/usr/bin/env node
var path = require('path');
var fs = require('fs');
var command = process.argv[2];
var param = process.argv[3];
if (command == 'generate') {
if (!param) {
console.error('Filename is required when calling generate. Example: "usite generate blog"');
return;
}
var generator = require(path.resolve(process.cwd(), param));
if (!generator.generate) {
console.error("Provided generator is missing generate function");
return;
}
var uSite = require("./dist/usite");
generator.generate(uSite.default);
}
if (command == 'init') {
var fse = require('fs-extra');
var dirPath = __dirname;
var demoPath = path.resolve(dirPath, './node_modules/usiteDemo/');
if (!fse.existsSync(demoPath)) {
demoPath = path.resolve(dirPath, '../usiteDemo/')
if (!fse.existsSync(demoPath)) {
console.error("usiteDemo dependency not found");
return;
}
}
var workingDirectory = process.cwd();
fse.copySync(path.resolve(demoPath, "./content"), path.resolve(workingDirectory, "./content"));
fse.copySync(path.resolve(demoPath, "./template"), path.resolve(workingDirectory, "./template"));
fse.copySync(path.resolve(demoPath, "./blog.js"), path.resolve(workingDirectory, "./blog.js"));
fse.copySync(path.resolve(demoPath, "./website.json"), path.resolve(workingDirectory, "./website.json"));
}