forked from CYBRToken/solidoc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
executable file
·101 lines (80 loc) · 2.43 KB
/
cli.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env node
"use strict";
const path = require("path");
const resolve = require("path").resolve;
const fs = require("fs-extra");
const compiler = require("./utils/compiler");
const pino = require("pino");
const parser = require("./parser");
const generator = require("./generator");
const logger = pino({
prettyPrint: true,
});
/***********************************************************************************************
Arguments:
1. Path to truffle project root.
2. Path to generate documentation to.
3. Do not recompile. Optional, default: false.
4. Language. Optional, default: en.
*************************************************************************************************/
function getConfig() {
function readConfig() {
const file = path.join(process.cwd(), "solidoc.json");
if (!fs.pathExistsSync(file)) {
return {};
}
const contents = fs.readFileSync(file);
const config = JSON.parse(contents.toString());
return config;
}
var config = readConfig();
const args = process.argv;
if (args.length > 6) {
logger.error(`Invalid command ${process.argv.join(" ")}`);
return;
}
if (args.length > 2) {
config.pathToRoot = args[2];
config.outputPath = args[3];
config.noCompilation = (args[4] || "").toLowerCase().startsWith("t");
config.language = args[5] || "en";
}
config.pathToRoot = resolve(config.pathToRoot);
config.outputPath = resolve(config.outputPath);
return config;
}
const config = getConfig();
global.config = config;
if (!config.pathToRoot) {
logger.error("Path to truffle project root was not specified.");
return;
}
const buildDirectory = path.join(
config.pathToRoot,
config.artifactDir || "build"
);
if (!fs.existsSync(config.pathToRoot)) {
logger.error("Invalid directory: %s.", config.pathToRoot);
return;
}
function begin() {
if (!fs.existsSync(buildDirectory)) {
logger.error(
"Please build your project first or run solidoc with recompilation on."
);
return;
}
if (!fs.existsSync(config.outputPath)) {
logger.info("Create the directory for the output path: %s.");
fs.mkdirSync(config.outputPath);
}
const contracts = parser.parse(buildDirectory);
generator.serialize(contracts, config.outputPath);
}
if (!config.noCompilation) {
fs.removeSync(buildDirectory);
logger.info("Removed %s.", buildDirectory);
compiler.compile(config.pathToRoot, begin);
return;
}
begin();