fix: move types to template

This commit is contained in:
思忠 2020-04-07 17:43:19 +08:00
parent ca3fa80519
commit d57575d665
2 changed files with 12 additions and 3 deletions

View File

@ -1,5 +1,6 @@
import * as path from 'path';
import * as fse from 'fs-extra';
import * as ejs from 'ejs';
import Generator from './generator';
export default async (api) => {
@ -11,12 +12,20 @@ export default async (api) => {
const appStoreTemplatePath = path.join(templatePath, 'appStore.ts.ejs');
const pageStoreTemplatePath = path.join(templatePath, 'pageStore.ts.ejs');
const pageStoresTemplatePath = path.join(templatePath, 'pageStores.ts.ejs');
const typesTemplatePath = path.join(templatePath, 'types.ts.ejs');
const projectType = getValue('PROJECT_TYPE');
// copy types/index.ts to .ice/store/index.ts
await fse.copy(path.join(__dirname, '..', 'src/types'), path.join(targetPath, './store'));
// TODO: 考虑合并为一个
applyMethod('addIceTypesExport', { source: './store', specifier: '{ IStore }', exportName: 'store?: IStore' });
applyMethod('addIceTypesExport', { source: './store/icestore' });
// render template/types.ts.ejs to .ice/store/types.ts
const typesTemplateContent = fse.readFileSync(typesTemplatePath, 'utf-8');
const typesTargetPath = path.join(targetPath, 'store', 'types.ts');
const content = ejs.render(typesTemplateContent);
fse.ensureFileSync(typesTargetPath);
fse.writeFileSync(typesTargetPath, content, 'utf-8');
applyMethod('addIceTypesExport', { source: './store/types' });
onGetWebpackConfig(config => {
if (command === 'build') {

View File

@ -1,4 +1,4 @@
import * as types from '$ice/appStore';
import * as types from '../appStore';
export type IRootDispatch = types.IRootDispatch;
export type IRootState = types.IRootState;