@symbo.ls/cli 2.11.16 → 2.11.21
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 +55 -45
- package/package.json +2 -2
package/bin/convert.js
CHANGED
|
@@ -7,9 +7,9 @@ import fs from 'fs'
|
|
|
7
7
|
import path from 'path'
|
|
8
8
|
import { JSDOM } from 'jsdom'
|
|
9
9
|
|
|
10
|
-
const l = (n) => console.log(`mark${n}`)
|
|
10
|
+
const l = (n) => console.log(`mark${n}`) // eslint-disable-line no-unused-vars
|
|
11
11
|
|
|
12
|
-
const jsdom = new JSDOM(
|
|
12
|
+
const jsdom = new JSDOM('<html><head></head><body></body></html>')
|
|
13
13
|
global.window = jsdom.window
|
|
14
14
|
global.document = window.document
|
|
15
15
|
|
|
@@ -23,15 +23,15 @@ const EXCLUDED_FROM_INTERNAL_UIKIT = [
|
|
|
23
23
|
'transformShadow',
|
|
24
24
|
'transformTransition'
|
|
25
25
|
]
|
|
26
|
-
const TMP_DIR_NAME =
|
|
26
|
+
const TMP_DIR_NAME = '.smbls_convert_tmp'
|
|
27
27
|
const TMP_DIR_PACKAGE_JSON_STR = JSON.stringify({
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
//"main": "index.js",
|
|
31
|
-
|
|
32
|
-
})
|
|
28
|
+
name: 'smbls_convert_tmp',
|
|
29
|
+
version: '1.0.0',
|
|
30
|
+
// "main": "index.js",
|
|
31
|
+
license: 'ISC'
|
|
32
|
+
})
|
|
33
33
|
|
|
34
|
-
function isDirectory(dir) {
|
|
34
|
+
function isDirectory (dir) { // eslint-disable-line no-unused-vars
|
|
35
35
|
if (!fs.existsSync(dir)) return false
|
|
36
36
|
|
|
37
37
|
const stat = fs.statSync(dir)
|
|
@@ -41,7 +41,7 @@ function isDirectory(dir) {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// Essentially does 'mkdir -P'
|
|
44
|
-
async function mkdirp(dir) {
|
|
44
|
+
async function mkdirp (dir) {
|
|
45
45
|
try {
|
|
46
46
|
return await fs.promises.mkdir(dir)
|
|
47
47
|
} catch (err) {
|
|
@@ -52,13 +52,13 @@ async function mkdirp(dir) {
|
|
|
52
52
|
return null
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
async function importDomqlModule(modulePath) {
|
|
55
|
+
async function importDomqlModule (modulePath) {
|
|
56
56
|
console.log(`importing ${modulePath}`)
|
|
57
57
|
return (await import(modulePath)).default
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
function convertDomqlModule(domqlModule, desiredFormat, options) {
|
|
61
|
-
let convertedStr =
|
|
60
|
+
function convertDomqlModule (domqlModule, desiredFormat, options) {
|
|
61
|
+
let convertedStr = ''
|
|
62
62
|
|
|
63
63
|
console.group()
|
|
64
64
|
const uniqueImports = []
|
|
@@ -72,24 +72,35 @@ function convertDomqlModule(domqlModule, desiredFormat, options) {
|
|
|
72
72
|
continue
|
|
73
73
|
}
|
|
74
74
|
console.log(key)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
75
|
+
// try {
|
|
76
|
+
// import('domql-to-mitosis').then(({ convert }) => {
|
|
77
|
+
// console.log('convert', convert)
|
|
78
|
+
// if (convert) {
|
|
79
|
+
console.group()
|
|
80
|
+
const component = domqlModule[key]
|
|
81
|
+
component.__name = key
|
|
82
|
+
|
|
83
|
+
const out = convert(component, desiredFormat, {
|
|
84
|
+
verbose: false,
|
|
85
|
+
exportDefault: exportCount === 1,
|
|
86
|
+
returnMitosisIR: true,
|
|
87
|
+
importsToRemove: uniqueImports,
|
|
88
|
+
removeReactImport: !first,
|
|
89
|
+
removeUseContextImport
|
|
90
|
+
})
|
|
86
91
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
convertedStr = convertedStr + out.str + '\n'
|
|
93
|
+
uniqueImports.push(...out.mitosisIR.imports)
|
|
94
|
+
first = false
|
|
95
|
+
if (out.mitosisIR._useContext) { removeUseContextImport = true }
|
|
96
|
+
console.groupEnd()
|
|
97
|
+
// } else {
|
|
98
|
+
// throw new Error('Convert from `domql-to-mitosis` is not defined. Try to install `domql-to-mitosis` and run this command again.')
|
|
99
|
+
// }
|
|
100
|
+
// })
|
|
101
|
+
// } catch (err) {
|
|
102
|
+
// throw new Error('`domql-to-mitosis` is not found.')
|
|
103
|
+
// }
|
|
93
104
|
}
|
|
94
105
|
console.groupEnd()
|
|
95
106
|
|
|
@@ -122,7 +133,7 @@ program
|
|
|
122
133
|
const srcPath = path.resolve(src || './src')
|
|
123
134
|
if (!fs.existsSync(srcPath)) {
|
|
124
135
|
console.erorr(`Source directory/file ('${srcPath}') does not exist`)
|
|
125
|
-
return 1
|
|
136
|
+
return 1
|
|
126
137
|
}
|
|
127
138
|
const srcIsDir = fs.statSync(srcPath).isDirectory()
|
|
128
139
|
|
|
@@ -141,7 +152,7 @@ program
|
|
|
141
152
|
// Convert single file. Output will also be a single file.
|
|
142
153
|
if (!srcIsDir) {
|
|
143
154
|
// Determine destFilePath and create it if needed
|
|
144
|
-
let destFilePath
|
|
155
|
+
let destFilePath
|
|
145
156
|
if (dest) {
|
|
146
157
|
// dest is given.
|
|
147
158
|
if (!fs.existsSync(dest)) {
|
|
@@ -171,7 +182,7 @@ program
|
|
|
171
182
|
sourcemap: true,
|
|
172
183
|
target: 'node12',
|
|
173
184
|
format: 'cjs',
|
|
174
|
-
outfile: bundledFilePath
|
|
185
|
+
outfile: bundledFilePath
|
|
175
186
|
})
|
|
176
187
|
|
|
177
188
|
// Import the module
|
|
@@ -180,9 +191,9 @@ program
|
|
|
180
191
|
// Convert & append each exported domql object
|
|
181
192
|
console.log(`Converting modules in ${bundledFilePath}:`)
|
|
182
193
|
const convertedModuleStr = convertDomqlModule(
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
194
|
+
domqlModule,
|
|
195
|
+
desiredFormat,
|
|
196
|
+
options
|
|
186
197
|
)
|
|
187
198
|
|
|
188
199
|
// Write file
|
|
@@ -192,13 +203,13 @@ program
|
|
|
192
203
|
await fh.close()
|
|
193
204
|
}
|
|
194
205
|
|
|
195
|
-
return 0
|
|
206
|
+
return 0
|
|
196
207
|
}
|
|
197
208
|
|
|
198
209
|
// We're converting multiple files (in a directory)
|
|
199
210
|
// Determine destDirPath & create it if needed
|
|
200
211
|
if (!dest) dest = path.resolve(desiredFormat)
|
|
201
|
-
let destDirPath
|
|
212
|
+
let destDirPath
|
|
202
213
|
if (!fs.existsSync(dest)) {
|
|
203
214
|
// dest doesn't exist. Create it.
|
|
204
215
|
destDirPath = path.resolve(dest)
|
|
@@ -209,11 +220,11 @@ program
|
|
|
209
220
|
} else {
|
|
210
221
|
// dest exists and is not a directory.
|
|
211
222
|
console.error(`The destination ('${path.resolve(dest)}') must be a directory when the source ('${srcPath}') is a directory`)
|
|
212
|
-
return 1
|
|
223
|
+
return 1
|
|
213
224
|
}
|
|
214
225
|
|
|
215
226
|
const origFiles = (await fs.promises.readdir(srcPath))
|
|
216
|
-
|
|
227
|
+
.filter(file => !IGNORED_FILES.includes(file))
|
|
217
228
|
|
|
218
229
|
// Bundle components
|
|
219
230
|
await esbuild.build({
|
|
@@ -228,7 +239,6 @@ program
|
|
|
228
239
|
// Convert components
|
|
229
240
|
const componentDirs = await fs.promises.readdir(tmpDirPath)
|
|
230
241
|
for (const componentDir of componentDirs) {
|
|
231
|
-
console.log(componentDirs)
|
|
232
242
|
const importDir = path.join(tmpDirPath, componentDir)
|
|
233
243
|
if ((await fs.promises.stat(importDir)).isDirectory()) {
|
|
234
244
|
// Import the module
|
|
@@ -241,15 +251,15 @@ program
|
|
|
241
251
|
|
|
242
252
|
// Convert & append each exported domql object
|
|
243
253
|
const convertedStr = convertDomqlModule(
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
254
|
+
domqlModule,
|
|
255
|
+
desiredFormat,
|
|
256
|
+
options
|
|
247
257
|
)
|
|
248
258
|
|
|
249
259
|
// Write file
|
|
250
260
|
if (convertedStr.length > 0) {
|
|
251
261
|
const fh = await fs.promises
|
|
252
|
-
|
|
262
|
+
.open(`${destComponentDirPath}/index.js`, 'w')
|
|
253
263
|
await fh.writeFile(convertedStr, 'utf8')
|
|
254
264
|
await fh.close()
|
|
255
265
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/cli",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.21",
|
|
4
4
|
"description": "Fetch your Symbols configuration",
|
|
5
5
|
"main": "bin/fetch.js",
|
|
6
6
|
"author": "Symbols",
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"domql-to-mitosis": "latest"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "56cbd0c8ecdf0ec6427bcbfa7f853dbd04020b9d"
|
|
31
31
|
}
|