ptap
Version:
pafang assets build tool.
245 lines (202 loc) • 6.32 kB
JavaScript
/**
* ptap
* Copyright (c) 2014 水木年华double
* Licensed under the MIT license.
*/
;
var CWD = process.cwd();
var ENV = process.env;
var STDIN = process.stdin,
STDOUT = process.stdout,
STDERR = process.stderr;
var spawn = require('child_process').spawn;
var path = require('path');
var ptapbin = path.resolve(__dirname, '../bin/ptap');
module.exports = function(grunt) {
// Please see the Grunt documentation for more information regarding task
// creation: http://gruntjs.com/creating-tasks
grunt.registerMultiTask('ptap', 'Generate seed file.', function() {
var done = this.async();
// if('buildcfg' === this.target){
//
// var options = this.options({
// flatten: false,
// name: null,
// version: null,
// path: 'src',
// baseurl: 'http://static.pinganfang.com/',
// dest: 'src',
// depFile: './src/seed.js',
// cfgFile: './src/config.json'
// });
//
// var kpc = require('node-kpc');
//
// var srcFiles = this.files.reduce(function(prev, file){
// return prev.concat(file.src);
// }, []);
//
// var pkgData;
// grunt.log.write('compiling ' + options.path + '... ')
//
// try {
// pkgData = kpc.compile({
// name: options.name,
// flatten: options.flatten,
// path: options.path
// }, srcFiles);
// } catch(e) {
// if (e.path && e.lineNumber) {
// grunt.log.error(e.path + '['+ e.lineNumber + ':' + e.column + ']');
// }
// grunt.log.error(e.message + '('+ e.path + ')');
// grunt.fatal(e);
// }
//
// grunt.log.ok();
//
//
// if (pkgData.ignoredFiles.length) {
// pkgData.ignoredFiles.forEach(function(file){
// grunt.log.writeln('Ignored "' + file.srcFile + '".');
// });
// }
//
//
// if (Object.keys(pkgData.modules).length) {
// var config = {};
//
// var configjson = options.cfgFile || path.join(options.dest, 'config.json');
// var seedjs = options.depFile || path.join(options.dest, 'seed.js');
//
// config.modules = pkgData.modules;
//
// var pkg = {};
// pkg[options.name] = {
// "path": options.baseurl + options.name+"/"+options.version+"/",
// "ignorePackageNameInUri": true,
// "debug": true
// }
//
// config.packages = pkg;
//
// var depFileCnt = '/** Generated by grunt-ptap **/\r\nKISSY.config('+JSON.stringify(config, null, 4)+')';
//
// grunt.file.write(configjson, JSON.stringify(config, null, 4));
// grunt.log.writeln('File "' + configjson + '" created.');
// grunt.file.write(seedjs, depFileCnt);
// grunt.log.writeln('File "' + seedjs + '" created.');
// }
//
// //grunt.task.run('kpc');
//
// done();
// }
if('build' === this.target){
var options = this.options({});
var argv = ['build'];
//不压缩则使用ascii
if(!options.compress){
argv.push('-a');
}
if(options.version){
argv.push('-v');
argv.push(options.version);
}
var ps = spawn(ptapbin, argv, {
env: ENV,
cwd: CWD,
stdio: [
STDIN,
STDOUT,
STDERR
]
});
ps.on('exit', function(){
done();
});
}
if('buildjs' === this.target){
var options = this.options({});
var argv = ['build'];
//不压缩则使用ascii
if(!options.compress){
argv.push('-a');
}
if(options.version){
argv.push('-v');
argv.push(options.version);
}
argv.push('-x');
argv.push('.js');
var ps = spawn(ptapbin, argv, {
env: ENV,
cwd: CWD,
stdio: [
STDIN,
STDOUT,
STDERR
]
});
ps.on('exit', function(){
done();
});
}
if('buildcss' === this.target){
var options = this.options({});
var argv = ['build'];
//不压缩则使用ascii
if(!options.compress){
argv.push('-a');
}
if(options.version){
argv.push('-v');
argv.push(options.version);
}
argv.push('-x');
argv.push('.css');
var ps = spawn(ptapbin, argv, {
env: ENV,
cwd: CWD,
stdio: [
STDIN,
STDOUT,
STDERR
]
});
ps.on('exit', function(){
done();
});
}
if('ascii' === this.target){
var argv = ['build', '-a'];
var ps = spawn(ptapbin, argv, {
env: ENV,
cwd: CWD,
stdio: [
STDIN,
STDOUT,
STDERR
]
});
ps.on('exit', function(){
done();
});
}
if('copy' === this.target){
var argv = ['build', '-o'];
var ps = spawn(ptapbin, argv, {
env: ENV,
cwd: CWD,
stdio: [
STDIN,
STDOUT,
STDERR
]
});
ps.on('exit', function(){
done();
});
}
});
};