@symbo.ls/cli 2.11.131 → 2.11.158
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/LICENSE +21 -0
- package/bin/convert.js +127 -37
- package/package.json +4 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 symbo.ls
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/bin/convert.js
CHANGED
|
@@ -6,10 +6,7 @@ import { parse } from 'globusa'
|
|
|
6
6
|
import fs from 'fs'
|
|
7
7
|
import path from 'path'
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
import syncWebpack from 'webpack'
|
|
11
|
-
import { promisify } from 'util'
|
|
12
|
-
const webpack = promisify(syncWebpack)
|
|
9
|
+
import * as esbuild from 'esbuild'
|
|
13
10
|
|
|
14
11
|
// Set up jsdom
|
|
15
12
|
import { JSDOM } from 'jsdom'
|
|
@@ -19,15 +16,29 @@ global.document = window.document
|
|
|
19
16
|
|
|
20
17
|
const IGNORED_FILES = ['index.js', 'package.json', 'node_modules', 'dist']
|
|
21
18
|
const EXCLUDED_FROM_INTERNAL_UIKIT = [
|
|
19
|
+
// We have our own React Svg implementation
|
|
22
20
|
'Svg',
|
|
21
|
+
|
|
22
|
+
// We have our own React Box implementation
|
|
23
|
+
'Box',
|
|
24
|
+
|
|
25
|
+
// These are not domql objects
|
|
23
26
|
'keySetters',
|
|
24
27
|
'getSystemTheme',
|
|
25
28
|
'splitTransition',
|
|
26
29
|
'transformDuration',
|
|
27
30
|
'transformShadow',
|
|
28
31
|
'transformTransition',
|
|
32
|
+
|
|
33
|
+
// FIXME: Temporary list of components we want to skip
|
|
34
|
+
'DatePicker',
|
|
29
35
|
'DatePickerDay',
|
|
36
|
+
'DatePickerTwoColumns',
|
|
30
37
|
'DatePickerGrid',
|
|
38
|
+
'DatePickerGridContainer',
|
|
39
|
+
|
|
40
|
+
// Not a domql object (headless-datepicker)
|
|
41
|
+
'calendar',
|
|
31
42
|
]
|
|
32
43
|
const TMP_DIR_NAME = '.smbls_convert_tmp'
|
|
33
44
|
const TMP_DIR_PACKAGE_JSON_STR = JSON.stringify({
|
|
@@ -37,6 +48,55 @@ const TMP_DIR_PACKAGE_JSON_STR = JSON.stringify({
|
|
|
37
48
|
license: 'ISC'
|
|
38
49
|
})
|
|
39
50
|
|
|
51
|
+
function generatePackageJsonFile(
|
|
52
|
+
sourcePackageJsonPath,
|
|
53
|
+
destPath,
|
|
54
|
+
globusaStruct,
|
|
55
|
+
desiredFormat,
|
|
56
|
+
options
|
|
57
|
+
) {
|
|
58
|
+
// Extract package name from source package.json
|
|
59
|
+
const str = fs.readFileSync(sourcePackageJsonPath, { encoding: 'utf8' })
|
|
60
|
+
let packageStruct
|
|
61
|
+
try {
|
|
62
|
+
packageStruct = JSON.parse(str)
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.error(`Error when parsing ${sourcePackageJsonPath}`)
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const split = packageStruct.name.split('/')
|
|
68
|
+
const packageName = split[split.length - 1]
|
|
69
|
+
|
|
70
|
+
// Generate list of dependencies
|
|
71
|
+
const deps = {
|
|
72
|
+
'css-in-props': 'latest',
|
|
73
|
+
[`@emotion/${desiredFormat}`]: '^11.11.0',
|
|
74
|
+
'@emotion/css': '^11.11.0',
|
|
75
|
+
'@symbo.ls/create': 'latest',
|
|
76
|
+
'@symbo.ls/react': 'latest',
|
|
77
|
+
}
|
|
78
|
+
globusaStruct.imports
|
|
79
|
+
.filter(imp => imp.path.match(/^@symbo\.ls\//))
|
|
80
|
+
.filter(imp => imp.path !== packageName)
|
|
81
|
+
.forEach(imp => deps[imp.path] = 'latest')
|
|
82
|
+
|
|
83
|
+
// Generate final package.json string
|
|
84
|
+
const genStr = JSON.stringify({
|
|
85
|
+
name: `@symbo.ls/${desiredFormat}-${packageName}`,
|
|
86
|
+
version: packageStruct.version ?? '1.0.0',
|
|
87
|
+
license: packageStruct.license ?? 'UNLICENSED',
|
|
88
|
+
dependencies: deps,
|
|
89
|
+
peerDependencies: {
|
|
90
|
+
'react': '^18.2.0',
|
|
91
|
+
'react-dom': '^18.2.0'
|
|
92
|
+
},
|
|
93
|
+
main: 'index.js',
|
|
94
|
+
source: 'index.js'
|
|
95
|
+
}, undefined, 2)
|
|
96
|
+
|
|
97
|
+
fs.writeFileSync(destPath, genStr)
|
|
98
|
+
}
|
|
99
|
+
|
|
40
100
|
function isDirectory (dir) { // eslint-disable-line no-unused-vars
|
|
41
101
|
if (!fs.existsSync(dir)) return false
|
|
42
102
|
|
|
@@ -123,8 +183,10 @@ function convertDomqlModule(domqlModule, globusaStruct, desiredFormat, options)
|
|
|
123
183
|
out = convert(dobj, desiredFormat, {
|
|
124
184
|
...kaldunaOpts,
|
|
125
185
|
removeReactImport: false,
|
|
126
|
-
|
|
127
|
-
|
|
186
|
+
// NOTE(nikaoto): Commented these out because we're using deps now, so
|
|
187
|
+
// all the imports and decls are going to be redundant
|
|
188
|
+
// importsToInclude: globusaStruct.imports,
|
|
189
|
+
// declarationsToInclude: globusaStruct.declarations,
|
|
128
190
|
})
|
|
129
191
|
} else {
|
|
130
192
|
out = convert(dobj, desiredFormat, {
|
|
@@ -148,6 +210,7 @@ function convertDomqlModule(domqlModule, globusaStruct, desiredFormat, options)
|
|
|
148
210
|
// Takes a source file, then bundles, parses and converts it and writes the
|
|
149
211
|
// result to the destination. The tmpDirPath is used as a working directory for
|
|
150
212
|
// temporary files.
|
|
213
|
+
// Returns globusaStruct for later usage.
|
|
151
214
|
async function convertFile(srcPath, tmpDirPath, destPath,
|
|
152
215
|
desiredFormat, options) {
|
|
153
216
|
// Parse with globusa
|
|
@@ -155,28 +218,23 @@ async function convertFile(srcPath, tmpDirPath, destPath,
|
|
|
155
218
|
const fileContent = await fs.promises.readFile(srcPath, 'utf8')
|
|
156
219
|
const globusaStruct = parse(fileContent)
|
|
157
220
|
|
|
158
|
-
// Bundle with webpack
|
|
159
|
-
const libraryName = 'banunu' // This can literally be anything
|
|
160
221
|
const fileName = path.basename(srcPath)
|
|
161
222
|
const bundledFilePath = path.resolve(tmpDirPath, fileName)
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
},
|
|
172
|
-
// experiments: { outputModule: true },
|
|
173
|
-
target: 'node',
|
|
174
|
-
mode: 'development'
|
|
223
|
+
|
|
224
|
+
// Bundle with esbuild
|
|
225
|
+
await esbuild.build({
|
|
226
|
+
entryPoints: [srcPath],
|
|
227
|
+
bundle: true,
|
|
228
|
+
sourcemap: true,
|
|
229
|
+
target: 'node12',
|
|
230
|
+
format: 'cjs',
|
|
231
|
+
outdir: tmpDirPath
|
|
175
232
|
})
|
|
176
233
|
|
|
177
234
|
// Import the bundled module to obtain exported domql objects
|
|
178
235
|
console.log(`Importing ${bundledFilePath}`)
|
|
179
|
-
const
|
|
236
|
+
const mod = (await import(bundledFilePath))
|
|
237
|
+
const domqlModule = mod.default
|
|
180
238
|
|
|
181
239
|
// Convert it/them with kalduna
|
|
182
240
|
console.log(`Converting components in ${bundledFilePath}:`)
|
|
@@ -196,12 +254,13 @@ async function convertFile(srcPath, tmpDirPath, destPath,
|
|
|
196
254
|
await fh.writeFile(convertedModuleStr, 'utf8')
|
|
197
255
|
await fh.close()
|
|
198
256
|
}
|
|
257
|
+
|
|
258
|
+
return globusaStruct
|
|
199
259
|
}
|
|
200
260
|
|
|
201
261
|
program
|
|
202
262
|
.command('convert')
|
|
203
|
-
.description('
|
|
204
|
-
'under a directory')
|
|
263
|
+
.description('Convert and copy all DomQL components under a directory')
|
|
205
264
|
.argument('[src]', 'Source directory/file. By default, it is "src/"')
|
|
206
265
|
.argument('[dest]',
|
|
207
266
|
'Destination directory/file. Will be overwritten. By ' +
|
|
@@ -214,16 +273,12 @@ program
|
|
|
214
273
|
'Use this directory for storing intermediate & build files instead of ' +
|
|
215
274
|
`the default (dest/${TMP_DIR_NAME})`)
|
|
216
275
|
.option('-o, --only <components>',
|
|
217
|
-
'Only convert these components; comma separated ' +
|
|
276
|
+
'Only convert these components; comma separated ' +
|
|
218
277
|
'(for example: --only=Flex,Img)')
|
|
219
278
|
.option('--internal-uikit',
|
|
220
|
-
'(For internal use only). ' +
|
|
279
|
+
'(For internal use only). ' +
|
|
221
280
|
'Excludes particular components from the conversion')
|
|
222
281
|
.action(async (src, dest, options) => {
|
|
223
|
-
console.log('smbls convert is deprecated. ' +
|
|
224
|
-
'Please use the Kalduna build script instead.')
|
|
225
|
-
return 1
|
|
226
|
-
|
|
227
282
|
if (!convert) {
|
|
228
283
|
throw new Error(
|
|
229
284
|
'convert() from `kalduna` is not defined. Try to install ' +
|
|
@@ -320,18 +375,53 @@ program
|
|
|
320
375
|
return 1
|
|
321
376
|
}
|
|
322
377
|
|
|
323
|
-
const
|
|
378
|
+
const sourceDirNames = (await fs.promises.readdir(srcPath))
|
|
324
379
|
.filter(file => !IGNORED_FILES.includes(file))
|
|
325
380
|
|
|
326
|
-
|
|
327
|
-
const indexFilePath = path.join(srcPath, file, 'index.js')
|
|
381
|
+
const dirs = []
|
|
328
382
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
383
|
+
for (const dir of sourceDirNames) {
|
|
384
|
+
// Ignored directories
|
|
385
|
+
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
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const dirPath = path.join(srcPath, dir)
|
|
393
|
+
const indexFilePath = path.join(dirPath, 'index.js')
|
|
394
|
+
const pjFilePath = path.join(dirPath, 'package.json')
|
|
395
|
+
|
|
396
|
+
const globusaStruct = await convertFile(
|
|
397
|
+
indexFilePath, // src
|
|
398
|
+
path.join(tmpDirPath, dir), // tmp
|
|
399
|
+
path.join(destDirPath, dir, 'index.js'), // dst
|
|
333
400
|
desiredFormat,
|
|
334
401
|
options
|
|
335
402
|
)
|
|
403
|
+
|
|
404
|
+
if (fs.existsSync(pjFilePath)) {
|
|
405
|
+
generatePackageJsonFile(
|
|
406
|
+
pjFilePath, // src
|
|
407
|
+
path.join(destDirPath, dir, 'package.json'), // dst
|
|
408
|
+
globusaStruct,
|
|
409
|
+
desiredFormat,
|
|
410
|
+
options
|
|
411
|
+
)
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
dirs.push(dir)
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// Generate top index.js file
|
|
418
|
+
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
|
|
422
|
+
|
|
423
|
+
const fh = await fs.promises.open(path.join(destDirPath, 'index.js'), 'w')
|
|
424
|
+
await fh.writeFile(fileContent, 'utf8')
|
|
425
|
+
await fh.close()
|
|
336
426
|
}
|
|
337
427
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/cli",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.158",
|
|
4
4
|
"description": "Fetch your Symbols configuration",
|
|
5
5
|
"main": "bin/fetch.js",
|
|
6
6
|
"author": "Symbols",
|
|
@@ -19,13 +19,11 @@
|
|
|
19
19
|
"@symbo.ls/socket": "latest",
|
|
20
20
|
"chalk": "^5.0.0",
|
|
21
21
|
"commander": "latest",
|
|
22
|
+
"esbuild": "^0.19.2",
|
|
22
23
|
"globusa": "latest",
|
|
23
|
-
"jsdom": "^
|
|
24
|
+
"jsdom": "^22.1.0",
|
|
24
25
|
"node-fetch": "^3.1.0",
|
|
25
26
|
"v8-compile-cache": "^2.3.0"
|
|
26
27
|
},
|
|
27
|
-
"gitHead": "
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"webpack": "^5.88.2"
|
|
30
|
-
}
|
|
28
|
+
"gitHead": "cbed9bf1f1a15c02489444ffa264acbaf2e8d918"
|
|
31
29
|
}
|