File index.js changed (mode: 100755) (index 7197327..0f44c5f) |
... |
... |
const fs = require("fs"), |
7 |
7 |
const [, , templatePath, projectPath] = process.argv; |
const [, , templatePath, projectPath] = process.argv; |
8 |
8 |
|
|
9 |
9 |
if (templatePath && projectPath) { |
if (templatePath && projectPath) { |
10 |
|
const script = "result = `" + fs.readFileSync(templatePath, "utf8") + "`;", |
|
11 |
|
interface = fs.readFileSync(path.join(projectPath, "src", "interface.h")), |
|
12 |
|
package = getPackage(projectPath); |
|
|
10 |
|
const script = "result = `" + readFile(templatePath) + "`;", |
|
11 |
|
interface = readFile(path.join(projectPath, "src", "interface.h")), |
|
12 |
|
package = readJSON(path.join(projectPath, "package.json")); |
13 |
13 |
|
|
14 |
14 |
let context = { |
let context = { |
15 |
15 |
title: package.name, |
title: package.name, |
16 |
16 |
interface, |
interface, |
17 |
17 |
objective: package.objective |
objective: package.objective |
18 |
18 |
}; |
}; |
|
19 |
|
|
19 |
20 |
vm.createContext(context); |
vm.createContext(context); |
20 |
21 |
vm.runInContext(script, context); |
vm.runInContext(script, context); |
21 |
22 |
|
|
22 |
23 |
console.log(context.result); |
console.log(context.result); |
23 |
24 |
} |
} |
24 |
25 |
|
|
25 |
|
function getPackage(projectPath) { |
|
26 |
|
let package = fs.readFileSync(path.join(projectPath, "package.json"), "utf8"); |
|
27 |
|
return JSON.parse(package); |
|
|
26 |
|
function readJSON(projectPath) { |
|
27 |
|
return JSON.parse(readFile(projectPath)); |
|
28 |
|
} |
|
29 |
|
|
|
30 |
|
function readFile(path) { |
|
31 |
|
return fs.readFileSync(path, "utf8"); |
28 |
32 |
} |
} |