forked from alibaba-fusion/next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.js
30 lines (24 loc) · 1015 Bytes
/
init.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const path = require('path');
const fs = require('fs-extra');
const { components } = require('./config');
const { logger, getComponentName } = require('./utils');
const cwd = process.cwd();
const hasEntry = component => ['core', 'locale', 'mixin-ui-state', 'util', 'validate'].indexOf(component) === -1;
const indexJSPath = path.join(cwd, 'src', 'index.js');
const indexJSContent = components.map(component => {
if (!hasEntry(component)) {
return '';
}
const name = getComponentName(component);
return `export { default as ${name} } from './${component}';\n`;
}).join('');
fs.writeFileSync(indexJSPath, indexJSContent);
const indexNoResetScssPath = path.join(cwd, 'index-noreset.scss');
const indexNoResetScssContent = components.map(component => {
if (!hasEntry(component)) {
return '';
}
return `@import "lib/${component}/index.scss";\n`;
}).join('');
fs.writeFileSync(indexNoResetScssPath, indexNoResetScssContent);
logger.success('Init project successfully!');