Skip to content

Commit d9940ac

Browse files
author
Shuwen Qian
committed
Move dbg and getPkgInfo methods to C
1 parent 978e5e0 commit d9940ac

5 files changed

Lines changed: 41 additions & 49 deletions

File tree

gulp/env.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
(function() {
22
'use strict';
33

4+
var fs = require('fs');
5+
var gif = require('gulp-if');
6+
var gutil = require('gulp-util');
7+
var debug = require('gulp-debug');
8+
9+
var IS_DEBUG = !!gutil.env.debug;
10+
11+
function dbg(t) {
12+
return gif(IS_DEBUG, debug({title:t}));
13+
}
14+
15+
function getPkgInfo() {
16+
return JSON.parse(fs.readFileSync('package.json', 'utf8'));
17+
}
18+
419
module.exports = {
520
ROOT: '.',
621
SRC: 'src/',
@@ -18,6 +33,9 @@
1833
DOCS_PORT: 8001,
1934
PATCH_LIST: [
2035
'bower_components/moment/min/moment.min.js'
21-
]
36+
],
37+
38+
dbg: dbg,
39+
getPkgInfo: getPkgInfo
2240
};
2341
})();

gulp/tasks/build.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,11 @@
1919
var run = require('run-sequence');
2020

2121
module.exports = function(gulp, plugins, C) {
22-
var IS_DEBUG = !!plugins.gutil.env.debug;
23-
24-
function dbg(t) {
25-
return plugins.gif(IS_DEBUG, plugins.debug({title:t}));
26-
}
2722

2823
gulp.task('patch-lib', function() {
2924

3025
gulp.src(C.PATCH_LIST, {base: C.BOWER})
31-
.pipe(dbg('patch-lib'))
26+
.pipe(C.dbg('patch-lib'))
3227
.pipe(plugins.wrap(function(data) {
3328
if (data.file.contents.toString('utf8').indexOf('/*patched*/') !== -1) {
3429
return "{{{contents}}}";
@@ -46,7 +41,7 @@
4641
gulp.task('copy', function() {
4742
return gulp.src([j(C.SRC,'**/*.+(html|js|woff)'), j('!',C.SRC,'**/example.html')])
4843
.pipe(plugins.cache('copy'))
49-
.pipe(dbg('copy'))
44+
.pipe(C.dbg('copy'))
5045
.pipe(gulp.dest(C.BUILD));
5146
});
5247

@@ -56,25 +51,25 @@
5651
.pipe(plugins.cache('scss'))
5752
.pipe(plugins.sass({includePaths: C.SASS_INCLUDE}).on('error', plugins.sass.logError))
5853
.pipe(plugins.postcss([autoprefixer({browsers: ['last 2 versions']})]))
59-
.pipe(dbg('sass'))
54+
.pipe(C.dbg('sass'))
6055
.pipe(gulp.dest(C.BUILD))
6156
.pipe(plugins.wrap(function(data) {
6257
data.fname = path.basename(data.file.relative,'.css');
6358
return wrapper;
6459
},{},{engine:"hogan"}))
6560
.pipe(plugins.rename({basename:"style", extname: ".html"}))
66-
.pipe(dbg('sass-html'))
61+
.pipe(C.dbg('sass-html'))
6762
.pipe(gulp.dest(C.BUILD));
6863
});
6964

7065
gulp.task('font', function() {
7166
return gulp.src(j(C.SRC, C.SHARED, '/fonts/fonts.scss'))
7267
.pipe(plugins.sass({includePaths: C.SASS_INCLUDE}).on('error', plugins.sass.logError))
73-
.pipe(dbg('font'))
68+
.pipe(C.dbg('font'))
7469
.pipe(gulp.dest(C.BUILD + 'shared/fonts/'))
7570
.pipe(plugins.wrap("<style>{{{contents}}}</style>",{},{engine:"hogan"}).on('error',console.log))
7671
.pipe(plugins.rename("fonts.html").on('error',console.log))
77-
.pipe(dbg('font-output'))
72+
.pipe(C.dbg('font-output'))
7873
.pipe(gulp.dest(j(C.BUILD,'/shared/fonts/')));
7974
});
8075

@@ -121,7 +116,7 @@
121116
inlineCss: true,
122117
implicitStrip: false
123118
}, excludes, C.BUILD))
124-
.pipe(dbg('vulcanize-modules'))
119+
.pipe(C.dbg('vulcanize-modules'))
125120
.pipe(plugins.htmlmin())
126121
.pipe(gulp.dest(C.BUILD));
127122

@@ -130,7 +125,7 @@
130125
inlineScripts: true,
131126
inlineCss: true
132127
}))
133-
.pipe(dbg('vulcanize-lib'))
128+
.pipe(C.dbg('vulcanize-lib'))
134129
.pipe(gulp.dest(C.BUILD));
135130
return merge(modules, lib);
136131
});
@@ -148,7 +143,7 @@
148143
});
149144

