|
@@ -9,7 +9,10 @@ const oslo = require('../src/index')
|
9
|
9
|
class OsloCLI {
|
10
|
10
|
constructor(opts) {
|
11
|
11
|
this.context = {}
|
|
12
|
+ this.eval(opts)
|
|
13
|
+ }
|
12
|
14
|
|
|
15
|
+ eval(opts) {
|
13
|
16
|
if (opts.l) {
|
14
|
17
|
this.context = JSON.parse(fs.readFileSync(this.absolutePath(opts.l)))
|
15
|
18
|
}
|
|
@@ -41,29 +44,7 @@ class OsloCLI {
|
41
|
44
|
}
|
42
|
45
|
|
43
|
46
|
if (opts.o) {
|
44
|
|
- const absoluteOutputPath = this.absolutePath(opts.o)
|
45
|
|
- if (opts.f || opts.e) {
|
46
|
|
- fs.writeFile(absoluteOutputPath, output, function(err) {
|
47
|
|
- if (err) throw err
|
48
|
|
- })
|
49
|
|
- } else if (opts.d) {
|
50
|
|
- const absoluteInputPath = this.absolutePath(opts.d)
|
51
|
|
- Object.keys(output).forEach(function(file) {
|
52
|
|
- const absoluteOutputFilePath = file
|
53
|
|
- .replace(absoluteInputPath, absoluteOutputPath)
|
54
|
|
- .replace(/\.oslo$/, '.html')
|
55
|
|
- const parentDirectory = path.dirname(absoluteOutputFilePath)
|
56
|
|
- if (!fs.existsSync(parentDirectory)) {
|
57
|
|
- fs.mkdirSync(parentDirectory)
|
58
|
|
- }
|
59
|
|
- fs.writeFile(absoluteOutputFilePath, output[file], function(err) {
|
60
|
|
- if (err) throw err
|
61
|
|
- console.log(
|
62
|
|
- `Writing to ${absoluteOutputFilePath.replace(process.cwd(), '')}`,
|
63
|
|
- )
|
64
|
|
- })
|
65
|
|
- })
|
66
|
|
- }
|
|
47
|
+ this.output(opts, output)
|
67
|
48
|
} else {
|
68
|
49
|
process.stdout.write(output)
|
69
|
50
|
process.stdout.write('\n')
|
|
@@ -100,6 +81,32 @@ class OsloCLI {
|
100
|
81
|
return path.join(root, file)
|
101
|
82
|
}
|
102
|
83
|
|
|
84
|
+ output(opts, output) {
|
|
85
|
+ const absoluteOutputPath = this.absolutePath(opts.o)
|
|
86
|
+ if (opts.f || opts.e) {
|
|
87
|
+ fs.writeFile(absoluteOutputPath, output, function(err) {
|
|
88
|
+ if (err) throw err
|
|
89
|
+ })
|
|
90
|
+ } else if (opts.d) {
|
|
91
|
+ const absoluteInputPath = this.absolutePath(opts.d)
|
|
92
|
+ Object.keys(output).forEach(function(file) {
|
|
93
|
+ const absoluteOutputFilePath = file
|
|
94
|
+ .replace(absoluteInputPath, absoluteOutputPath)
|
|
95
|
+ .replace(/\.oslo$/, '.html')
|
|
96
|
+ const parentDirectory = path.dirname(absoluteOutputFilePath)
|
|
97
|
+ if (!fs.existsSync(parentDirectory)) {
|
|
98
|
+ fs.mkdirSync(parentDirectory)
|
|
99
|
+ }
|
|
100
|
+ fs.writeFile(absoluteOutputFilePath, output[file], function(err) {
|
|
101
|
+ if (err) throw err
|
|
102
|
+ console.log(
|
|
103
|
+ `Writing to ${absoluteOutputFilePath.replace(process.cwd(), '')}`,
|
|
104
|
+ )
|
|
105
|
+ })
|
|
106
|
+ })
|
|
107
|
+ }
|
|
108
|
+ }
|
|
109
|
+
|
103
|
110
|
printUsage() {
|
104
|
111
|
console.log(
|
105
|
112
|
`USAGE
|