-
Notifications
You must be signed in to change notification settings - Fork 0
/
reci.commands.js
56 lines (47 loc) · 1.28 KB
/
reci.commands.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const template = `
import fs from "fs"
const {{ functionName }} = () => {
console.log('{{ varaibleName }}')
}
export default {{ functionName }}
`
module.exports = {
add: async (args, lib) => {
const [componentName, ...rest] = args
const { log, fs } = lib
const withCss = rest.include('--withCss')
// create component and its styles files
await fs
.create({
path: 'src/component',
children: [
{
path: componentName + '.jsx',
content: generateContent({
template: 'component',
variables: {
componentName,
stylesPath: './' + componentName + '.css',
},
}),
},
withCss && {
path: componentName + '.css',
content: generateContent({
template: 'styles',
}),
},
],
})
.catch(log.error)
// add new compoenent to index file
await fs.edit('components/index.ts', (err, content) => {
if(err) {
return log.error(err)
}
const newLine = `\n export { default as ${componentName} } from './${componentName}.tsx'`
return content + newLine
}).catch(log.error)
log.success(componentName + 'added succefully')
},
}