接上一个博客源码共读-UMI-2,接下来,我们来继续执行 umi generate
从第一个博客中我们知道,执行umi generate 会执行lib/scripts/ generate.js
lib/scripts/generate.js
import yParser from 'yargs-parser';
import generate from '../generate';
const argv = yParser(process.argv.slice(2));
const [type, file] = argv._;
generate({
type,
file,
useClass: argv.c || argv.class || false,
isDirectory: argv.d || argv.directory || false,
});
取出参数调用generate
../generate.js
import assert from 'assert';
import page from './generators/page';
const generators = {
page,
};
这里应该是为了后续扩展使用的,这里暂时只有一个page
export default function(opts = {}) {
const { type, file } = opts;
assert(type, 'opts.type should be supplied');
assert(typeof type === 'string', 'opts.file should be string');
assert(file,