Skip to content

Commit ccef1b0

Browse files
authored
Merge pull request #11 from StatelessSoftware/v0.1.0
V0.1.0
2 parents 6909d20 + 25f7609 commit ccef1b0

6 files changed

Lines changed: 81 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# html-baker
22

3+
## [0.1.0] - 2018-03-31
4+
5+
### Additions
6+
7+
- [Issue #8] - Wget creates .1.html files
8+
- [Issue #7] - Config should allow for post-command
9+
- [Issue #6] - Config creator should be able to append to existing config
10+
11+
### Fixes
12+
13+
- [Issue #10] - Convert links should not be on by default
14+
315
## [0.0.2] - 2018-03-31
416

517
### Fixes

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ To remove the build and rebuild, run `html-baker -f`
2222

2323
## Configuration
2424

25+
- **precmd** - A command to run before the build starts
2526
- **domains** - An array of domain urls to download
2627
- **input** - If you have an app locally to download from, you can have it auto-start with these options
2728
- **directory** - Location of the app
2829
- **runcmd** - Command to run (start) the app. i.e. - `npm start`
2930
- **output**
3031
- **directory** - Directory to bake into
32+
- **fixDotOnes** - (boolean) If html-baker should convert wget's .1 files to .html files
3133
- **options** - Array of wget options
34+
- **postcmd** - A command to run after the build succeeds

config.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"baker": {
3+
"precmd": "",
34
"domains": [
45
"localhost:3000"
56
],
@@ -8,15 +9,16 @@
89
"runcmd": "npm start"
910
},
1011
"output": {
11-
"directory": "./docs"
12+
"directory": "./docs",
13+
"fixDotOnes": true
1214
},
1315
"options": [
1416
"--recursive",
1517
"--page-requisites",
1618
"--html-extension",
17-
"--convert-links",
1819
"--restrict-file-names=windows",
1920
"--no-parent"
20-
]
21+
],
22+
"postcmd": ""
2123
}
2224
}

index.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const shell = require("child_process");
2+
const fs = require("fs");
23

34
// Load cli
45
let cli = require("./lib/cli")();
@@ -27,6 +28,12 @@ if (cli.force && config.output && config.output.directory) {
2728

2829
// Start the engine
2930

31+
// Run the precmd
32+
if (config.precmd && config.precmd.length) {
33+
console.log("Pre-cmd:", config.precmd);
34+
shell.execSync(config.precmd);
35+
}
36+
3037
/// Check for input server command
3138
let server = false;
3239
let serverStarted = false;
@@ -108,6 +115,34 @@ function download() {
108115

109116
try {
110117
shell.execSync(wgetcmd);
118+
119+
// Run the post command
120+
if (config.postcmd && config.postcmd.length) {
121+
console.log("Post-cmd:", config.postcmd);
122+
shell.execSync(config.postcmd);
123+
}
124+
125+
// Fix dot ones
126+
if (config.output && config.output.fixDotOnes) {
127+
128+
// Scan the directory
129+
fs.readdirSync(config.output.directory).forEach(file => {
130+
if (file.includes(".1.html")) {
131+
132+
file = config.output.directory + '/' + file;
133+
let newfile = file.replace(".1.html", ".html");
134+
135+
try {
136+
fs.renameSync(file, newfile);
137+
}
138+
catch (ex) {
139+
throw "Could not move file " + file;
140+
}
141+
}
142+
});
143+
144+
}
145+
111146
console.log("Done.");
112147
}
113148
catch (ex) {
@@ -125,4 +160,4 @@ function download() {
125160
}
126161
process.exit();
127162

128-
}
163+
}

lib/config.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ module.exports = function() {
2121
shell.execSync("mkdir " + dir);
2222
}
2323

24+
// Pull default config
25+
let defaultConfig = require("../config.json");
26+
2427
// Check for environment config file
2528
if (!fs.existsSync(file)) {
26-
let defaultConfig = require("../config.json");
2729

2830
try {
2931
// Create file
@@ -34,14 +36,34 @@ module.exports = function() {
3436
'\t'
3537
)
3638
);
39+
40+
console.log("Config file created successfully.");
3741
}
3842
catch (ex) {
3943
throw "Could not create configuration file.";
4044
}
4145

4246
}
4347
else {
44-
console.log("Configuration file exists. Will not overwrite.");
48+
// Append the config to existing
49+
let existingConfig = fs.readFileSync(file);
50+
if (existingConfig) {
51+
existingConfig = JSON.parse(existingConfig);
52+
existingConfig.baker = defaultConfig.baker;
53+
54+
// Rewrite the file
55+
try {
56+
fs.writeFileSync(file, JSON.stringify(existingConfig, null, '\t'));
57+
}
58+
catch (ex) {
59+
throw "Could not append configuration file.";
60+
}
61+
62+
console.log("Config file appended successfully.");
63+
}
64+
else {
65+
throw "Could not append configuration file."
66+
}
4567
}
4668

4769
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html-baker",
3-
"version": "0.0.2",
3+
"version": "0.1.0",
44
"description": "Convert websites into flat-file websites",
55
"main": "index.js",
66
"bin": {

0 commit comments

Comments
 (0)