Skip to content

Commit

Permalink
Chore: Update make new component logic (#15542)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun authored and luckyCao committed May 17, 2019
1 parent 64ed780 commit 28583d8
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions build/bin/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ if (!process.argv[2]) {
}

const path = require('path');
const fs = require('fs');
const fileSave = require('file-save');
const uppercamelcase = require('uppercamelcase');
const componentname = process.argv[2];
Expand Down Expand Up @@ -104,6 +105,29 @@ fileSave(path.join(__dirname, '../../components.json'))
.write(JSON.stringify(componentsFile, null, ' '), 'utf8')
.end('\n');

// 添加到 index.scss
const sassPath = path.join(__dirname, '../../packages/theme-chalk/src/index.scss');
const sassImportText = `${fs.readFileSync(sassPath)}@import "./${componentname}.scss";`;
fileSave(sassPath)
.write(sassImportText, 'utf8')
.end('\n');

// 添加到 element-ui.d.ts
const elementTsPath = path.join(__dirname, '../../types/element-ui.d.ts');

let elementTsText = `${fs.readFileSync(elementTsPath)}
/** ${ComponentName} Component */
export class ${ComponentName} extends El${ComponentName} {}`;

const index = elementTsText.indexOf('export') - 1;
const importString = `import { El${ComponentName} } from './${componentname}'`;

elementTsText = elementTsText.slice(0, index) + importString + '\n' + elementTsText.slice(index);

fileSave(elementTsPath)
.write(elementTsText, 'utf8')
.end('\n');

// 创建 package
Files.forEach(file => {
fileSave(path.join(PackagePath, file.filename))
Expand Down

0 comments on commit 28583d8

Please sign in to comment.