Skip to content

Commit 403ba07

Browse files
authored
[refactor] improve dev process with gulp watch
1 parent f327d2c commit 403ba07

File tree

4 files changed

+635
-94
lines changed

4 files changed

+635
-94
lines changed

‎.gitignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.DS_Store
2-
dest
2+
dev
3+
build
34
node_modules

‎gulpfile.js‎

Lines changed: 146 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const{
22
src,
33
dest,
4+
series,
45
parallel
56
}=require('gulp');
67

@@ -14,92 +15,163 @@ const replace = require('gulp-replace');
1415

1516
consthtmlmin=require('gulp-htmlmin');
1617

17-
constfolder={
18+
constwatch=require('gulp-watch');
19+
20+
constclean=require('gulp-clean');
21+
22+
constpath={
1823
src: 'src',
19-
dest: 'dest/web',
24+
dev: 'dev',
25+
build: 'build/web',
2026
nodeModules: 'node_modules',
2127
}
2228

2329
constfilename={
2430
css: "nighttab.min.css",
31+
jsDependencies: "nighttab.dependencies.js",
32+
jsFiles: "nighttab.files.js",
2533
js: "nighttab.min.js"
2634
}
2735

28-
functionmanifest(){
29-
returnsrc(folder.src+'/manifest.json')
30-
.pipe(dest(folder.dest))
31-
}
32-
33-
functionhtml(){
34-
returnsrc(folder.src+'/index.html')
35-
.pipe(replace(/\<\!\-\-\ css\-block\ \-\-\>([\s\S]*)\<\!\-\-\ end\-css\-block\ \-\-\>/mg,'<link rel="stylesheet" href="css/'+filename.css+'">'))
36-
.pipe(replace(/\<\!\-\-\ js\-block\ \-\-\>([\s\S]*)\<\!\-\-\ end\-js\-block\ \-\-\>/mg,'<script src="js/'+filename.js+'"></script>'))
37-
.pipe(htmlmin({
38-
collapseWhitespace: true
39-
}))
40-
.pipe(dest(folder.dest))
41-
}
42-
43-
functionfonts(){
44-
returnsrc(folder.src+'/fonts/**/*.*')
45-
.pipe(dest(folder.dest+'/fonts'))
46-
}
36+
constjsDependencies=[
37+
path.nodeModules+'/html5sortable/dist/html5sortable.min.js',
38+
path.nodeModules+'/invert-color/lib/invert.min.js'
39+
]
4740

48-
functionicons(){
49-
returnsrc(folder.src+'/icons/**/*.*')
50-
.pipe(dest(folder.dest+'/icons'))
51-
}
41+
constjsFiles=[
42+
path.src+'/js/helper.js',
43+
path.src+'/js/data.js',
44+
path.src+'/js/fontawesome.js',
45+
path.src+'/js/update.js',
46+
path.src+'/js/state.js',
47+
path.src+'/js/bookmarks.js',
48+
path.src+'/js/control.js',
49+
path.src+'/js/menu.js',
50+
path.src+'/js/header.js',
51+
path.src+'/js/modal.js',
52+
path.src+'/js/tip.js',
53+
path.src+'/js/shade.js',
54+
path.src+'/js/theme.js',
55+
path.src+'/js/date.js',
56+
path.src+'/js/greeting.js',
57+
path.src+'/js/transitional.js',
58+
path.src+'/js/clock.js',
59+
path.src+'/js/search.js',
60+
path.src+'/js/link.js',
61+
path.src+'/js/version.js',
62+
path.src+'/js/keyboard.js',
63+
path.src+'/js/background.js',
64+
path.src+'/js/layout.js',
65+
path.src+'/js/auto-suggest.js',
66+
path.src+'/js/pagelock.js',
67+
path.src+'/js/edge.js',
68+
path.src+'/js/init.js'
69+
]
5270

53-
functioncss(){
54-
returnsrc(folder.src+'/css/*.css')
55-
.pipe(concat(filename.css))
56-
.pipe(csso())
57-
.pipe(dest(folder.dest+'/css'))
71+
constbuild={
72+
manifest: function(){
73+
returnsrc(path.src+'/manifest.json')
74+
.pipe(dest(path.build))
75+
},
76+
html: function(){
77+
returnsrc(path.src+'/index.html')
78+
.pipe(replace(/\<\!\-\-\ css\-block\ \-\-\>([\s\S]*)\<\!\-\-\ end\-css\-block\ \-\-\>/mg,'<link rel="stylesheet" href="css/'+filename.css+'">'))
79+
.pipe(replace(/\<\!\-\-\ js\-block\ \-\-\>([\s\S]*)\<\!\-\-\ end\-js\-block\ \-\-\>/mg,'<script src="js/'+filename.js+'"></script>'))
80+
.pipe(htmlmin({
81+
collapseWhitespace: true
82+
}))
83+
.pipe(dest(path.build))
84+
},
85+
fonts: function(){
86+
returnsrc(path.src+'/fonts/**/*.*')
87+
.pipe(dest(path.build+'/fonts'))
88+
},
89+
icons: function(){
90+
returnsrc(path.src+'/icons/**/*.*')
91+
.pipe(dest(path.build+'/icons'))
92+
},
93+
css: function(){
94+
returnsrc(path.src+'/css/*.css')
95+
.pipe(concat(filename.css))
96+
.pipe(csso())
97+
.pipe(dest(path.build+'/css'))
98+
},
99+
jsDependencies: function(){
100+
returnsrc(jsDependencies)
101+
.pipe(concat(filename.jsDependencies))
102+
.pipe(dest(path.build+'/js'))
103+
},
104+
jsFiles: function(){
105+
returnsrc(jsFiles)
106+
.pipe(concat(filename.jsFiles))
107+
.pipe(uglify())
108+
.pipe(dest(path.build+'/js',{
109+
sourcemaps: '.'
110+
}))
111+
},
112+
js: function(){
113+
returnsrc([path.build+'/js/'+filename.jsDependencies,path.build+'/js/'+filename.jsFiles])
114+
.pipe(concat(filename.js))
115+
.pipe(dest(path.build+'/js',{
116+
sourcemaps: '.'
117+
}))
118+
},
119+
jsClean: function(){
120+
returnsrc([path.build+'/js/'+filename.jsDependencies,path.build+'/js/'+filename.jsFiles])
121+
.pipe(clean())
122+
}
58123
}
59124

60-
functionjs(){
61-
returnsrc([
62-
folder.nodeModules+'/html5sortable/dist/html5sortable.min.js',
63-
folder.nodeModules+'/invert-color/lib/invert.min.js',
64-
folder.src+'/js/helper.js',
65-
folder.src+'/js/data.js',
66-
folder.src+'/js/fontawesome.js',
67-
folder.src+'/js/update.js',
68-
folder.src+'/js/state.js',
69-
folder.src+'/js/bookmarks.js',
70-
folder.src+'/js/control.js',
71-
folder.src+'/js/menu.js',
72-
folder.src+'/js/header.js',
73-
folder.src+'/js/modal.js',
74-
folder.src+'/js/tip.js',
75-
folder.src+'/js/shade.js',
76-
folder.src+'/js/theme.js',
77-
folder.src+'/js/date.js',
78-
folder.src+'/js/greeting.js',
79-
folder.src+'/js/transitional.js',
80-
folder.src+'/js/clock.js',
81-
folder.src+'/js/search.js',
82-
folder.src+'/js/link.js',
83-
folder.src+'/js/version.js',
84-
folder.src+'/js/keyboard.js',
85-
folder.src+'/js/background.js',
86-
folder.src+'/js/layout.js',
87-
folder.src+'/js/auto-suggest.js',
88-
folder.src+'/js/pagelock.js',
89-
folder.src+'/js/edge.js',
90-
folder.src+'/js/init.js',
91-
])
92-
.pipe(concat(filename.js))
93-
.pipe(uglify())
94-
.pipe(dest(folder.dest+'/js',{
95-
sourcemaps: '.'
96-
}))
125+
constdev={
126+
manifest: function(){
127+
watch(path.src+'/manifest.json',{
128+
ignoreInitial: false
129+
},function(){
130+
returnsrc(path.src+'/manifest.json')
131+
.pipe(dest(path.dev))
132+
})
133+
},
134+
html: function(){
135+
watch(path.src+'/index.html',{
136+
ignoreInitial: false
137+
},function(){
138+
returnsrc(path.src+'/index.html')
139+
.pipe(dest(path.dev))
140+
})
141+
},
142+
fonts: function(){
143+
watch(path.src+'/fonts/**/*.*',{
144+
ignoreInitial: false
145+
},function(){
146+
returnsrc(path.src+'/fonts/**/*.*')
147+
.pipe(dest(path.dev+'/fonts'))
148+
})
149+
},
150+
icons: function(){
151+
watch(path.src+'/icons/**/*.*',{
152+
ignoreInitial: false
153+
},function(){
154+
returnsrc(path.src+'/icons/**/*.*')
155+
.pipe(dest(path.dev+'/icons'))
156+
})
157+
},
158+
css: function(){
159+
watch(path.src+'/css/*.css',{
160+
ignoreInitial: false
161+
},function(){
162+
returnsrc(path.src+'/css/*.css')
163+
.pipe(dest(path.dev+'/css'))
164+
})
165+
},
166+
js: function(){
167+
watch(jsFiles,{
168+
ignoreInitial: false
169+
},function(){
170+
returnsrc(jsFiles)
171+
.pipe(dest(path.dev+'/js'))
172+
})
173+
}
97174
}
98175

99-
exports.manifest=manifest;
100-
exports.html=html;
101-
exports.fonts=fonts;
102-
exports.icons=icons;
103-
exports.css=css;
104-
exports.js=js;
105-
exports.default=parallel(manifest,html,fonts,icons,css,js);
176+
exports.dev=parallel(dev.manifest,dev.html,dev.fonts,dev.icons,dev.css,dev.js)
177+
exports.build=series(parallel(build.manifest,build.html,build.fonts,build.icons,build.css),series(build.jsDependencies,build.jsFiles,build.js),build.jsClean)

0 commit comments

Comments
(0)