-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvlink.js
executable file
·66 lines (54 loc) · 1.92 KB
/
vlink.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
66
#!/usr/bin/env node
const { resolve, dirname, relative, join } = require('path')
const { readdir, stat, writeFile, readFile } = require('fs').promises
const { program } = require('commander')
const fs = require('fs')
const shell = require('shelljs')
const package = require('./package.json')
program.version(package.version)
program
.command('link [componentFolder]')
.description('Link VTEX IO components')
.action(async (componentFolder) => {
const scriptList = ['yarn concurrently']
componentFolder = componentFolder ?? '.'
for await (const file of getFiles(componentFolder)) {
const relativePath = relative(componentFolder, file)
scriptList.push(`"cd ${relativePath ? relativePath : componentFolder} && vtex link"`)
}
if(!shell.find('package.json').length) shell.exec('yarn init --yes')
shell.exec(scriptList.join(' '))
});
program
.command('fix [componentFolder]')
.description('Unlink and Link VTEX IO components')
.action(async (componentFolder) => {
const scriptList = ['yarn concurrently']
componentFolder = componentFolder ?? '.'
for await (const file of getFiles(componentFolder)) {
const relativePath = relative(componentFolder, file)
scriptList.push(`"cd ${relativePath ? relativePath : componentFolder} && vtex unlink && vtex link"`)
}
if(!shell.find('package.json').length) shell.exec('yarn init --yes')
shell.exec(scriptList.join(' '))
});
program.parse(process.argv);
async function* getFiles(rootPath) {
const fileNames = await readdir(rootPath)
for (const fileName of fileNames) {
if (fileName) {
const path = resolve(rootPath, fileName)
if (
(await stat(path)).isDirectory() &&
!path.includes('node_modules') &&
!path.includes('.')
) {
yield* getFiles(path)
} else {
if(path.includes('manifest.json')) {
yield dirname(path)
}
}
}
}
}