@symbo.ls/cli 2.11.16 → 2.11.23

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