150145
gulp.task('lib-version', function() {
151-
var pkg = getPkgInfo();
146+
var pkg = C.getPkgInfo();
152147
var templatePath = j(C.TEMPLATES, '/lib_version.html');
153148
var templateString = fs.readFileSync(templatePath, 'utf8');
154149
var template = hogan.compile(templateString);
@@ -174,7 +169,7 @@
174169
}))
175170
.pipe(plugins.inlinemin())
176171
.pipe(plugins.header('<!--\n' + fs.readFileSync('BANNER.txt','utf8') + ' -->'))
177-
.pipe(dbg('vulcanize-modules'))
172+
.pipe(C.dbg('vulcanize-modules'))
178173
.pipe(gulp.dest(C.DIST));
179174

180175
var lib = gulp.src(j(C.BUILD,'strand.html'))
@@ -191,7 +186,7 @@
191186
}))
192187
.pipe(plugins.inlinemin())
193188
.pipe(plugins.header('<!--\n' + fs.readFileSync('BANNER.txt','utf8') + ' -->'))
194-
.pipe(dbg('vulcanize-lib'))
189+
.pipe(C.dbg('vulcanize-lib'))
195190
.pipe(gulp.dest(C.DIST));
196191

197192
return merge(modules, lib);

gulp/tasks/docs.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@
2222
var run = require('run-sequence');
2323

2424
module.exports = function(gulp, plugins, C) {
25-
var IS_DEBUG = !!plugins.gutil.env.debug;
26-
27-
function dbg(t) {
28-
return plugins.gif(IS_DEBUG, plugins.debug({title:t}));
29-
}
3025

3126
gulp.task('docs', ['copy:docs', 'sass:docs', 'docs:templates']);
3227

@@ -43,19 +38,19 @@
4338
.pipe(gulp.dest(C.BUILD_DOCS));
4439

4540
var bower_components = gulp.src([j(C.BOWER,'/webcomponentsjs/**/*'), j(C.BOWER,'/polymer/**/*')], {base:C.BOWER})
46-
.pipe(dbg('copy-bower'))
41+
.pipe(C.dbg('copy-bower'))
4742
.pipe(gulp.dest(j(C.BUILD_DOCS,C.BOWER)));
4843

4944
var lib = gulp.src(j(C.BUILD,'**'))
50-
.pipe(dbg('copy-lib'))
45+
.pipe(C.dbg('copy-lib'))
5146
.pipe(gulp.dest(j(C.BUILD_DOCS,C.BOWER,'/strand/dist')));
5247

5348
return merge(bower_components, merged_static, lib);
5449
});
5550

5651
gulp.task('sass:docs', function() {
5752
return gulp.src(j(C.DOCS,'/**/*.scss'))
58-
.pipe(dbg('sass-docs'))
53+
.pipe(C.dbg('sass-docs'))
5954
.pipe(plugins.sass({includePaths: C.SASS_INCLUDE}).on('error', plugins.sass.logError))
6055
.pipe(plugins.postcss([autoprefixer({browsers: ['last 2 versions']})]))
6156
.pipe(gulp.dest(C.BUILD_DOCS));
@@ -162,7 +157,7 @@
162157
});
163158
}
164159

