@symbo.ls/cli 2.11.158 → 2.11.160
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 +98 -83
- package/package.json +2 -2
package/bin/convert.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
-
|
|
2
|
+
// TODO: --only flag doesn't work!!!
|
|
3
3
|
import { program } from './program.js'
|
|
4
4
|
import { convert } from 'kalduna'
|
|
5
5
|
import { parse } from 'globusa'
|
|
@@ -14,32 +14,41 @@ const jsdom = new JSDOM('<html><head></head><body></body></html>')
|
|
|
14
14
|
global.window = jsdom.window
|
|
15
15
|
global.document = window.document
|
|
16
16
|
|
|
17
|
-
const
|
|
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
|
-
]
|
|
17
|
+
const INTERNAL_UIKIT_CONF = {
|
|
18
|
+
excludedComponents: [
|
|
19
|
+
// We have our own React Svg implementation
|
|
20
|
+
'Svg',
|
|
21
|
+
|
|
22
|
+
// We have our own React Box implementation
|
|
23
|
+
'Box',
|
|
24
|
+
|
|
25
|
+
// These are not domql objects
|
|
26
|
+
'keySetters',
|
|
27
|
+
'getSystemTheme',
|
|
28
|
+
'splitTransition',
|
|
29
|
+
'transformDuration',
|
|
30
|
+
'transformShadow',
|
|
31
|
+
'transformTransition',
|
|
32
|
+
|
|
33
|
+
// FIXME: Temporary list of components we want to skip
|
|
34
|
+
'DatePicker',
|
|
35
|
+
'DatePickerDay',
|
|
36
|
+
'DatePickerTwoColumns',
|
|
37
|
+
'DatePickerGrid',
|
|
38
|
+
'DatePickerGridContainer',
|
|
39
|
+
|
|
40
|
+
// Not a domql object (headless-datepicker)
|
|
41
|
+
'calendar'
|
|
42
|
+
],
|
|
43
|
+
|
|
44
|
+
// Can be strings or regex patterns
|
|
45
|
+
excludedDirectories: [
|
|
46
|
+
// TODO: Review these ignores with @nikoloza
|
|
47
|
+
/Threejs$/,
|
|
48
|
+
/Editorjs$/,
|
|
49
|
+
/User$/
|
|
50
|
+
]
|
|
51
|
+
}
|
|
43
52
|
const TMP_DIR_NAME = '.smbls_convert_tmp'
|
|
44
53
|
const TMP_DIR_PACKAGE_JSON_STR = JSON.stringify({
|
|
45
54
|
name: 'smbls_convert_tmp',
|
|
@@ -48,7 +57,7 @@ const TMP_DIR_PACKAGE_JSON_STR = JSON.stringify({
|
|
|
48
57
|
license: 'ISC'
|
|
49
58
|
})
|
|
50
59
|
|
|
51
|
-
function generatePackageJsonFile(
|
|
60
|
+
function generatePackageJsonFile (
|
|
52
61
|
sourcePackageJsonPath,
|
|
53
62
|
destPath,
|
|
54
63
|
globusaStruct,
|
|
@@ -62,7 +71,7 @@ function generatePackageJsonFile(
|
|
|
62
71
|
packageStruct = JSON.parse(str)
|
|
63
72
|
} catch (error) {
|
|
64
73
|
console.error(`Error when parsing ${sourcePackageJsonPath}`)
|
|
65
|
-
return
|
|
74
|
+
return
|
|
66
75
|
}
|
|
67
76
|
const split = packageStruct.name.split('/')
|
|
68
77
|
const packageName = split[split.length - 1]
|
|
@@ -73,12 +82,12 @@ function generatePackageJsonFile(
|
|
|
73
82
|
[`@emotion/${desiredFormat}`]: '^11.11.0',
|
|
74
83
|
'@emotion/css': '^11.11.0',
|
|
75
84
|
'@symbo.ls/create': 'latest',
|
|
76
|
-
'@symbo.ls/react': 'latest'
|
|
85
|
+
'@symbo.ls/react': 'latest'
|
|
77
86
|
}
|
|
78
87
|
globusaStruct.imports
|
|
79
88
|
.filter(imp => imp.path.match(/^@symbo\.ls\//))
|
|
80
89
|
.filter(imp => imp.path !== packageName)
|
|
81
|
-
.forEach(imp => deps[imp.path] = 'latest')
|
|
90
|
+
.forEach(imp => { deps[imp.path] = 'latest' })
|
|
82
91
|
|
|
83
92
|
// Generate final package.json string
|
|
84
93
|
const genStr = JSON.stringify({
|
|
@@ -87,7 +96,7 @@ function generatePackageJsonFile(
|
|
|
87
96
|
license: packageStruct.license ?? 'UNLICENSED',
|
|
88
97
|
dependencies: deps,
|
|
89
98
|
peerDependencies: {
|
|
90
|
-
|
|
99
|
+
react: '^18.2.0',
|
|
91
100
|
'react-dom': '^18.2.0'
|
|
92
101
|
},
|
|
93
102
|
main: 'index.js',
|
|
@@ -97,10 +106,8 @@ function generatePackageJsonFile(
|
|
|
97
106
|
fs.writeFileSync(destPath, genStr)
|
|
98
107
|
}
|
|
99
108
|
|
|
100
|
-
function isDirectory (dir) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const stat = fs.statSync(dir)
|
|
109
|
+
function isDirectory (dir) {
|
|
110
|
+
const stat = fs.statSync(dir, { throwIfNoEntry: false })
|
|
104
111
|
if (!stat) return false
|
|
105
112
|
|
|
106
113
|
return stat.isDirectory()
|
|
@@ -119,31 +126,31 @@ async function mkdirp (dir) {
|
|
|
119
126
|
}
|
|
120
127
|
|
|
121
128
|
// Returns a string
|
|
122
|
-
function convertDomqlModule(domqlModule, globusaStruct, desiredFormat, options) {
|
|
129
|
+
function convertDomqlModule (domqlModule, globusaStruct, desiredFormat, options) {
|
|
123
130
|
let convertedStr = ''
|
|
124
131
|
const whitelist = (options.only ? options.only.split(',') : null)
|
|
125
132
|
|
|
126
133
|
console.group()
|
|
127
134
|
const exports = Object.keys(domqlModule)
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const isSingleComponent = (exports.length === 1)
|
|
135
|
+
.filter(exportName => {
|
|
136
|
+
if (!whitelist) return true
|
|
137
|
+
if (whitelist.includes(exportName)) {
|
|
138
|
+
console.log(`Skipping ${exportName} component due to whitelist exclusion`)
|
|
139
|
+
return false
|
|
140
|
+
}
|
|
141
|
+
return true
|
|
142
|
+
})
|
|
143
|
+
.filter(exportName => {
|
|
144
|
+
if (!options.internalUikit) return true
|
|
145
|
+
if (INTERNAL_UIKIT_CONF.excludedComponents.includes(exportName)) {
|
|
146
|
+
console.log(`Skipping ${exportName} component due to internal uikit exclusion`)
|
|
147
|
+
return false
|
|
148
|
+
}
|
|
149
|
+
return true
|
|
150
|
+
})
|
|
151
|
+
|
|
146
152
|
const uniqueImports = []
|
|
153
|
+
let globalSymbolTable = {}
|
|
147
154
|
for (const idx in exports) {
|
|
148
155
|
const exportName = exports[idx]
|
|
149
156
|
|
|
@@ -155,15 +162,17 @@ function convertDomqlModule(domqlModule, globusaStruct, desiredFormat, options)
|
|
|
155
162
|
}
|
|
156
163
|
|
|
157
164
|
console.group()
|
|
158
|
-
console.log(dobj.__name) // NOTE
|
|
165
|
+
console.log(dobj.__name) // NOTE: Don't remove this
|
|
159
166
|
|
|
160
|
-
|
|
161
|
-
const
|
|
167
|
+
// NOTE: Don't use '===' here!
|
|
168
|
+
const isFirst = (idx == 0) // eslint-disable-line
|
|
169
|
+
const isLast = (idx == (exports.length - 1)) // eslint-disable-line
|
|
162
170
|
|
|
163
171
|
const kaldunaOpts = {
|
|
164
172
|
verbose: false,
|
|
165
173
|
returnMitosisIR: true,
|
|
166
|
-
|
|
174
|
+
globalSymbolTable,
|
|
175
|
+
exportDefault: false,
|
|
167
176
|
importsToRemove: uniqueImports,
|
|
168
177
|
|
|
169
178
|
/* NOTE: The option below prevents a name collision bug. For example:
|
|
@@ -175,14 +184,14 @@ function convertDomqlModule(domqlModule, globusaStruct, desiredFormat, options)
|
|
|
175
184
|
But, in this case, because A is in local scope as one of the exports,
|
|
176
185
|
the component import will be ignored, preventing the collision.
|
|
177
186
|
*/
|
|
178
|
-
componentImportsToIgnore: exports
|
|
187
|
+
componentImportsToIgnore: exports
|
|
179
188
|
}
|
|
180
189
|
|
|
181
190
|
let out = null
|
|
182
191
|
if (isFirst) {
|
|
183
192
|
out = convert(dobj, desiredFormat, {
|
|
184
193
|
...kaldunaOpts,
|
|
185
|
-
removeReactImport: false
|
|
194
|
+
removeReactImport: false
|
|
186
195
|
// NOTE(nikaoto): Commented these out because we're using deps now, so
|
|
187
196
|
// all the imports and decls are going to be redundant
|
|
188
197
|
// importsToInclude: globusaStruct.imports,
|
|
@@ -191,7 +200,7 @@ function convertDomqlModule(domqlModule, globusaStruct, desiredFormat, options)
|
|
|
191
200
|
} else {
|
|
192
201
|
out = convert(dobj, desiredFormat, {
|
|
193
202
|
...kaldunaOpts,
|
|
194
|
-
removeReactImport: true
|
|
203
|
+
removeReactImport: true
|
|
195
204
|
})
|
|
196
205
|
}
|
|
197
206
|
|
|
@@ -200,6 +209,7 @@ function convertDomqlModule(domqlModule, globusaStruct, desiredFormat, options)
|
|
|
200
209
|
convertedStr += '\n'
|
|
201
210
|
}
|
|
202
211
|
uniqueImports.push(...out.mitosisIR.imports)
|
|
212
|
+
globalSymbolTable = out.mitosisIR._globalSymbolTable
|
|
203
213
|
console.groupEnd()
|
|
204
214
|
}
|
|
205
215
|
console.groupEnd()
|
|
@@ -211,8 +221,8 @@ function convertDomqlModule(domqlModule, globusaStruct, desiredFormat, options)
|
|
|
211
221
|
// result to the destination. The tmpDirPath is used as a working directory for
|
|
212
222
|
// temporary files.
|
|
213
223
|
// Returns globusaStruct for later usage.
|
|
214
|
-
async function convertFile(srcPath, tmpDirPath, destPath,
|
|
215
|
-
|
|
224
|
+
async function convertFile (srcPath, tmpDirPath, destPath,
|
|
225
|
+
desiredFormat, options) {
|
|
216
226
|
// Parse with globusa
|
|
217
227
|
console.log(`Parsing components in ${srcPath}`)
|
|
218
228
|
const fileContent = await fs.promises.readFile(srcPath, 'utf8')
|
|
@@ -226,6 +236,7 @@ async function convertFile(srcPath, tmpDirPath, destPath,
|
|
|
226
236
|
entryPoints: [srcPath],
|
|
227
237
|
bundle: true,
|
|
228
238
|
sourcemap: true,
|
|
239
|
+
keepNames: false,
|
|
229
240
|
target: 'node12',
|
|
230
241
|
format: 'cjs',
|
|
231
242
|
outdir: tmpDirPath
|
|
@@ -263,20 +274,20 @@ program
|
|
|
263
274
|
.description('Convert and copy all DomQL components under a directory')
|
|
264
275
|
.argument('[src]', 'Source directory/file. By default, it is "src/"')
|
|
265
276
|
.argument('[dest]',
|
|
266
|
-
|
|
277
|
+
'Destination directory/file. Will be overwritten. By ' +
|
|
267
278
|
'default, it becomes the name of the desired format')
|
|
268
279
|
.option('--react', 'Convert all DomQL components to React')
|
|
269
280
|
.option('--angular', 'Convert all DomQL components to Angular')
|
|
270
281
|
.option('--vue2', 'Convert all DomQL components to Vue2')
|
|
271
282
|
.option('--vue3', 'Convert all DomQL components to Vue3')
|
|
272
283
|
.option('-t, --tmp-dir <path>',
|
|
273
|
-
|
|
284
|
+
'Use this directory for storing intermediate & build files instead of ' +
|
|
274
285
|
`the default (dest/${TMP_DIR_NAME})`)
|
|
275
286
|
.option('-o, --only <components>',
|
|
276
|
-
|
|
287
|
+
'Only convert these components; comma separated ' +
|
|
277
288
|
'(for example: --only=Flex,Img)')
|
|
278
289
|
.option('--internal-uikit',
|
|
279
|
-
|
|
290
|
+
'(For internal use only). ' +
|
|
280
291
|
'Excludes particular components from the conversion')
|
|
281
292
|
.action(async (src, dest, options) => {
|
|
282
293
|
if (!convert) {
|
|
@@ -307,7 +318,6 @@ program
|
|
|
307
318
|
console.erorr(`Source directory/file ('${srcPath}') does not exist`)
|
|
308
319
|
return 1
|
|
309
320
|
}
|
|
310
|
-
const srcIsDir = fs.statSync(srcPath).isDirectory()
|
|
311
321
|
|
|
312
322
|
// Resolve & create tmp dir
|
|
313
323
|
const tmpDirPath = options.tmpDir ??
|
|
@@ -323,7 +333,7 @@ program
|
|
|
323
333
|
await pj.close()
|
|
324
334
|
|
|
325
335
|
// Convert single file. Output will also be a single file.
|
|
326
|
-
if (!
|
|
336
|
+
if (!isDirectory(srcPath)) {
|
|
327
337
|
// Determine destFilePath and create it if needed
|
|
328
338
|
let destFilePath
|
|
329
339
|
if (dest) {
|
|
@@ -331,7 +341,7 @@ program
|
|
|
331
341
|
if (!fs.existsSync(dest)) {
|
|
332
342
|
// dest doesn't exist. That's the output file we'll create.
|
|
333
343
|
destFilePath = path.resolve(dest)
|
|
334
|
-
} else if (
|
|
344
|
+
} else if (isDirectory(dest)) {
|
|
335
345
|
// dest exists and is a directory. Create our output file inside it.
|
|
336
346
|
destFilePath = path.join(path.resolve(dest), path.basename(srcPath))
|
|
337
347
|
} else {
|
|
@@ -364,7 +374,7 @@ program
|
|
|
364
374
|
// dest doesn't exist. Create it.
|
|
365
375
|
destDirPath = path.resolve(dest)
|
|
366
376
|
await mkdirp(destDirPath)
|
|
367
|
-
} else if (
|
|
377
|
+
} else if (isDirectory(dest)) {
|
|
368
378
|
// dest exists and is a directory.
|
|
369
379
|
destDirPath = path.resolve(dest)
|
|
370
380
|
} else {
|
|
@@ -375,27 +385,31 @@ program
|
|
|
375
385
|
return 1
|
|
376
386
|
}
|
|
377
387
|
|
|
388
|
+
const ignoredFiles = ['index.js', 'package.json', 'node_modules', 'dist']
|
|
378
389
|
const sourceDirNames = (await fs.promises.readdir(srcPath))
|
|
379
|
-
|
|
390
|
+
.filter(dir => !ignoredFiles.includes(dir))
|
|
380
391
|
|
|
381
392
|
const dirs = []
|
|
382
393
|
|
|
383
394
|
for (const dir of sourceDirNames) {
|
|
384
395
|
// Ignored directories
|
|
385
396
|
if (options.internalUikit) {
|
|
386
|
-
|
|
387
|
-
if (dir.match(
|
|
388
|
-
if (
|
|
389
|
-
if (dir.match(/User$/)) continue
|
|
397
|
+
let skip = false
|
|
398
|
+
for (const pat of INTERNAL_UIKIT_CONF.excludedDirectories) { if (dir.match(pat)) { skip = true; break } }
|
|
399
|
+
if (skip) continue
|
|
390
400
|
}
|
|
391
401
|
|
|
392
402
|
const dirPath = path.join(srcPath, dir)
|
|
403
|
+
if (!isDirectory(dirPath)) {
|
|
404
|
+
console.log(`Skipping ${dirPath} because it is not a directory`)
|
|
405
|
+
continue
|
|
406
|
+
}
|
|
393
407
|
const indexFilePath = path.join(dirPath, 'index.js')
|
|
394
408
|
const pjFilePath = path.join(dirPath, 'package.json')
|
|
395
409
|
|
|
396
410
|
const globusaStruct = await convertFile(
|
|
397
|
-
indexFilePath,
|
|
398
|
-
path.join(tmpDirPath, dir),
|
|
411
|
+
indexFilePath, // src
|
|
412
|
+
path.join(tmpDirPath, dir), // tmp
|
|
399
413
|
path.join(destDirPath, dir, 'index.js'), // dst
|
|
400
414
|
desiredFormat,
|
|
401
415
|
options
|
|
@@ -403,7 +417,7 @@ program
|
|
|
403
417
|
|
|
404
418
|
if (fs.existsSync(pjFilePath)) {
|
|
405
419
|
generatePackageJsonFile(
|
|
406
|
-
pjFilePath,
|
|
420
|
+
pjFilePath, // src
|
|
407
421
|
path.join(destDirPath, dir, 'package.json'), // dst
|
|
408
422
|
globusaStruct,
|
|
409
423
|
desiredFormat,
|
|
@@ -416,9 +430,10 @@ program
|
|
|
416
430
|
|
|
417
431
|
// Generate top index.js file
|
|
418
432
|
if (dirs.length > 0) {
|
|
419
|
-
const importLines = dirs.map(d => `import ${d} from './${d}'`).join('\n') + '\n'
|
|
420
|
-
const exportLines = 'export {\n' + dirs.map(d => ` ${d}`).join(',\n') + '\n}\n'
|
|
421
|
-
const fileContent = importLines + '\n' + exportLines
|
|
433
|
+
// const importLines = dirs.map(d => `import ${d} from './${d}'`).join('\n') + '\n'
|
|
434
|
+
// const exportLines = 'export {\n' + dirs.map(d => ` ${d}`).join(',\n') + '\n}\n'
|
|
435
|
+
// const fileContent = importLines + '\n' + exportLines
|
|
436
|
+
const fileContent = dirs.map(d => `export * from './${d}'`).join('\n')
|
|
422
437
|
|
|
423
438
|
const fh = await fs.promises.open(path.join(destDirPath, 'index.js'), 'w')
|
|
424
439
|
await fh.writeFile(fileContent, 'utf8')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/cli",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.160",
|
|
4
4
|
"description": "Fetch your Symbols configuration",
|
|
5
5
|
"main": "bin/fetch.js",
|
|
6
6
|
"author": "Symbols",
|
|
@@ -25,5 +25,5 @@
|
|
|
25
25
|
"node-fetch": "^3.1.0",
|
|
26
26
|
"v8-compile-cache": "^2.3.0"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "f36bc99a2d0c1b771e3d8e104d1b1005b2b0a33a"
|
|
29
29
|
}
|