-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcli.js
68 lines (58 loc) · 2 KB
/
cli.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
63
64
65
const { AutoComplete, prompt } = require('enquirer');
const { copyMagentoFile } = require('./copyThemeHelper');
const path = require('path')
const FileHound = require('filehound');
const themesDir = path.resolve(process.cwd(), './dev/tools/frontools/config/themes.json')
const themesConfig = require(themesDir)
async function init() {
const themeChoices = Object.keys(themesConfig)
const response = await prompt([
{
type: 'select',
name: 'parentTheme',
message: 'Pick your parent theme:',
limit: 10,
choices: themeChoices
},
{
type: 'select',
name: 'childTheme',
message: 'Pick your child theme:',
limit: 10,
choices: themeChoices
},
{
type: 'select',
name: 'fileType',
message: 'Pick your file type:',
limit: 10,
initial: 2,
choices: ['scss', 'js', 'phtml']
},
]);
async function fileToCopy(response) {
const parentTheme = themesConfig[response.parentTheme];
const childTheme = themesConfig[response.childTheme];
const parentThemeDirectory = themesConfig[response.parentTheme].src;
const fileTypeRequested = response.fileType;
const foundFiles = FileHound.create()
.paths(parentThemeDirectory)
.ext(fileTypeRequested)
.find()
.then((files) => {
const prompt = new AutoComplete({
name: 'file',
message: 'Choose your file to copy: (This file will be committed immediately)',
limit: 10,
choices: files
});
prompt.run()
.then((answer) => {
copyMagentoFile(answer, parentTheme, childTheme)
})
.catch(console.error);
})
}
fileToCopy(response)
}
init();