Skip to content

Commit 116a319

Browse files
committed
[Issue #7] - Pre & Post commands at each step
1 parent 6349797 commit 116a319

4 files changed

Lines changed: 36 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Additions
66

77
- [Issue #10] - Config creator should export full-featured config file
8+
- [Issue #7] - Pre & Post commands at each step
89
- [Issue #6] - Converter needs to remap directories
910
- [Issue #2] - Importer should have ignore files functionality
1011

config.json

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
"layoutFile": "layout.html",
1212
"ignoreViews": [
1313
"styleguide.html"
14-
]
14+
],
15+
16+
"precmd": "echo 'test' >> test.txt",
17+
"postcmd": ""
1518

1619
},
1720
"converter": {
@@ -28,19 +31,28 @@
2831
"prepend": "",
2932
"append": "",
3033
"remap": []
31-
}
34+
},
35+
36+
"precmd": "",
37+
"postcmd": ""
3238
},
3339
"builder": {
3440
"dirBuild": "./dist",
3541
"installCmd": "express -v hbs -c sass && npm i",
36-
"cleanupCmd": "rm -rf public/* views/*.hbs"
42+
"cleanupCmd": "rm -rf public/* views/*.hbs",
43+
44+
"precmd": "",
45+
"postcmd": ""
3746
},
3847
"exporter": {
3948
"dirBuild": "./dist",
4049
"dirViews": "./views",
4150
"dirImages": "./public/images",
4251
"dirCSS": "./public/stylesheets",
4352
"dirJS": "./public/javascripts",
44-
"viewExtension": ".hbs"
53+
"viewExtension": ".hbs",
54+
55+
"precmd": "",
56+
"postcmd": ""
4557
}
4658
}

lib/execute-cmd.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const shell = require("child_process");
2+
3+
module.exports = function(cmd) {
4+
if (cmd && cmd.length) {
5+
shell.execSync(cmd);
6+
}
7+
};

lib/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const env = process.env.NODE_ENV || 'default';
44
// Import dependencies
55
const getCliArguments = require("command-line-args");
66
const config = require("config");
7-
const shell = require("child_process");
7+
const executeCommand = require("./execute-cmd");
88
const fs = require("fs");
99

1010
// Build chain functions
@@ -78,7 +78,7 @@ catch (ex) {
7878
// Check for config dir
7979
if (!fs.existsSync("config")) {
8080
// Create dir
81-
shell.execSync("mkdir config");
81+
executeCommand("mkdir config");
8282
}
8383

8484
// Check for environment config file
@@ -109,13 +109,18 @@ payload.build.force = cli.args.forceBuild;
109109

110110
// Start the engine
111111
console.log("Importing...");
112+
executeCommand(importer.precmd);
112113
importer.run(payload)
113114
.then((payload) => {
115+
executeCommand(importer.postcmd);
116+
executeCommand(converter.precmd);
114117
console.log("Converting...");
115118
return converter.run(payload);
116119
})
117120
.then((payload) => {
121+
executeCommand(converter.postcmd);
118122
if (builder.shouldBuild() || cli.args.forceBuild) {
123+
executeCommand(builder.precmd);
119124
console.log("Building...");
120125
return builder.run(payload);
121126
}
@@ -125,10 +130,15 @@ importer.run(payload)
125130
}
126131
})
127132
.then((payload) => {
133+
if (builder.shouldBuild() || cli.args.forceBuild) {
134+
executeCommand(builder.postcmd);
135+
}
136+
executeCommand(exporter.precmd);
128137
console.log("Exporting...");
129138
return exporter.run(payload);
130139
})
131140
.then((payload) => {
141+
executeCommand(exporter.postcmd);
132142
console.log("Exported", payload, "files.");
133143
console.log("Finished.");
134144
})

0 commit comments

Comments
 (0)