@symbo.ls/cli 2.11.158 → 2.11.159

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.
Files changed (2) hide show
  1. package/bin/convert.js +58 -43
  2. package/package.json +2 -2
package/bin/convert.js CHANGED
@@ -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 IGNORED_FILES = ['index.js', 'package.json', 'node_modules', 'dist']
18
- const EXCLUDED_FROM_INTERNAL_UIKIT = [
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
- ]
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',
@@ -97,10 +106,8 @@ function generatePackageJsonFile(
97
106
  fs.writeFileSync(destPath, genStr)
98
107
  }
99
108
 
100
- function isDirectory (dir) { // eslint-disable-line no-unused-vars
101
- if (!fs.existsSync(dir)) return false
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()
@@ -135,7 +142,7 @@ function convertDomqlModule(domqlModule, globusaStruct, desiredFormat, options)
135
142
  })
136
143
  .filter(exportName => {
137
144
  if (!options.internalUikit) return true
138
- if (EXCLUDED_FROM_INTERNAL_UIKIT.includes(exportName)) {
145
+ if (INTERNAL_UIKIT_CONF.excludedComponents.includes(exportName)) {
139
146
  console.log(`Skipping ${exportName} component due to internal uikit exclusion`)
140
147
  return false
141
148
  }
@@ -144,6 +151,7 @@ function convertDomqlModule(domqlModule, globusaStruct, desiredFormat, options)
144
151
 
145
152
  const isSingleComponent = (exports.length === 1)
146
153
  const uniqueImports = []
154
+ let globalSymbolTable = {}
147
155
  for (const idx in exports) {
148
156
  const exportName = exports[idx]
149
157
 
@@ -163,6 +171,7 @@ function convertDomqlModule(domqlModule, globusaStruct, desiredFormat, options)
163
171
  const kaldunaOpts = {
164
172
  verbose: false,
165
173
  returnMitosisIR: true,
174
+ globalSymbolTable,
166
175
  exportDefault: isSingleComponent,
167
176
  importsToRemove: uniqueImports,
168
177
 
@@ -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()
@@ -307,7 +317,6 @@ program
307
317
  console.erorr(`Source directory/file ('${srcPath}') does not exist`)
308
318
  return 1
309
319
  }
310
- const srcIsDir = fs.statSync(srcPath).isDirectory()
311
320
 
312
321
  // Resolve & create tmp dir
313
322
  const tmpDirPath = options.tmpDir ??
@@ -323,7 +332,7 @@ program
323
332
  await pj.close()
324
333
 
325
334
  // Convert single file. Output will also be a single file.
326
- if (!srcIsDir) {
335
+ if (!isDirectory(srcPath)) {
327
336
  // Determine destFilePath and create it if needed
328
337
  let destFilePath
329
338
  if (dest) {
@@ -331,7 +340,7 @@ program
331
340
  if (!fs.existsSync(dest)) {
332
341
  // dest doesn't exist. That's the output file we'll create.
333
342
  destFilePath = path.resolve(dest)
334
- } else if (fs.statSync(dest).isDirectory()) {
343
+ } else if (isDirectory(dest)) {
335
344
  // dest exists and is a directory. Create our output file inside it.
336
345
  destFilePath = path.join(path.resolve(dest), path.basename(srcPath))
337
346
  } else {
@@ -364,7 +373,7 @@ program
364
373
  // dest doesn't exist. Create it.
365
374
  destDirPath = path.resolve(dest)
366
375
  await mkdirp(destDirPath)
367
- } else if (fs.statSync(dest).isDirectory()) {
376
+ } else if (isDirectory(dest)) {
368
377
  // dest exists and is a directory.
369
378
  destDirPath = path.resolve(dest)
370
379
  } else {
@@ -375,21 +384,26 @@ program
375
384
  return 1
376
385
  }
377
386
 
387
+ const ignoredFiles = ['index.js', 'package.json', 'node_modules', 'dist']
378
388
  const sourceDirNames = (await fs.promises.readdir(srcPath))
379
- .filter(file => !IGNORED_FILES.includes(file))
389
+ .filter(dir => !ignoredFiles.includes(dir))
380
390
 
381
391
  const dirs = []
382
392
 
383
393
  for (const dir of sourceDirNames) {
384
394
  // Ignored directories
385
395
  if (options.internalUikit) {
386
- // TODO: check with @nikoloza on these components
387
- if (dir.match(/Threejs$/)) continue
388
- if (dir.match(/Editorjs$/)) continue
389
- if (dir.match(/User$/)) continue
396
+ let skip = false
397
+ for (const pat of INTERNAL_UIKIT_CONF.excludedDirectories)
398
+ 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
 
@@ -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.158",
3
+ "version": "2.11.159",
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": "cbed9bf1f1a15c02489444ffa264acbaf2e8d918"
28
+ "gitHead": "4dbce17a65f09e9c7e9451f5d9042ddbe351280b"
29
29
  }