This repository has been archived by the owner on Oct 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
index.js
executable file
·102 lines (85 loc) · 2.21 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env node
const path = require('path')
const fs = require('fs')
const program = require('commander')
const gulp = require('gulp')
const pkginfo = require('pkginfo')(module, 'version')
const gutil = require('gulp-util')
function init() {
gutil.log(gutil.colors.red(`hugulp v${module.exports.version}`))
const hugulpRc = path.join(process.cwd(), '.hugulprc')
if (fs.existsSync(hugulpRc)) {
gutil.log(
gutil.colors.yellow('.hugulprc already exists (initialization skipped)')
)
return
}
const config = {
version: 2,
pipeline: ['images', 'styles', 'scripts', 'fingerprint', 'html'],
path: {
styles: 'styles',
images: 'images',
scripts: 'scripts'
},
watch: {
source: 'assets',
target: 'static'
},
build: {
source: 'public',
target: 'public'
},
autoprefixer: {
browsers: ['last 2 versions']
},
cleancss: {
advanced: false
},
htmlmin: {
collapseWhitespace: true
},
gifsicle: { interlaced: true },
jpegtran: { progressive: true },
optipng: { optimizationLevel: 5 },
svgo: {
plugins: [{ removeViewBox: true }, { cleanupIDs: false }]
}
}
fs.writeFileSync(hugulpRc, JSON.stringify(config, null, ' '))
gutil.log(
gutil.colors.green(
'hugulp has been initialized (.hugulprc was created with default values)'
)
)
}
function build() {
gutil.log(gutil.colors.red(`hugulp v${module.exports.version}`))
require(path.join(fs.realpathSync(__dirname), 'gulp', 'build'))
gulp.start('build')
}
function watch() {
gutil.log(gutil.colors.red(`hugulp v${module.exports.version}`))
require(path.join(fs.realpathSync(__dirname), 'gulp', 'watch'))
gulp.start('watch')
}
function version() {
console.log('hugulp v' + module.exports.version)
}
program
.command('init')
.description('create default .hugulprc')
.action(init)
program
.command('version')
.description('display version information')
.action(version)
program
.command('build')
.description('optimize site (for publishing purposes)')
.action(build)
program
.command('watch')
.description('watch for changes to styles and/or javascript')
.action(watch)
program.parse(process.argv)