-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-components-directories.js
62 lines (51 loc) · 1.48 KB
/
create-components-directories.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
57
58
59
60
61
62
const path = require('path');
const fs = require('fs');
const glob = require('glob');
const report = require('@alexistessier/report')
const saveFile = require('xebia-web-common/scripts/save-file');
const options = require('./cli-options');
const rawFiles = [
...glob.sync(path.join(__dirname, 'src/main/components/*.vue')),
...glob.sync(path.join(__dirname, 'src/main/components/*.js'))
];
const componentsDirectories = glob.sync(path.join(__dirname, 'src/main/components/*')).filter(dir => {
return rawFiles.indexOf(dir) === -1;
});
componentsDirectories.forEach(dir => {
const componentName = path.basename(dir);
const indexJsFile = path.join(dir, 'index.js');
const indexVueFile = path.join(dir, 'index.vue');
const indexJsExists = fs.existsSync(indexJsFile);
if(!fs.existsSync(indexVueFile) || options.override) {
if (indexJsExists) {
const indexJsContent = fs.readFileSync(indexJsFile, {encoding: 'utf-8'});
saveFile({
path: indexVueFile,
content: (
`<script>
//this file was generated from ${__dirname}/${__filename}, don't override it
${indexJsContent}
</script>
`
)
})
}
else{
saveFile({
path: indexVueFile,
content: (
`<script>
//this file was generated from ${__dirname}/${__filename}, don't override it
export default require('./${componentName}');
</script>
`
)
})
}
}
if (options.removeExistingIndex && indexJsExists) {
fs.unlink(indexJsFile, err => {
report('warning', 'File deleted at path '+indexJsFile);
});
}
})