-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
100 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const fse = require('fs-extra'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const {backup} = require('../utils/hasBackup'); | ||
const {getAllComponents, newComponent} = require('../utils/component'); | ||
const showProcess = require('../utils/showProcess'); | ||
const consola = require('consola'); | ||
|
||
module.exports = (output) => { | ||
const allComponents = getAllComponents(); | ||
const backupStyleDir = path.resolve(backup, `./components/styles`); | ||
const outputStyleDir = path.resolve(output, './styles'); | ||
|
||
showProcess.start('starting output all components........'); | ||
// 创建styles 目录 | ||
// 组件公用style目录是否存在 | ||
if (!fs.existsSync(outputStyleDir)) { | ||
fse.copySync(backupStyleDir, outputStyleDir); | ||
} | ||
|
||
let newCount = 0; | ||
for (const component of allComponents) { | ||
if (newComponent(component, output)) { | ||
newCount++; | ||
}; | ||
} | ||
showProcess.end(`Ending output ${newCount} components`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const {backup} = require('./hasBackup'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const fse = require('fs-extra'); | ||
const consola = require('consola'); | ||
|
||
// 获取所有组件名 | ||
const getAllComponents = () => { | ||
const files = fs.readdirSync(path.resolve(backup, './components')); | ||
const notComponents = ['template', 'styles', 'utils', 'index.tsx', 'tsconfig.json']; | ||
const components = new Set(files); | ||
for (const item of notComponents) { | ||
components.delete(item); | ||
} | ||
return Array.from(components); | ||
} | ||
|
||
// 是否有该组件 | ||
const hasComponent = (component) => { | ||
return getAllComponents().indexOf(component) !== -1; | ||
} | ||
|
||
|
||
// 创建单个组件,不解析依赖树 | ||
const newComponent = (component, output) => { | ||
const backupComponentDir = path.resolve(backup, `./components/${component}`); | ||
const backupComponentStyleDir = path.resolve(backupComponentDir, `./style`); | ||
const outputComponentDir = path.resolve(output, component); | ||
const outputComponentStyleDir = path.resolve(outputComponentDir, './style'); | ||
|
||
if (fs.existsSync(outputComponentDir)) { | ||
consola.error(`component ${component} has existed!`); | ||
return false; | ||
} | ||
|
||
// 创建组件 | ||
fs.mkdirSync(outputComponentDir); | ||
fse.copySync(backupComponentStyleDir, outputComponentStyleDir); | ||
|
||
const template = `import './style/index.less'; | ||
import ${component} from 'yoshino/lib/${component}'; | ||
export default ${component}`; | ||
fs.writeFileSync(path.resolve(outputComponentDir, './index.tsx'), template); | ||
|
||
consola.success(`component ${component} has been successfully created!`); | ||
return true; | ||
} | ||
|
||
module.exports = { | ||
getAllComponents, | ||
hasComponent, | ||
newComponent, | ||
} |
This file was deleted.
Oops, something went wrong.