Skip to content

Commit e61f2e2

Browse files
authored
Merge pull request #11 from StatelessSoftware/v0.1.0
V0.1.0
2 parents 5b076bd + 116a319 commit e61f2e2

7 files changed

Lines changed: 247 additions & 89 deletions

File tree

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# Changelog - html-to-app
22

3+
## [0.1.0] - 2018-03-26
4+
5+
### Additions
6+
7+
- [Issue #10] - Config creator should export full-featured config file
8+
- [Issue #7] - Pre & Post commands at each step
9+
- [Issue #6] - Converter needs to remap directories
10+
- [Issue #2] - Importer should have ignore files functionality
11+
12+
### Fixes
13+
14+
- [Issue #8] - Out-of-source build creates extra subnested dist folder
15+
- [Issue #5] - Build fails if images directory doesnt exist
16+
- [Issue #4] - Default config file should be in seperate file
17+
- [Issue #3] - Default config should support out-of-source build
18+
319
## [0.0.2] - 2018-03-24
420

521
### Fixes

config.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"importer": {
3+
"dirHTML": "./html/",
4+
"dirImages": "./html/images",
5+
"dirCSS": "./html/",
6+
"dirJS": "./html/",
7+
8+
"typeCSS": "scss",
9+
"typeJS": "js",
10+
11+
"layoutFile": "layout.html",
12+
"ignoreViews": [
13+
"styleguide.html"
14+
],
15+
16+
"precmd": "echo 'test' >> test.txt",
17+
"postcmd": ""
18+
19+
},
20+
"converter": {
21+
"layout": {
22+
"target": "document.documentElement.outerHTML",
23+
"remove": "pingendo",
24+
"prepend": "<!DOCTYPE html>",
25+
"append": "",
26+
"remap": []
27+
},
28+
"view": {
29+
"target": "document.body.innerHTML",
30+
"remove": "script, pingendo",
31+
"prepend": "",
32+
"append": "",
33+
"remap": []
34+
},
35+
36+
"precmd": "",
37+
"postcmd": ""
38+
},
39+
"builder": {
40+
"dirBuild": "./dist",
41+
"installCmd": "express -v hbs -c sass && npm i",
42+
"cleanupCmd": "rm -rf public/* views/*.hbs",
43+
44+
"precmd": "",
45+
"postcmd": ""
46+
},
47+
"exporter": {
48+
"dirBuild": "./dist",
49+
"dirViews": "./views",
50+
"dirImages": "./public/images",
51+
"dirCSS": "./public/stylesheets",
52+
"dirJS": "./public/javascripts",
53+
"viewExtension": ".hbs",
54+
55+
"precmd": "",
56+
"postcmd": ""
57+
}
58+
}

lib/chainlinks/converter.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ let Converter = function() {
1212
"remove": "",
1313
"prepend": "",
1414
"append": ""
15+
1516
};
1617

1718
/**
@@ -31,6 +32,79 @@ let Converter = function() {
3132
});
3233
}
3334

35+
// Remaps
36+
if (func.remap) {
37+
38+
func.remap.forEach((remap) => {
39+
40+
if (remap.tag) {
41+
42+
dom.window.document.querySelectorAll(remap.tag).forEach((element) => {
43+
44+
let href = "";
45+
46+
switch (remap.tag) {
47+
case "a":
48+
case "link":
49+
href = element.href;
50+
51+
break;
52+
53+
case "img":
54+
case "script":
55+
href = element.src;
56+
57+
break;
58+
59+
}
60+
61+
// Remap
62+
if (remap.from !== undefined && remap.to !== undefined) {
63+
64+
href = href.replace(remap.from, remap.to);
65+
66+
}
67+
68+
// Prepend
69+
if (remap.prepend) {
70+
href = remap.prepend + href;
71+
}
72+
73+
// Append
74+
if (remap.append) {
75+
href = href + remap.prepend;
76+
}
77+
78+
switch (remap.tag) {
79+
case "a":
80+
case "link":
81+
element.href = href;
82+
83+
break;
84+
85+
case "img":
86+
case "script":
87+
element.src = href;
88+
89+
break;
90+
91+
}
92+
93+
});
94+
95+
}
96+
else {
97+
throw "All Converter remaps must contain a tag";
98+
}
99+
100+
})
101+
102+
// JS Files
103+
104+
// Images
105+
106+
}
107+
34108
// Retarget dom & stringify
35109
if (func.target) {
36110
let target = "dom.window." + func.target;

lib/chainlinks/exporter.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ let Exporter = function() {
8383
let moves = [];
8484

8585
// Create public directories
86-
this.createDirIfNotExists(this.dirBuild);
8786
this.createDirIfNotExists(this.dirViews);
8887
this.createDirIfNotExists(this.dirCSS);
8988
this.createDirIfNotExists(this.dirJS);
@@ -107,7 +106,7 @@ let Exporter = function() {
107106
}
108107

109108
// Copy images
110-
if (payload.import.images.length) {
109+
if (payload.import.images) {
111110
payload.import.images.forEach((file, i) => {
112111

113112
let from = payload.import.dirImages + '/' + file;
@@ -118,7 +117,7 @@ let Exporter = function() {
118117
}
119118

120119
// Copy css
121-
if (payload.import.css.length) {
120+
if (payload.import.css) {
122121
payload.import.css.forEach((file, i) => {
123122

124123
let from = payload.import.dirCSS + '/' + file;
@@ -129,7 +128,7 @@ let Exporter = function() {
129128
}
130129

131130
// Copy js
132-
if (payload.import.js.length) {
131+
if (payload.import.js) {
133132
payload.import.js.forEach((file, i) => {
134133

135134
let from = payload.import.dirJS + '/' + file;

lib/chainlinks/importer.js

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ let Importer = function() {
99
this.dirCSS = "";
1010
this.dirJS = "";
1111
this.layoutFile = "";
12-
12+
this.ignoreViews = [];
13+
1314
this.typeCSS = "";
1415
this.typeJS = "";
1516

@@ -115,7 +116,8 @@ let Importer = function() {
115116

116117
// Layout is not a view
117118
if (view !== this.layoutFile &&
118-
view.includes(".html") !== false
119+
view.includes(".html") !== false &&
120+
!this.ignoreViews.includes(view)
119121
) {
120122

121123
// Load the file
@@ -130,23 +132,39 @@ let Importer = function() {
130132
}
131133

132134
// Parse for images
133-
payload.import.dirImages = this.fixFilename("", this.dirImages);
134-
payload.import.images = fs.readdirSync(payload.import.dirImages);
135+
let imgdir = this.fixFilename("", this.dirImages);
136+
if (fs.existsSync(imgdir)) {
137+
payload.import.dirImages = imgdir;
138+
payload.import.images = fs.readdirSync(payload.import.dirImages);
139+
}
135140

136141
// Parse for css
137-
payload.import.dirCSS = this.fixFilename("", this.dirCSS);
138-
payload.import.typeCSS = this.typeCSS;
139-
payload.import.css = this.readdirFiletype(this.dirCSS, this.typeCSS);
142+
let cssdir = this.fixFilename("", this.dirCSS);
143+
if (fs.existsSync(cssdir)) {
144+
payload.import.dirCSS = cssdir;
145+
payload.import.typeCSS = this.typeCSS;
146+
payload.import.css = this.readdirFiletype(this.dirCSS, this.typeCSS);
147+
}
140148

141149
// Parse for js
142-
payload.import.dirJS = this.fixFilename("", this.dirJS);
143-
payload.import.typeJS = this.typeJS;
144-
payload.import.js = this.readdirFiletype(this.dirJS, this.typeJS);
150+
let jsdir = this.fixFilename("", this.dirJS);
151+
if (fs.existsSync(jsdir)) {
152+
payload.import.dirJS = jsdir;
153+
payload.import.typeJS = this.typeJS;
154+
payload.import.js = this.readdirFiletype(this.dirJS, this.typeJS);
155+
}
145156

146157
console.log("\t" + loadFunctions.length + " views (including layouts)");
147-
console.log("\t" + payload.import.images.length + " images");
148-
console.log("\t" + payload.import.css.length + " " + this.typeCSS + " files");
149-
console.log("\t" + payload.import.js.length + " " + this.typeJS + " files");
158+
159+
if (payload.import.images) {
160+
console.log("\t" + payload.import.images.length + " images");
161+
}
162+
if (payload.import.css) {
163+
console.log("\t" + payload.import.css.length + " " + this.typeCSS + " files");
164+
}
165+
if (payload.import.js) {
166+
console.log("\t" + payload.import.js.length + " " + this.typeJS + " files");
167+
}
150168

151169
// Load layout file
152170
Promise.all(loadFunctions)

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+
};

0 commit comments

Comments
 (0)