From 277133a75287f3d57680eeaa22a9789dbc1dcab0 Mon Sep 17 00:00:00 2001 From: xuqiang Date: Mon, 4 Dec 2017 17:54:50 +0800 Subject: [PATCH] add dva-generate option [lang] for specifing style file type. eg: less. default: css --- bin/dva-generate | 1 + src/generate.js | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/dva-generate b/bin/dva-generate index 33ff74e..15fd0b8 100755 --- a/bin/dva-generate +++ b/bin/dva-generate @@ -6,6 +6,7 @@ program .option('--no-css', 'Don\'t generate css for component and routeComponent') .option('--base [base]', 'Specify base path, default src') .option('--entry [entry]', 'Specify entry path, default ${base}/src') + .option('--lang [lang]', 'Specify style lang, default css') .parse(process.argv); require('../lib/generate')(program, { diff --git a/src/generate.js b/src/generate.js index c46274d..f263a96 100644 --- a/src/generate.js +++ b/src/generate.js @@ -32,6 +32,8 @@ function generate(program, { cwd }) { const [type, name] = program.args; + const lang = program.lang || 'css'; + try { switch (type) { case 'model': @@ -54,7 +56,7 @@ function generate(program, { cwd }) { (() => { const componentName = upperCamelCase(name); const componentPath = `${base}/routes/${componentName}.js`; - const componentCSSPath = `${base}/routes/${componentName}.css`; + const componentCSSPath = `${base}/routes/${componentName}.${lang || 'css'}`; const withCSS = program.css ? `, ${componentCSSPath}` : ''; info('create', `routeComponent ${componentPath}${withCSS}`); api('routeComponents.create', { @@ -62,6 +64,7 @@ function generate(program, { cwd }) { filePath: componentPath, componentName, css: program.css, + lang }); info('create', `route ${name} with ${componentPath}`); api('router.createRoute', { @@ -81,7 +84,7 @@ function generate(program, { cwd }) { const fileDir = dirname(name); const componentName = upperCamelCase(fileName); const filePath = join(`${base}/components`, fileDir, `${componentName}.js`); - const componentCSSPath = join(`${base}/components`, fileDir, `${componentName}.css`); + const componentCSSPath = join(`${base}/components`, fileDir, `${componentName}.${lang || 'css'}`); const withCSS = program.css ? `, ${componentCSSPath}` : ''; info('create', `component ${filePath}${withCSS}`); api('components.create', { @@ -89,6 +92,7 @@ function generate(program, { cwd }) { filePath, componentName, css: program.css, + lang }); })(); break;