harp 0.41.2 → 0.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/harp +25 -5
- package/lib/index.js +37 -37
- package/package.json +16 -15
package/bin/harp
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var argv = require('minimist')(process.argv.slice(2))
|
|
4
4
|
var pkg = require("../package.json")
|
|
5
|
-
var colors = require("colors")
|
|
5
|
+
var colors = require("@colors/colors")
|
|
6
6
|
var path = require("path")
|
|
7
7
|
var boxt = require("boxt")
|
|
8
8
|
|
|
@@ -19,7 +19,7 @@ var help = function(){
|
|
|
19
19
|
var box = (...args) => console.log(boxt(...args).split("\n").join("\n "));
|
|
20
20
|
|
|
21
21
|
log()
|
|
22
|
-
log("Harp".underline.blue, "〜".grey,
|
|
22
|
+
log("Harp".underline.blue, "〜".grey, pkg.description.brightYellow, "v".grey + pkg.version.grey)
|
|
23
23
|
log()
|
|
24
24
|
// log("Process | Bundle | Generate - Just In Time".grey)
|
|
25
25
|
// log()
|
|
@@ -32,8 +32,8 @@ var help = function(){
|
|
|
32
32
|
log(" -h, --host " +"0.0.0.0".blue +" server host to answer to")
|
|
33
33
|
// log(" -c, --cache " +"false".blue +" server memory cache")
|
|
34
34
|
// log(" -t, --pretty " +"false".blue +" server/compile keep whitespace")
|
|
35
|
-
log(" -h, --help
|
|
36
|
-
log(" -v, --version
|
|
35
|
+
log(" -h, --help ")
|
|
36
|
+
log(" -v, --version ")
|
|
37
37
|
box(
|
|
38
38
|
`${'PROCESSING'.grey } ${'DATA'.grey }
|
|
39
39
|
${'.ejs -> .html' } ${'_data.json - directory data' }
|
|
@@ -92,6 +92,18 @@ ${ ('http://localhost:' + port + "/").underline.cyan }`, { align: "left", color:
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
var duration = function(d){
|
|
98
|
+
if (d[0] < 1){
|
|
99
|
+
var ms = d[1].toString().substring(0,3)
|
|
100
|
+
return + ms + "ms"
|
|
101
|
+
} else {
|
|
102
|
+
var ms = d[1].toString().substring(0,1)
|
|
103
|
+
return [d[0], ms].join(".") + "s"
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
95
107
|
/**
|
|
96
108
|
* Compile
|
|
97
109
|
*/
|
|
@@ -100,12 +112,20 @@ if (argv["_"].length === 2){
|
|
|
100
112
|
var projectPath = path.resolve(process.cwd(), argv["_"][0])
|
|
101
113
|
var buildPath = path.resolve(process.cwd(), argv["_"][1])
|
|
102
114
|
|
|
115
|
+
console.log()
|
|
116
|
+
console.log(" ", `Harp v${ pkg.version }`.yellow)
|
|
117
|
+
console.log(" ", "Generating Site & Bundling Assets...".blue)
|
|
118
|
+
console.log()
|
|
119
|
+
|
|
103
120
|
harp.compile(projectPath, buildPath, function(errors, output){
|
|
104
121
|
if(errors) {
|
|
105
122
|
console.log(JSON.stringify(errors, null, 2))
|
|
106
123
|
process.exit(1)
|
|
107
124
|
}
|
|
108
|
-
|
|
125
|
+
console.log()
|
|
126
|
+
console.log(" ", "Done!".green, `(${ duration(output.stats.duration) })`.grey)
|
|
127
|
+
console.log()
|
|
109
128
|
})
|
|
129
|
+
|
|
110
130
|
}
|
|
111
131
|
|
package/lib/index.js
CHANGED
|
@@ -8,6 +8,7 @@ var helpers = require('./helpers')
|
|
|
8
8
|
var middleware = require('./middleware')
|
|
9
9
|
var pkg = require('../package.json')
|
|
10
10
|
var url = require("url")
|
|
11
|
+
var hrn = require("human-readable-numbers")
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
|
|
@@ -154,6 +155,11 @@ exports.middleware = middleware;
|
|
|
154
155
|
*/
|
|
155
156
|
|
|
156
157
|
exports.compile = function(projectPath, outputPath, callback){
|
|
158
|
+
const compileStart = process.hrtime()
|
|
159
|
+
|
|
160
|
+
var stats = {
|
|
161
|
+
types: {}
|
|
162
|
+
}
|
|
157
163
|
|
|
158
164
|
/**
|
|
159
165
|
* Both projectPath and outputPath are optional
|
|
@@ -176,7 +182,7 @@ exports.compile = function(projectPath, outputPath, callback){
|
|
|
176
182
|
try{
|
|
177
183
|
outputPath = path.resolve(projectPath, outputPath)
|
|
178
184
|
var setup = helpers.setup(projectPath, "production")
|
|
179
|
-
var terra
|
|
185
|
+
var terra = terraform.root(setup.publicPath, setup.config.globals)
|
|
180
186
|
}catch(err){
|
|
181
187
|
return callback(err)
|
|
182
188
|
}
|
|
@@ -196,6 +202,13 @@ exports.compile = function(projectPath, outputPath, callback){
|
|
|
196
202
|
})
|
|
197
203
|
}
|
|
198
204
|
|
|
205
|
+
var toHuman = function(bytes){
|
|
206
|
+
var human = hrn.toHumanString(bytes)
|
|
207
|
+
var pattern = /\d+\D$/
|
|
208
|
+
if (pattern.test(human)) return human
|
|
209
|
+
return human + "B"
|
|
210
|
+
}
|
|
211
|
+
|
|
199
212
|
|
|
200
213
|
/**
|
|
201
214
|
* Compile and save file
|
|
@@ -204,40 +217,17 @@ exports.compile = function(projectPath, outputPath, callback){
|
|
|
204
217
|
var compileFile = function(file, done){
|
|
205
218
|
process.nextTick(function () {
|
|
206
219
|
terra.render(file, function(error, body){
|
|
207
|
-
if(error)
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
absWorkingDir: setup.publicPath,
|
|
219
|
-
entryPoints: [setup.publicPath + '/app.jsx'],
|
|
220
|
-
outfile: 'app.js',
|
|
221
|
-
bundle: true,
|
|
222
|
-
write: false,
|
|
223
|
-
plugins: [],
|
|
224
|
-
})
|
|
225
|
-
fs.writeFile([outputPath, "app.js"].join(path.sep), results.outputFiles[0]["text"], done)
|
|
226
|
-
}else if (file === "bundle.cjs"){
|
|
227
|
-
var results = esbuild.buildSync({
|
|
228
|
-
absWorkingDir: setup.publicPath,
|
|
229
|
-
entryPoints: [setup.publicPath + '/bundle.cjs'],
|
|
230
|
-
outfile: 'bundle.js',
|
|
231
|
-
bundle: true,
|
|
232
|
-
write: false,
|
|
233
|
-
plugins: [],
|
|
234
|
-
})
|
|
235
|
-
fs.writeFile([outputPath, "bundle.js"].join(path.sep), results.outputFiles[0]["text"], done)
|
|
236
|
-
} else {
|
|
237
|
-
done()
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
220
|
+
if(error) return done(error)
|
|
221
|
+
if(!body) return done()
|
|
222
|
+
var dest = path.resolve(outputPath, terraform.helpers.outputPath(file))
|
|
223
|
+
fs.mkdirp(path.dirname(dest), function(err){
|
|
224
|
+
var sizeInBytes = body.length
|
|
225
|
+
var sizeHuman = toHuman(sizeInBytes)
|
|
226
|
+
var sizePadded = sizeHuman.padStart(8, " ")
|
|
227
|
+
var filePath = `/${ terraform.helpers.outputPath(file) }`
|
|
228
|
+
console.log(sizePadded.green, filePath)
|
|
229
|
+
fs.writeFile(dest, body, done)
|
|
230
|
+
})
|
|
241
231
|
})
|
|
242
232
|
})
|
|
243
233
|
}
|
|
@@ -253,7 +243,14 @@ exports.compile = function(projectPath, outputPath, callback){
|
|
|
253
243
|
if(!terraform.helpers.shouldIgnore(file) && [".jsx", ".jade", ".ejs", ".md", ".styl", ".less", ".scss", ".sass", ".coffee", ".cjs"].indexOf(ext) === -1){
|
|
254
244
|
var localPath = path.resolve(outputPath, file)
|
|
255
245
|
fs.mkdirp(path.dirname(localPath), function(err){
|
|
256
|
-
fs.
|
|
246
|
+
fs.stat(path.resolve(setup.publicPath, file), function(err, stats){
|
|
247
|
+
var sizeInBytes = stats.size
|
|
248
|
+
var sizeHuman = toHuman(sizeInBytes)
|
|
249
|
+
var sizePadded = sizeHuman.padStart(8, " ")
|
|
250
|
+
var filePath = `/${ file }`
|
|
251
|
+
console.log(sizePadded.grey, filePath)
|
|
252
|
+
fs.copy(path.resolve(setup.publicPath, file), localPath, done)
|
|
253
|
+
})
|
|
257
254
|
})
|
|
258
255
|
}else{
|
|
259
256
|
done()
|
|
@@ -273,9 +270,12 @@ exports.compile = function(projectPath, outputPath, callback){
|
|
|
273
270
|
callback(err)
|
|
274
271
|
}else{
|
|
275
272
|
async.each(results, copyFile, function(err){
|
|
273
|
+
stats.duration = process.hrtime(compileStart)
|
|
274
|
+
|
|
276
275
|
setup.config['harp_version'] = pkg.version
|
|
277
276
|
delete setup.config.globals
|
|
278
|
-
|
|
277
|
+
setup.stats = stats
|
|
278
|
+
callback(null, setup)
|
|
279
279
|
})
|
|
280
280
|
}
|
|
281
281
|
})
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "harp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Static
|
|
3
|
+
"version": "0.44.0",
|
|
4
|
+
"description": "Static Web Server/Generator/Bundler",
|
|
5
5
|
"author": "Brock Whitten <brock@chloi.io>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Brock Whitten <brock@chloi.io>",
|
|
@@ -43,27 +43,28 @@
|
|
|
43
43
|
"url": "https://github.com/sintaxi/harp.git"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@
|
|
46
|
+
"@colors/colors": "1.5.0",
|
|
47
47
|
"async": "0.2.9",
|
|
48
|
-
"basic-auth": "
|
|
49
|
-
"boxt": "
|
|
50
|
-
"
|
|
51
|
-
"connect": "^3.6.6",
|
|
48
|
+
"basic-auth": "2.0.1",
|
|
49
|
+
"boxt": "1.1.2",
|
|
50
|
+
"connect": "3.7.0",
|
|
52
51
|
"envy-json": "0.2.1",
|
|
53
|
-
"fs-extra": "1.
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
52
|
+
"fs-extra": "10.1.0",
|
|
53
|
+
"human-readable-numbers": "0.9.5",
|
|
54
|
+
"mime-types": "2.1.35",
|
|
55
|
+
"minimist": "1.2.6",
|
|
56
|
+
"parseurl": "1.3.3",
|
|
57
57
|
"pause": "0.1.0",
|
|
58
|
-
"send": "
|
|
59
|
-
"terraform": "
|
|
58
|
+
"send": "0.18.0",
|
|
59
|
+
"terraform": "1.22.1"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"
|
|
63
|
-
"
|
|
62
|
+
"axios": "0.27.2",
|
|
63
|
+
"mocha": "10.0.0",
|
|
64
64
|
"should": "3.3.2"
|
|
65
65
|
},
|
|
66
66
|
"scripts": {
|
|
67
|
+
"prepare": "git config core.hooksPath ./hooks",
|
|
67
68
|
"test": "mocha --reporter spec -t 4000",
|
|
68
69
|
"test:fallbacks": "mocha test/fallbacks.js -t 3000",
|
|
69
70
|
"test:helpers": "mocha test/helpers.js -t 3000"
|