Skip to content

Commit

Permalink
✨ feat: 优化新建模块模板的 alias
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Mar 18, 2021
1 parent 5523dc6 commit 4b29256
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions scripts/create-package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const argv = require('yargs').argv;
const lernaConfig = require('../../lerna.json');

const packagePath = path.join(__dirname, '../../packages');
const tsconfigPath = path.join(__dirname, '../../tsconfig.json');
const jestconfigPath = path.join(__dirname, '../../jest.config.base.js');

/**
* 检查是否已经存在模块
Expand Down Expand Up @@ -35,6 +37,31 @@ const checkTemplateFiles = (entries) => {
}
};

/**
* 添加模块 alias 依赖
* @param pkg
*/
const addAlias = (pkg: string) => {
const tsconfigFile = fs.readFileSync(tsconfigPath, 'utf-8');

const tsconfig = tsconfigFile.replace(
'"@arvinxu/float-label-input"',
`"@arvinxu/${pkg}": ["./packages/${pkg}/src"],
"@arvinxu/${pkg}/*": ["./packages/${pkg}/src/*"],
"@arvinxu/float-label-input"`,
);

fs.writeFileSync(tsconfigPath, tsconfig);

const jestconfigFile = fs.readFileSync(jestconfigPath, 'utf-8');
const jestconfig = jestconfigFile.replace(
"'@arvinxu/float-label-input'",
`'@arvinxu/${pkg}': '<rootDir>/packages/${pkg}/src',
'@arvinxu/float-label-input'`,
);
fs.writeFileSync(jestconfigPath, jestconfig);
};

/**
* 创建
*/
Expand Down Expand Up @@ -81,6 +108,8 @@ const create = async () => {
});

await Promise.all(filesPromise);

addAlias(pkg);
};

create();

0 comments on commit 4b29256

Please sign in to comment.