This repository was archived by the owner on Nov 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·68 lines (55 loc) · 1.92 KB
/
index.js
File metadata and controls
executable file
·68 lines (55 loc) · 1.92 KB
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
#!/usr/bin/env node
"use strict";
var normalize = require('normalize-path');
const promisify = require("promisify-node");
const glob = promisify(require("glob"));
const fse = require("fs-extra");
const child_process = require("child_process");
const os = require("os");
const path = require("path");
const program = require("commander");
const pkg = require("./package.json");
const options = { nonull : true };
program
.version(pkg.version)
.option("--partials <dir>", "Directory containing partials")
.option("--output <dir>", "Output directory (i.e. \"build/partials\")")
.parse(process.argv);
if( !program.partials || !program.output) {
program.help();
}
// options is optional
glob(program.partials + "/**/*.cshtml", options)
.then(files => {
const jobs = files.map( f => buildPartial(f) );
return Promise.all(jobs);
})
.catch(err => {
console.error(err);
process.exit(1);
});
/**
* @returns {Promise}
*/
function buildPartial(partialName){
const normalizedPartialName = normalize(partialName);
const partialDir = normalize(path.dirname(partialName));
const baseName = path.basename(partialName, ".cshtml");
const modelFileName = path.join(partialDir, baseName) + ".example.json";
// remove the first part
const outputDir = path.join(program.output, partialDir.replace(normalize(program.partials), ""));
const outputFile = path.join(outputDir, baseName + ".html");
return new Promise((resolve, reject) => {
const dirLib = path.join(__dirname, "build");
const env = {};
const cp = child_process.exec(`${dirLib}/razor-cli ${partialName} ${modelFileName}`, env, (err, stdout, stderr) => {
if(err) reject(err);
fse.outputFile(outputFile, stdout, (err) => {
if(err) {
return reject(err);
}
resolve();
});
});
});
}