|
|
|
|
|
|
var nunjucks = require('nunjucks'); |
|
|
|
var chokidar = require('chokidar'); |
|
|
|
|
|
|
|
exports.command = 'codegen [dir]'; |
|
|
|
exports.command = 'codegen [dir] [file]'; |
|
|
|
exports.desc = "generate mixin code"; |
|
|
|
exports.builder = function (yargs) { |
|
|
|
return yargs.positional('dir', { |
|
|
|
|
|
|
}).positional('file', { |
|
|
|
describe: 'the target file if specified', |
|
|
|
type: 'string', |
|
|
|
default: '' |
|
|
|
}).option('watch', { |
|
|
|
alias: 'w', |
|
|
|
describe: 'Watch for file changes', |
|
|
|
|
|
|
|
|
|
|
exports.handler = function (argv) { |
|
|
|
var cwd = path.resolve(__dirname, '../..', argv.dir); |
|
|
|
var file = '' |
|
|
|
if (argv.file != '') { |
|
|
|
file = argv.file; |
|
|
|
} |
|
|
|
var data = {}; |
|
|
|
var env = nunjucks.configure(cwd, { |
|
|
|
trimBlocks: true, |
|
|
|
|
|
|
if (err) { |
|
|
|
return console.error(chalk.red(err)); |
|
|
|
} |
|
|
|
|
|
|
|
renderAll(env, cwd, files, data); |
|
|
|
if (files.indexOf(file) >=0) { |
|
|
|
render(env, cwd, file, data); |
|
|
|
} |
|
|
|
else { |
|
|
|
renderAll(env, cwd, files, data); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
if (argv.watch) { |
|
|
|