grunt-webpage-scaffold
Advanced tools
Comparing version
@@ -42,2 +42,3 @@ /* | ||
webpage_scaffold: { | ||
/* | ||
default_options: { | ||
@@ -58,2 +59,12 @@ options: { | ||
} | ||
}, | ||
*/ | ||
options: { | ||
//coffee: 'coffee/page/', | ||
js: 'js/page/', | ||
less: 'less/page/', | ||
//sass: 'sass/page/', | ||
demo: 'demos/', | ||
watchPath: 'http://localhost/git/moc/build/demos/', | ||
tplPath: '.tpl' | ||
} | ||
@@ -83,2 +94,5 @@ }, | ||
//test build new project | ||
grunt.registerTask('build', ['webpage_scaffold']); | ||
}; |
{ | ||
"name": "grunt-webpage-scaffold", | ||
"description": "Help build the new Webpage project, static resource automatic generation of page demo file and dependence (optional without JS file). Once to initialize grunt, open the default browser to observe the compiled Demo. At the same time will automatically start the Livereload pattern of development, we can start coding directly : )", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"homepage": "https://github.com/Mickey-/webpage-scaffold", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -12,25 +12,64 @@ /* | ||
'use strict'; | ||
module.exports = function(grunt) { | ||
return grunt.registerMultiTask('webpage_scaffold', 'Help build the new Webpage project, static resource automatic generation of page demo file and dependence (optional without JS file). Once to initialize grunt, open the default browser to observe the compiled Demo. At the same time will automatically start the Livereload pattern of development, we can start coding: )', function() { | ||
var options; | ||
options = this.options({ | ||
punctuation: '.', | ||
separator: ', ' | ||
module.exports = function(g) { | ||
return g.registerTask('init', 'Help build the new Webpage project, static resource automatic generation of page demo file and dependence (optional without JS file). Once to initialize grunt, open the default browser to observe the compiled Demo. At the same time will automatically start the Livereload pattern of development, we can start coding: )', function() { | ||
var done, files, gruntIns, ifNotNeedJs, open, opt, pageName, sc, scriptType, styleType, tplBuffer, write, writeError; | ||
require('colors'); | ||
open = require('open'); | ||
done = this.async(); | ||
opt = this.options({ | ||
coffee: false, | ||
js: 'js/page/', | ||
less: 'less/page/', | ||
sass: false, | ||
demo: 'demos/', | ||
watchPath: 'http://localhost/git/moc/build/demos/', | ||
tplPath: '.tpl' | ||
}); | ||
return this.files.forEach(function(f) { | ||
var src; | ||
src = f.src.filter(function(filepath) { | ||
if (!grunt.file.exists(filepath)) { | ||
grunt.log.warn('Source file "' + filepath + '" not found.'); | ||
return false; | ||
pageName = this.args[0]; | ||
ifNotNeedJs = this.args[1]; | ||
if (!pageName) { | ||
g.fail.warn('请指定新项目模块名称,如: ' + 'grunt init:modname'.inverse + '。注意默认会在新demo文件' + 'modname.html'.underline + '里引入' + 'modname.js'.cyan + '和' + 'modname.css'.cyan); | ||
} | ||
tplBuffer = g.file.read(opt.tplPath); | ||
tplBuffer = tplBuffer.replace(/#{pagename}/g, pageName); | ||
write = g.file.write; | ||
styleType = opt.sass ? 'sass' : 'less'; | ||
scriptType = opt.coffee ? 'coffee' : 'js'; | ||
files = [ | ||
{ | ||
dest: opt.demo + pageName + '.html', | ||
content: tplBuffer | ||
}, { | ||
dest: opt[styleType] + pageName + '.' + styleType, | ||
content: '.' + pageName + ' {\r\n\r\n}' | ||
}, { | ||
dest: opt[scriptType] + pageName + '.' + scriptType, | ||
content: '', | ||
ifNotNeedJs: ifNotNeedJs | ||
} | ||
]; | ||
files.forEach(function(v, k) { | ||
if (v.ifNotNeedJs === void 0 || !v.ifNotNeedJs) { | ||
if (write(v.dest, v.content)) { | ||
return g.log.ok(v.dest + '生成成功!'); | ||
} else { | ||
return true; | ||
return writeError(); | ||
} | ||
}).map(function(filepath) { | ||
return grunt.file.read(filepath); | ||
}).join(grunt.util.normalizelf(options.separator)); | ||
src += options.punctuation; | ||
grunt.file.write(f.dest, src); | ||
return grunt.log.writeln('File "' + f.dest + '" created.'); | ||
} | ||
}); | ||
gruntIns = g.log.write('\n模块' + pageName.cyan + '构建中...'); | ||
sc = g.util.spawn({ | ||
cmd: 'grunt' | ||
}, function(err, ret, code) { | ||
if (!err) { | ||
gruntIns.ok(); | ||
console.log('\n进入开发模式'.yellow); | ||
g.task.run(['watch']); | ||
open(opt.watchPath + pageName + '.html'); | ||
return done(true); | ||
} | ||
}); | ||
return writeError = function(msg) { | ||
return g.log.error(msg || '文件写入失败!'); | ||
}; | ||
}); | ||
@@ -37,0 +76,0 @@ }; |
Sorry, the diff of this file is not supported yet
14361
19.94%14
7.69%196
36.11%