165-
var pkg = getPkgInfo();
160+
var pkg = C.getPkgInfo();
166161

167162
// Create moduleList from directory listing
168163
var modules = glob.sync(j(C.MODULE_MASK, "/doc.json"), {cwd:C.SRC});
@@ -233,7 +228,7 @@
233228
.pipe(plugins.cache('docs_module'))
234229
.pipe(injectBehaviorDocs(behaviorsMap))
235230
.pipe(injectModuleData(pkg, moduleMap, articleList, articleMap))
236-
.pipe(dbg('docs-modules'))
231+
.pipe(C.dbg('docs-modules'))
237232
.pipe(through.obj(function(file, enc, cb) {
238233
var moduleDoc = JSON.parse(file.contents);
239234
var templatePath = j(C.DOCS,'/component_template.html');
@@ -257,16 +252,16 @@
257252
.pipe(plugins.marked().on('error',console.log))
258253
.pipe(injectArticleData(pkg, moduleMap, articleList, articleMap))
259254
.pipe(plugins.rename({prefix: 'article_'}))
260-
.pipe(dbg('docs-articles'))
255+
.pipe(C.dbg('docs-articles'))
261256
.pipe(gulp.dest(C.BUILD_DOCS));
262257

263258
return merge(indexStream, moduleStream, articleStream);
264259
});
265260

266261
gulp.task('gh-pages', function() {
267-
var pkg = getPkgInfo();
262+
var pkg = C.getPkgInfo();
268263
return gulp.src(C.BUILD_DOCS+'**/*')
269-
.pipe(dbg('gh-pages'))
264+
.pipe(C.dbg('gh-pages'))
270265
.pipe(plugins.ghPages({
271266
message: 'docs updates v'+pkg.version
272267
}));

gulp/tasks/live.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@
2323

2424
module.exports = function(gulp, plugins, C) {
2525

26-
var IS_DEBUG = !!plugins.gutil.env.debug;
27-
28-
function dbg(t) {
29-
return plugins.gif(IS_DEBUG, plugins.debug({title:t}));
30-
}
31-
3226
gulp.task('watch', function () {
3327
gulp.watch(j(C.SRC, C.MODULE_MASK, '/*.scss'), ['sass']);
3428
gulp.watch(j(C.SRC, C.MODULE_MASK, C.MODULE_HTML), ['copy', 'vulcanize']);

gulp/tasks/release.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@
2323

2424
module.exports = function(gulp, plugins, C) {
2525

26-
var IS_DEBUG = !!plugins.gutil.env.debug;
27-
28-
function dbg(t) {
29-
return plugins.gif(IS_DEBUG, plugins.debug({title:t}));
30-
}
31-
3226
function inc(version) {
3327
if(!version) version = 'patch';
3428
return gulp.src(['package.json', 'bower.json'])
@@ -66,23 +60,19 @@
6660
}
6761
}
6862
}))
69-
.pipe(dbg('changelog'))
63+
.pipe(C.dbg('changelog'))
7064
.pipe(gulp.dest('.'));
7165
});
7266

73-
function getPkgInfo() {
74-
return JSON.parse(fs.readFileSync('package.json', 'utf8'));
75-
}
76-
7767
gulp.task('stage-release', function() {
78-
var pkg = getPkgInfo();
68+
var pkg = C.getPkgInfo();
7969
return gulp.src([C.DIST, 'package.json', 'bower.json', 'CHANGELOG.md'])
8070
.pipe(plugins.git.add())
8171
.pipe(plugins.git.commit('Release v'+pkg.version));
8272
});
8373

8474
gulp.task('tag-release', function() {
85-
var pkg = getPkgInfo();
75+
var pkg = C.getPkgInfo();
8676
plugins.git.tag('v'+pkg.version, 'Version '+pkg.version, function(err) {
8777
console.log(err);
8878
});

0 commit comments

Comments
 (0)