Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/dva-generate
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
8 changes: 6 additions & 2 deletions src/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ function generate(program, { cwd }) {

const [type, name] = program.args;

const lang = program.lang || 'css';

try {
switch (type) {
case 'model':
Expand All @@ -54,14 +56,15 @@ 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', {
sourcePath: cwd,
filePath: componentPath,
componentName,
css: program.css,
lang
});
info('create', `route ${name} with ${componentPath}`);
api('router.createRoute', {
Expand All @@ -81,14 +84,15 @@ 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', {
sourcePath: cwd,
filePath,
componentName,
css: program.css,
lang
});
})();
break;
Expand Down