@symbo.ls/cli 2.10.120 → 2.10.122
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/convert.js +50 -21
- package/package.json +2 -2
package/bin/convert.js
CHANGED
|
@@ -14,6 +14,17 @@ global.document = window.document
|
|
|
14
14
|
|
|
15
15
|
const TMP_DIR_NAME = ".smbls_convert_tmp"
|
|
16
16
|
|
|
17
|
+
async function mkdirp(dir) {
|
|
18
|
+
try {
|
|
19
|
+
return await fs.promises.mkdir(dir)
|
|
20
|
+
} catch (err) {
|
|
21
|
+
if (err.code !== 'EEXIST') {
|
|
22
|
+
throw err
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return null
|
|
26
|
+
}
|
|
27
|
+
|
|
17
28
|
program
|
|
18
29
|
.command('convert')
|
|
19
30
|
.description('Recursively convert and copy all DomQL components under a directory')
|
|
@@ -36,18 +47,12 @@ program
|
|
|
36
47
|
|
|
37
48
|
// Resolve source & destination directories
|
|
38
49
|
const srcPath = path.resolve(src || './src')
|
|
39
|
-
const destPath = path.resolve(dest ||
|
|
50
|
+
const destPath = path.resolve(dest || desiredFormat)
|
|
40
51
|
const tmpDirPath = path.resolve(path.dirname(destPath), TMP_DIR_NAME)
|
|
41
52
|
|
|
42
|
-
// Make tmp
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
} catch (err) {
|
|
46
|
-
if (err.code !== 'EEXIST') {
|
|
47
|
-
console.log(err)
|
|
48
|
-
return 1;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
53
|
+
// Make tmp and dist directories
|
|
54
|
+
await mkdirp(tmpDirPath)
|
|
55
|
+
await mkdirp(destPath)
|
|
51
56
|
|
|
52
57
|
const origFiles = await fs.promises.readdir(srcPath)
|
|
53
58
|
|
|
@@ -62,24 +67,48 @@ program
|
|
|
62
67
|
})
|
|
63
68
|
|
|
64
69
|
// Convert components
|
|
65
|
-
const
|
|
66
|
-
for (const
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const importPath = `${filePath}/index.js`
|
|
70
|
+
const componentDirs = await fs.promises.readdir(tmpDirPath)
|
|
71
|
+
for (const componentDir of componentDirs) {
|
|
72
|
+
if (componentDir === 'Atoms') continue
|
|
73
|
+
let importDir = path.join(tmpDirPath, componentDir)
|
|
74
|
+
if ((await fs.promises.stat(importDir)).isDirectory()) {
|
|
75
|
+
// Import the module
|
|
76
|
+
const importPath = `${importDir}/index.js`
|
|
73
77
|
console.log(`importing ${importPath}`)
|
|
74
78
|
const domqlModule = (await import(importPath)).default
|
|
75
79
|
console.log(domqlModule)
|
|
80
|
+
|
|
81
|
+
// Create directory for component in dest dir
|
|
82
|
+
const destComponentDirPath = `${destPath}/${componentDir}`
|
|
83
|
+
await mkdirp(destComponentDirPath)
|
|
84
|
+
|
|
85
|
+
// Convert & append each exported domql object
|
|
86
|
+
const uniqueImports = []
|
|
87
|
+
let fileContents = ""
|
|
88
|
+
let first = true
|
|
76
89
|
for (const key in domqlModule) {
|
|
77
90
|
const component = domqlModule[key]
|
|
78
|
-
|
|
91
|
+
component.__name = key
|
|
92
|
+
const out = convert(component, desiredFormat, {
|
|
79
93
|
verbose: false,
|
|
80
|
-
exportDefault:
|
|
94
|
+
exportDefault: false,
|
|
95
|
+
returnMitosisIR: true,
|
|
96
|
+
importsToRemove: uniqueImports,
|
|
97
|
+
removeReactImport: !first
|
|
81
98
|
})
|
|
82
|
-
|
|
99
|
+
|
|
100
|
+
fileContents = fileContents + out.str + '\n'
|
|
101
|
+
uniqueImports.push(...out.mitosisIR.imports)
|
|
102
|
+
first = false
|
|
103
|
+
}
|
|
104
|
+
console.log(uniqueImports)
|
|
105
|
+
|
|
106
|
+
// Write file
|
|
107
|
+
if (fileContents.length > 0) {
|
|
108
|
+
const fh = await fs.promises
|
|
109
|
+
.open(`${destComponentDirPath}/index.js`, 'w')
|
|
110
|
+
await fh.writeFile(fileContents, 'utf8')
|
|
111
|
+
await fh.close()
|
|
83
112
|
}
|
|
84
113
|
}
|
|
85
114
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/cli",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.122",
|
|
4
4
|
"description": "Fetch your Symbols configuration",
|
|
5
5
|
"main": "bin/fetch.js",
|
|
6
6
|
"author": "Symbols",
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"standard": {
|
|
28
28
|
"parser": "babel-eslint"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "6d969a3ea842c89f518ca5c43636ddb06055e8ba"
|
|
31
31
|
}
|