@symbo.ls/cli 2.11.160 → 2.11.164
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 +160 -22
- package/bin/fetch.js +87 -82
- package/bin/index.js +2 -0
- package/bin/install.js +75 -0
- package/bin/link-packages.js +91 -0
- package/bin/require.js +1 -1
- package/bin/sync.js +71 -17
- package/package.json +2 -2
- package/bin/link-all.js +0 -10
package/bin/convert.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import fs from 'fs'
|
|
4
|
+
import chalk from 'chalk'
|
|
5
|
+
import path from 'path'
|
|
3
6
|
import { program } from './program.js'
|
|
4
7
|
import { convert } from 'kalduna'
|
|
5
8
|
import { parse } from 'globusa'
|
|
6
|
-
import fs from 'fs'
|
|
7
|
-
import path from 'path'
|
|
8
9
|
|
|
9
10
|
import * as esbuild from 'esbuild'
|
|
10
11
|
|
|
@@ -114,9 +115,9 @@ function isDirectory (dir) {
|
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
// Essentially does 'mkdir -P'
|
|
117
|
-
|
|
118
|
+
function mkdirp (dir) {
|
|
118
119
|
try {
|
|
119
|
-
return
|
|
120
|
+
return fs.mkdirSync(dir, { recursive: true })
|
|
120
121
|
} catch (err) {
|
|
121
122
|
if (err.code !== 'EEXIST') {
|
|
122
123
|
throw err
|
|
@@ -126,7 +127,7 @@ async function mkdirp (dir) {
|
|
|
126
127
|
}
|
|
127
128
|
|
|
128
129
|
// Returns a string
|
|
129
|
-
function convertDomqlModule (domqlModule, globusaStruct, desiredFormat, options) {
|
|
130
|
+
export function convertDomqlModule (domqlModule, globusaStruct, desiredFormat, options = {}) {
|
|
130
131
|
let convertedStr = ''
|
|
131
132
|
const whitelist = (options.only ? options.only.split(',') : null)
|
|
132
133
|
|
|
@@ -134,7 +135,7 @@ function convertDomqlModule (domqlModule, globusaStruct, desiredFormat, options)
|
|
|
134
135
|
const exports = Object.keys(domqlModule)
|
|
135
136
|
.filter(exportName => {
|
|
136
137
|
if (!whitelist) return true
|
|
137
|
-
if (whitelist.includes(exportName)) {
|
|
138
|
+
if (!whitelist.includes(exportName)) {
|
|
138
139
|
console.log(`Skipping ${exportName} component due to whitelist exclusion`)
|
|
139
140
|
return false
|
|
140
141
|
}
|
|
@@ -257,7 +258,7 @@ async function convertFile (srcPath, tmpDirPath, destPath,
|
|
|
257
258
|
)
|
|
258
259
|
|
|
259
260
|
// Create dest dir
|
|
260
|
-
|
|
261
|
+
mkdirp(path.dirname(destPath))
|
|
261
262
|
|
|
262
263
|
// Write file
|
|
263
264
|
if (convertedModuleStr && convertedModuleStr.length > 0) {
|
|
@@ -269,6 +270,124 @@ async function convertFile (srcPath, tmpDirPath, destPath,
|
|
|
269
270
|
return globusaStruct
|
|
270
271
|
}
|
|
271
272
|
|
|
273
|
+
// Aborts copying if destination exists
|
|
274
|
+
function recursiveCopy (src, dst, exclude) {
|
|
275
|
+
if (exclude && exclude.includes(src)) { return }
|
|
276
|
+
|
|
277
|
+
if (!fs.existsSync(src)) {
|
|
278
|
+
console.error(`Error (recursiveCopy): Source file '${src}' does not exist.`)
|
|
279
|
+
return
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (fs.existsSync(dst)) {
|
|
283
|
+
console.error(`Error (recursiveCopy): Destination file '${dst}' exists.`)
|
|
284
|
+
return
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (!isDirectory(src)) {
|
|
288
|
+
fs.copyFileSync(src, dst)
|
|
289
|
+
return
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
mkdirp(dst)
|
|
293
|
+
const files = fs.readdirSync(src)
|
|
294
|
+
for (const f of files) {
|
|
295
|
+
if (exclude && exclude.includes(f)) { continue }
|
|
296
|
+
|
|
297
|
+
recursiveCopy(path.join(src, f), path.join(dst, f), exclude)
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function mergeDirectories (mrg, dst, { globusaMerge, exclude }) {
|
|
302
|
+
// Source doesn't exist, skip
|
|
303
|
+
if (!fs.existsSync(mrg)) {
|
|
304
|
+
console.error(`Error: Source merge directory '${mrg}' does not exist.`)
|
|
305
|
+
return
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Direct copy, no merging needed
|
|
309
|
+
if (!fs.existsSync(dst)) {
|
|
310
|
+
recursiveCopy(mrg, dst, exclude)
|
|
311
|
+
return
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const isMrgDir = isDirectory(mrg)
|
|
315
|
+
const isDstDir = isDirectory(dst)
|
|
316
|
+
|
|
317
|
+
if (!isMrgDir && !isDstDir) {
|
|
318
|
+
return
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (!isMrgDir && isDstDir) {
|
|
322
|
+
console.error(`mergeDirectories('${mrg}', '${dst}') skipped. ` +
|
|
323
|
+
'Merge source (mrg) is a regular file and the ' +
|
|
324
|
+
'destination (dst) is a directory.')
|
|
325
|
+
return
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (isMrgDir && !isDstDir) {
|
|
329
|
+
console.error(`mergeDirectories('${mrg}', '${dst}') skipped. ` +
|
|
330
|
+
'Merge source (mrg) is a directory and the ' +
|
|
331
|
+
'destination (dst) is a regular file.')
|
|
332
|
+
return
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const mrgFiles = fs.readdirSync(mrg).filter(f => !exclude.includes(f))
|
|
336
|
+
const dstFiles = fs.readdirSync(dst)
|
|
337
|
+
|
|
338
|
+
// Make a map of dstFiles for quick access
|
|
339
|
+
const dstFilesMap = {}
|
|
340
|
+
for (const f of dstFiles) {
|
|
341
|
+
dstFilesMap[f] = true
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Do a direct directory merge (without globusa)
|
|
345
|
+
const directMrgFiles = mrgFiles.filter(f => !globusaMerge.includes(f))
|
|
346
|
+
for (const f of directMrgFiles) {
|
|
347
|
+
if (!dstFilesMap[f]) {
|
|
348
|
+
recursiveCopy(path.resolve(mrg, f), path.resolve(dst, f), exclude)
|
|
349
|
+
} else {
|
|
350
|
+
mergeDirectories(path.resolve(mrg, f), path.resolve(dst, f), {
|
|
351
|
+
globusaMerge, exclude
|
|
352
|
+
})
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Do a smart file merge (with globusa)
|
|
357
|
+
const globusaMrgFiles = mrgFiles.filter(f => globusaMerge.includes(f))
|
|
358
|
+
for (const f of globusaMrgFiles) {
|
|
359
|
+
if (!dstFilesMap[f]) {
|
|
360
|
+
// Nothing to merge. Do a direct copy
|
|
361
|
+
const p = path.resolve(mrg, f)
|
|
362
|
+
if (isDirectory(p)) {
|
|
363
|
+
console.error('Error: Globusa merge can only be done on files, ' +
|
|
364
|
+
`but '${p}' is a directory`)
|
|
365
|
+
} else {
|
|
366
|
+
fs.copyFileSync(p, path.resolve(dst, f))
|
|
367
|
+
}
|
|
368
|
+
} else {
|
|
369
|
+
// Concatenate the files
|
|
370
|
+
const mrgTxt = fs.readFileSync(path.resolve(mrg, f), { encoding: 'utf8' })
|
|
371
|
+
const dstTxt = fs.readFileSync(path.resolve(dst, f), { encoding: 'utf8' })
|
|
372
|
+
const outTxt = mrgTxt + '\n' + dstTxt
|
|
373
|
+
|
|
374
|
+
// TODO: Dedup the imports with globusa here
|
|
375
|
+
|
|
376
|
+
fs.writeFileSync(path.resolve(dst, f), outTxt, { encoding: 'utf8' })
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export function convertFromCli (data, opts) {
|
|
382
|
+
const { framework, verbose, verboseCode } = opts
|
|
383
|
+
console.log(chalk.dim('\n----------------\n'))
|
|
384
|
+
console.log('Converting components to', chalk.bold(framework))
|
|
385
|
+
const convertedStrings = convertDomqlModule(data, null, framework)
|
|
386
|
+
if (verboseCode) console.log(convertedStrings)
|
|
387
|
+
console.log(chalk.bold.green('\nSuccessfully converted'))
|
|
388
|
+
return verbose
|
|
389
|
+
}
|
|
390
|
+
|
|
272
391
|
program
|
|
273
392
|
.command('convert')
|
|
274
393
|
.description('Convert and copy all DomQL components under a directory')
|
|
@@ -286,6 +405,8 @@ program
|
|
|
286
405
|
.option('-o, --only <components>',
|
|
287
406
|
'Only convert these components; comma separated ' +
|
|
288
407
|
'(for example: --only=Flex,Img)')
|
|
408
|
+
.option('-m, --merge <dir>',
|
|
409
|
+
'After converting an entire directory, perform a recursive merge that takes files from this directory and puts them in the dest directory. It also concatenates index.js files')
|
|
289
410
|
.option('--internal-uikit',
|
|
290
411
|
'(For internal use only). ' +
|
|
291
412
|
'Excludes particular components from the conversion')
|
|
@@ -315,14 +436,14 @@ program
|
|
|
315
436
|
// Resolve source file/dir
|
|
316
437
|
const srcPath = path.resolve(src || './src')
|
|
317
438
|
if (!fs.existsSync(srcPath)) {
|
|
318
|
-
console.
|
|
319
|
-
|
|
439
|
+
console.error(`Source directory/file ('${srcPath}') does not exist`)
|
|
440
|
+
process.exit(1)
|
|
320
441
|
}
|
|
321
442
|
|
|
322
443
|
// Resolve & create tmp dir
|
|
323
444
|
const tmpDirPath = options.tmpDir ??
|
|
324
445
|
path.resolve(path.dirname(srcPath), TMP_DIR_NAME)
|
|
325
|
-
|
|
446
|
+
mkdirp(tmpDirPath)
|
|
326
447
|
|
|
327
448
|
// Put a package.json file so that when we import() the modules from the
|
|
328
449
|
// directory, node doesn't recognize them as ES modules (in case the parent
|
|
@@ -351,7 +472,7 @@ program
|
|
|
351
472
|
} else {
|
|
352
473
|
// dest not given. Use default (desiredFormat as directory).
|
|
353
474
|
const destDir = path.resolve(desiredFormat)
|
|
354
|
-
|
|
475
|
+
mkdirp(destDir)
|
|
355
476
|
destFilePath = path.join(destDir, path.basename(srcPath))
|
|
356
477
|
}
|
|
357
478
|
|
|
@@ -363,7 +484,7 @@ program
|
|
|
363
484
|
options
|
|
364
485
|
)
|
|
365
486
|
|
|
366
|
-
|
|
487
|
+
process.exit(0)
|
|
367
488
|
}
|
|
368
489
|
|
|
369
490
|
// We're converting multiple files (in a directory).
|
|
@@ -373,7 +494,7 @@ program
|
|
|
373
494
|
if (!fs.existsSync(dest)) {
|
|
374
495
|
// dest doesn't exist. Create it.
|
|
375
496
|
destDirPath = path.resolve(dest)
|
|
376
|
-
|
|
497
|
+
mkdirp(destDirPath)
|
|
377
498
|
} else if (isDirectory(dest)) {
|
|
378
499
|
// dest exists and is a directory.
|
|
379
500
|
destDirPath = path.resolve(dest)
|
|
@@ -382,15 +503,26 @@ program
|
|
|
382
503
|
console.error(
|
|
383
504
|
`The destination ('${path.resolve(dest)}') must be a directory when ` +
|
|
384
505
|
`the source ('${srcPath}') is a directory`)
|
|
385
|
-
|
|
506
|
+
process.exit(1)
|
|
386
507
|
}
|
|
387
508
|
|
|
388
|
-
|
|
509
|
+
// Resolve merge dir
|
|
510
|
+
let mergeDirPath = null
|
|
511
|
+
if (options.merge && options.internalUikit) {
|
|
512
|
+
mergeDirPath = path.resolve(options.merge)
|
|
513
|
+
if (!fs.existsSync(mergeDirPath)) {
|
|
514
|
+
console.error(`Merge directory '${mergeDirPath}' does not exist`)
|
|
515
|
+
process.exit(1)
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
const dontConvert = ['index.js', 'package.json', 'node_modules', 'dist']
|
|
389
520
|
const sourceDirNames = (await fs.promises.readdir(srcPath))
|
|
390
|
-
.filter(dir => !
|
|
521
|
+
.filter(dir => !dontConvert.includes(dir))
|
|
391
522
|
|
|
392
523
|
const dirs = []
|
|
393
524
|
|
|
525
|
+
// Core convert loop
|
|
394
526
|
for (const dir of sourceDirNames) {
|
|
395
527
|
// Ignored directories
|
|
396
528
|
if (options.internalUikit) {
|
|
@@ -415,7 +547,7 @@ program
|
|
|
415
547
|
options
|
|
416
548
|
)
|
|
417
549
|
|
|
418
|
-
if (fs.existsSync(pjFilePath)) {
|
|
550
|
+
if (options.internalUikit && fs.existsSync(pjFilePath)) {
|
|
419
551
|
generatePackageJsonFile(
|
|
420
552
|
pjFilePath, // src
|
|
421
553
|
path.join(destDirPath, dir, 'package.json'), // dst
|
|
@@ -430,13 +562,19 @@ program
|
|
|
430
562
|
|
|
431
563
|
// Generate top index.js file
|
|
432
564
|
if (dirs.length > 0) {
|
|
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
565
|
const fileContent = dirs.map(d => `export * from './${d}'`).join('\n')
|
|
437
|
-
|
|
438
566
|
const fh = await fs.promises.open(path.join(destDirPath, 'index.js'), 'w')
|
|
439
567
|
await fh.writeFile(fileContent, 'utf8')
|
|
440
568
|
await fh.close()
|
|
441
569
|
}
|
|
570
|
+
|
|
571
|
+
if (mergeDirPath) {
|
|
572
|
+
console.log(`Merging '${mergeDirPath}' and ${destDirPath}...`)
|
|
573
|
+
mergeDirectories(mergeDirPath, destDirPath, {
|
|
574
|
+
globusaMerge: ['index.js', 'index.jsx'],
|
|
575
|
+
exclude: ['dist', 'node_modules']
|
|
576
|
+
})
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
process.exit(0)
|
|
442
580
|
})
|
package/bin/fetch.js
CHANGED
|
@@ -3,112 +3,117 @@
|
|
|
3
3
|
import fs from 'fs'
|
|
4
4
|
import chalk from 'chalk'
|
|
5
5
|
import { loadModule } from './require.js'
|
|
6
|
-
import { exec } from 'child_process'
|
|
7
6
|
import { program } from './program.js'
|
|
7
|
+
import * as fetch from '@symbo.ls/fetch'
|
|
8
8
|
|
|
9
|
-
import
|
|
10
|
-
|
|
9
|
+
import * as utils from '@domql/utils'
|
|
10
|
+
import { convertFromCli } from './convert.js'
|
|
11
|
+
const { isObjectLike } = utils.default
|
|
12
|
+
|
|
13
|
+
const { fetchRemote } = fetch.default
|
|
11
14
|
|
|
12
|
-
const PACKAGE_PATH = process.cwd() + '/package.json'
|
|
13
15
|
const RC_PATH = process.cwd() + '/symbols.json'
|
|
14
16
|
const LOCAL_CONFIG_PATH = process.cwd() + '/node_modules/@symbo.ls/init/dynamic.json'
|
|
15
17
|
const DEFAULT_REMOTE_REPOSITORY = 'https://github.com/symbo-ls/default-config/'
|
|
16
|
-
const DEFAULT_REMOTE_CONFIG_PATH = 'https://api.symbols.
|
|
18
|
+
const DEFAULT_REMOTE_CONFIG_PATH = 'https://api.symbols.app/' // eslint-disable-line
|
|
17
19
|
|
|
18
|
-
const
|
|
20
|
+
const API_URL_LOCAL = 'http://localhost:13335/'
|
|
21
|
+
const API_URL = 'https://api.symbols.app/'
|
|
19
22
|
|
|
20
|
-
const pkg = loadModule(PACKAGE_PATH)
|
|
21
23
|
const rcFile = loadModule(RC_PATH) // eslint-disable-line
|
|
22
24
|
const localConfig = loadModule(LOCAL_CONFIG_PATH) // eslint-disable-line
|
|
23
25
|
|
|
26
|
+
const debugMsg = chalk.dim('Use --verbose to debug the error or open the issue at https://github.com/symbo-ls/smbls')
|
|
27
|
+
|
|
24
28
|
let rc = {}
|
|
25
29
|
try {
|
|
26
30
|
rc = loadModule(RC_PATH) // eslint-disable-line
|
|
27
31
|
} catch (e) { console.error('Please include symbols.json to your root of respository') }
|
|
28
32
|
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
export const fetchFromCli = async (opts) => {
|
|
34
|
+
const { dev, verbose, prettify, convert: convertOpt } = opts
|
|
31
35
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
.description('Install Symbols')
|
|
35
|
-
.option('--framework', 'Which Symbols to install (domql, react)')
|
|
36
|
-
.action(async (framework) => {
|
|
37
|
-
if (!rcFile || !localConfig) {
|
|
38
|
-
console.error('symbols.json not found in the root of the repository')
|
|
39
|
-
return
|
|
40
|
-
}
|
|
36
|
+
await rc.then(async data => {
|
|
37
|
+
const { key, framework } = data
|
|
41
38
|
|
|
42
|
-
|
|
43
|
-
const packageName = 'smbls'
|
|
44
|
-
console.log('Adding', chalk.green.bold(packageName))
|
|
39
|
+
const endpoint = dev ? API_URL_LOCAL : API_URL
|
|
45
40
|
|
|
46
|
-
|
|
47
|
-
exec('yarn add domql@^1.15.26 --force', (error, stdout, stderr) => {
|
|
48
|
-
if (error) {
|
|
49
|
-
console.log(`error: ${error.message}`)
|
|
50
|
-
return
|
|
51
|
-
}
|
|
52
|
-
if (stderr) {
|
|
53
|
-
console.log(`stderr: ${stderr}`)
|
|
54
|
-
// return;
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
}
|
|
41
|
+
console.log('\nFetching from:', chalk.bold(endpoint), '\n')
|
|
58
42
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
43
|
+
const body = await fetchRemote(key, {
|
|
44
|
+
endpoint,
|
|
45
|
+
onError: (e) => {
|
|
46
|
+
console.log(chalk.red('Failed to fetch:'), key)
|
|
47
|
+
if (verbose) console.error(e)
|
|
48
|
+
else console.log(debugMsg)
|
|
63
49
|
}
|
|
64
|
-
if (stderr) {
|
|
65
|
-
console.log(`stderr: ${stderr}`)
|
|
66
|
-
// return;
|
|
67
|
-
}
|
|
68
|
-
console.log('')
|
|
69
|
-
console.log(`stdout: ${stdout}`)
|
|
70
|
-
console.log('\n')
|
|
71
|
-
console.log(chalk.green.bold(packageName), 'successfuly added!')
|
|
72
|
-
console.log('')
|
|
73
|
-
console.log(chalk.dim('Now you can import components like:'), 'import { Button } from \'smbls')
|
|
74
50
|
})
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (key) console.log(chalk.green(key))
|
|
90
|
-
else console.log(chalk.dim('- Default config from:'), chalk.dim.underline(DEFAULT_REMOTE_REPOSITORY))
|
|
91
|
-
console.log('')
|
|
92
|
-
|
|
93
|
-
console.log(chalk.dim('- dynamic.json updated:'), chalk.dim.underline(LOCAL_CONFIG_PATH))
|
|
94
|
-
console.log('')
|
|
95
|
-
|
|
96
|
-
for (const t in config) {
|
|
97
|
-
const type = config[t]
|
|
98
|
-
console.log(chalk.bold(t))
|
|
99
|
-
const arr = []
|
|
100
|
-
for (const v in type) arr.push(v)
|
|
101
|
-
console.log(' ', chalk.dim(arr.join(', ')))
|
|
51
|
+
if (!body) return
|
|
52
|
+
|
|
53
|
+
const { version, ...config } = body
|
|
54
|
+
|
|
55
|
+
if (verbose) {
|
|
56
|
+
if (key) {
|
|
57
|
+
console.log(chalk.bold('Symbols'), 'data fetched for', chalk.green(body.name))
|
|
58
|
+
} else {
|
|
59
|
+
console.log(
|
|
60
|
+
chalk.bold('Symbols'),
|
|
61
|
+
'config fetched from',
|
|
62
|
+
chalk.bold('default-config from:'),
|
|
63
|
+
chalk.dim.underline(DEFAULT_REMOTE_REPOSITORY)
|
|
64
|
+
)
|
|
102
65
|
}
|
|
66
|
+
console.log()
|
|
67
|
+
}
|
|
103
68
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
69
|
+
for (const t in config) {
|
|
70
|
+
const type = config[t]
|
|
71
|
+
const arr = []
|
|
72
|
+
if (isObjectLike(type)) {
|
|
73
|
+
for (const v in type) arr.push(v)
|
|
74
|
+
if (arr.length) {
|
|
75
|
+
console.log(chalk.dim(t + ':'))
|
|
76
|
+
console.log(chalk.bold(arr.join(', ')))
|
|
109
77
|
} else {
|
|
110
|
-
console.log('
|
|
78
|
+
console.log(chalk.dim(t + ':'), chalk.dim('- empty -'))
|
|
111
79
|
}
|
|
112
|
-
})
|
|
113
|
-
}
|
|
80
|
+
} else console.log(chalk.dim(t + ':'), chalk.bold(type))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (body.designsystem) {
|
|
84
|
+
body.designSystem = body.designsystem
|
|
85
|
+
delete body.designsystem
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const bodyString = JSON.stringify(body, null, prettify ?? 2)
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
await fs.writeFileSync(LOCAL_CONFIG_PATH, bodyString)
|
|
92
|
+
|
|
93
|
+
if (verbose) {
|
|
94
|
+
console.log(chalk.dim('\ndynamic.json has been updated:'))
|
|
95
|
+
console.log(chalk.dim.underline(LOCAL_CONFIG_PATH))
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
console.log(chalk.bold.green('\nSuccessfully wrote file'))
|
|
99
|
+
} catch (e) {
|
|
100
|
+
console.log(chalk.bold.red('\nError writing file'))
|
|
101
|
+
if (verbose) console.error(e)
|
|
102
|
+
else console.log(debugMsg)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
console.log(convertOpt)
|
|
106
|
+
if (body.components && convertOpt && framework) {
|
|
107
|
+
convertFromCli(body.components, { ...opts, framework })
|
|
108
|
+
}
|
|
114
109
|
})
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
program
|
|
113
|
+
.command('fetch')
|
|
114
|
+
.description('Fetch symbols')
|
|
115
|
+
.option('-d, --dev', 'Running from local server')
|
|
116
|
+
.option('-v, --verbose', 'Verbose errors and warnings')
|
|
117
|
+
.option('--convert', 'Verbose errors and warnings', true)
|
|
118
|
+
.option('--verbose-code', 'Verbose errors and warnings')
|
|
119
|
+
.action(fetchFromCli)
|
package/bin/index.js
CHANGED
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
import 'v8-compile-cache'
|
|
4
4
|
|
|
5
5
|
import { program } from './program.js'
|
|
6
|
+
import './install.js'
|
|
6
7
|
import './init.js'
|
|
7
8
|
import './fetch.js'
|
|
8
9
|
import './sync.js'
|
|
9
10
|
import './clean.js'
|
|
10
11
|
import './convert.js'
|
|
11
12
|
import './create.js'
|
|
13
|
+
import './link-packages.js'
|
|
12
14
|
|
|
13
15
|
const args = process.argv
|
|
14
16
|
program.parse(args)
|
package/bin/install.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import chalk from 'chalk'
|
|
4
|
+
import { loadModule } from './require.js'
|
|
5
|
+
import { exec } from 'child_process'
|
|
6
|
+
import { program } from './program.js'
|
|
7
|
+
|
|
8
|
+
const PACKAGE_PATH = process.cwd() + '/package.json'
|
|
9
|
+
const RC_PATH = process.cwd() + '/symbols.json'
|
|
10
|
+
const LOCAL_CONFIG_PATH = process.cwd() + '/node_modules/@symbo.ls/init/dynamic.json'
|
|
11
|
+
const DEFAULT_REMOTE_CONFIG_PATH = 'https://api.symbols.app/' // eslint-disable-line
|
|
12
|
+
|
|
13
|
+
const pkg = loadModule(PACKAGE_PATH)
|
|
14
|
+
const rcFile = loadModule(RC_PATH) // eslint-disable-line
|
|
15
|
+
const localConfig = loadModule(LOCAL_CONFIG_PATH) // eslint-disable-line
|
|
16
|
+
|
|
17
|
+
let rc = {}
|
|
18
|
+
try {
|
|
19
|
+
rc = loadModule(RC_PATH) // eslint-disable-line
|
|
20
|
+
} catch (e) { console.error('Please include symbols.json to your root of respository') }
|
|
21
|
+
|
|
22
|
+
const makeCommand = (packageManager, packageName) => {
|
|
23
|
+
return packageManager === 'yarn'
|
|
24
|
+
? `yarn add ${packageName}`
|
|
25
|
+
: packageManager === 'pnpm'
|
|
26
|
+
? `pnpm add ${packageName}`
|
|
27
|
+
: `npm i ${packageName} --save`
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const installFromCli = async (options) => {
|
|
31
|
+
if (!rcFile || !localConfig) {
|
|
32
|
+
console.error('symbols.json not found in the root of the repository')
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const framework = rcFile.framework || options.framework
|
|
37
|
+
const packageManager = rcFile.packageManager || options.packageManager
|
|
38
|
+
|
|
39
|
+
// const packageName = `@symbo.ls/${mode || 'uikit'}`
|
|
40
|
+
const packageName = framework === 'react' ? '@symbo.ls/react' : 'smbls'
|
|
41
|
+
console.log('Adding', chalk.green.bold(packageName))
|
|
42
|
+
|
|
43
|
+
const command = makeCommand(packageManager, packageName)
|
|
44
|
+
exec(command, (error, stdout, stderr) => {
|
|
45
|
+
if (error) {
|
|
46
|
+
console.log(`error: ${error.message}`)
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
if (stderr) {
|
|
50
|
+
console.log(`stderr: ${stderr}`)
|
|
51
|
+
// return;
|
|
52
|
+
}
|
|
53
|
+
console.log('')
|
|
54
|
+
console.log(`stdout: ${stdout}`)
|
|
55
|
+
console.log('\n')
|
|
56
|
+
console.log(chalk.green.bold(packageName), 'successfuly added!')
|
|
57
|
+
console.log('')
|
|
58
|
+
console.log(
|
|
59
|
+
chalk.dim('Now you can import components like:'),
|
|
60
|
+
`import { Button } from '${packageName}'`
|
|
61
|
+
)
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
program
|
|
66
|
+
.version(pkg.version ?? 'unknown')
|
|
67
|
+
|
|
68
|
+
program
|
|
69
|
+
.command('install')
|
|
70
|
+
.description('Install Symbols')
|
|
71
|
+
.option('-d, --dev', 'Running from local server')
|
|
72
|
+
.option('-v, --verbose', 'Verbose errors and warnings')
|
|
73
|
+
.option('-f, --fetch', 'Verbose errors and warnings', true)
|
|
74
|
+
.option('--framework', 'Which Symbols to install (domql, react)')
|
|
75
|
+
.action(installFromCli)
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { execSync } from 'child_process'
|
|
4
|
+
import { program } from './program.js'
|
|
5
|
+
|
|
6
|
+
const packagesToLink = [
|
|
7
|
+
'attrs-in-props',
|
|
8
|
+
'@symbo.ls/cli',
|
|
9
|
+
'@symbo.ls/convert',
|
|
10
|
+
'@symbo.ls/create',
|
|
11
|
+
'css-in-props',
|
|
12
|
+
'@symbo.ls/default-config',
|
|
13
|
+
'@symbo.ls/fetch',
|
|
14
|
+
'@symbo.ls/emotion',
|
|
15
|
+
'@symbo.ls/init',
|
|
16
|
+
'@symbo.ls/scratch',
|
|
17
|
+
'smbls',
|
|
18
|
+
'@symbo.ls/socket-ui',
|
|
19
|
+
'@symbo.ls/utils',
|
|
20
|
+
'@symbo.ls/socket',
|
|
21
|
+
'@symbo.ls/uikit',
|
|
22
|
+
'@symbo.ls/react',
|
|
23
|
+
'@symbo.ls/atoms',
|
|
24
|
+
'@symbo.ls/board',
|
|
25
|
+
'@symbo.ls/avatar',
|
|
26
|
+
'@symbo.ls/box',
|
|
27
|
+
'@symbo.ls/button',
|
|
28
|
+
'@symbo.ls/card',
|
|
29
|
+
'@symbo.ls/chat',
|
|
30
|
+
'@symbo.ls/datepicker',
|
|
31
|
+
'@symbo.ls/checkbox',
|
|
32
|
+
'@symbo.ls/dialog',
|
|
33
|
+
'@symbo.ls/dropdown',
|
|
34
|
+
'@symbo.ls/editorjs',
|
|
35
|
+
'@symbo.ls/form',
|
|
36
|
+
'@symbo.ls/field',
|
|
37
|
+
'@symbo.ls/google-maps',
|
|
38
|
+
'@symbo.ls/helmet',
|
|
39
|
+
'@symbo.ls/icon',
|
|
40
|
+
'@symbo.ls/indicator',
|
|
41
|
+
'@symbo.ls/input',
|
|
42
|
+
'@symbo.ls/link',
|
|
43
|
+
'@symbo.ls/list',
|
|
44
|
+
'@symbo.ls/label',
|
|
45
|
+
'@symbo.ls/markdown',
|
|
46
|
+
'@symbo.ls/modal',
|
|
47
|
+
'@symbo.ls/notification',
|
|
48
|
+
'@symbo.ls/progress',
|
|
49
|
+
'@symbo.ls/pills',
|
|
50
|
+
'@symbo.ls/range',
|
|
51
|
+
'@symbo.ls/select',
|
|
52
|
+
'@symbo.ls/sidebar',
|
|
53
|
+
'@symbo.ls/slider',
|
|
54
|
+
'@symbo.ls/steps',
|
|
55
|
+
'@symbo.ls/tab',
|
|
56
|
+
'@symbo.ls/table',
|
|
57
|
+
'@symbo.ls/threejs',
|
|
58
|
+
'@symbo.ls/timepicker',
|
|
59
|
+
'@symbo.ls/titleparagraph',
|
|
60
|
+
'@symbo.ls/tooltip',
|
|
61
|
+
'@symbo.ls/upload',
|
|
62
|
+
'@symbo.ls/unitvalue',
|
|
63
|
+
'@symbo.ls/video',
|
|
64
|
+
'@symbo.ls/default-icons',
|
|
65
|
+
'@symbo.ls/feather-icons',
|
|
66
|
+
'@symbo.ls/material-icons',
|
|
67
|
+
'@symbo.ls/fluent-icons',
|
|
68
|
+
'@symbo.ls/react-atoms',
|
|
69
|
+
'@symbo.ls/react-box',
|
|
70
|
+
'@symbo.ls/react-button',
|
|
71
|
+
'@symbo.ls/react-icon',
|
|
72
|
+
'@symbo.ls/react-provider',
|
|
73
|
+
'@symbo.ls/react-tooltip'
|
|
74
|
+
// Add all your package names here,
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
program
|
|
78
|
+
.command('link-packages')
|
|
79
|
+
.description('Run "yarn link" on specified packages')
|
|
80
|
+
.action(() => {
|
|
81
|
+
try {
|
|
82
|
+
for (const packageName of packagesToLink) {
|
|
83
|
+
console.log(`Linking ${packageName}...`)
|
|
84
|
+
execSync(`yarn link ${packageName}`, { stdio: 'inherit' })
|
|
85
|
+
}
|
|
86
|
+
console.log('All packages linked successfully.')
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error('Error linking packages:', error.message)
|
|
89
|
+
process.exit(1)
|
|
90
|
+
}
|
|
91
|
+
})
|
package/bin/require.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { createRequire } from 'module'
|
|
4
3
|
import fs from 'fs'
|
|
4
|
+
import { createRequire } from 'module'
|
|
5
5
|
|
|
6
6
|
class ImportError extends Error {} /* Bring in the ability to create the 'require' method */ // eslint-disable-line
|
|
7
7
|
const require = createRequire(import.meta.url) // construct the require method
|
package/bin/sync.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import * as socketClient from '@symbo.ls/socket/client.js'
|
|
3
|
+
import chalk from 'chalk'
|
|
5
4
|
import { program } from './program.js'
|
|
6
5
|
import { loadModule } from './require.js'
|
|
6
|
+
import { updateDynamycFile } from '@symbo.ls/socket'
|
|
7
|
+
|
|
8
|
+
import * as socketClient from '@symbo.ls/socket/client.js'
|
|
9
|
+
import { fetchFromCli } from './fetch.js'
|
|
10
|
+
import { convertFromCli } from './convert.js'
|
|
11
|
+
|
|
12
|
+
const SOCKET_API_URL_LOCAL = 'http://localhost:13336/'
|
|
13
|
+
const SOCKET_API_URL = 'https://socket.symbols.app/'
|
|
14
|
+
|
|
15
|
+
const debugMsg = chalk.dim('Use --verbose to debug the error or open the issue at https://github.com/symbo-ls/smbls')
|
|
7
16
|
|
|
8
17
|
const RC_PATH = process.cwd() + '/symbols.json'
|
|
9
18
|
let rc = {}
|
|
@@ -14,21 +23,53 @@ try {
|
|
|
14
23
|
program
|
|
15
24
|
.command('sync')
|
|
16
25
|
.description('Sync with Symbols')
|
|
17
|
-
.option('-
|
|
18
|
-
.option('--
|
|
19
|
-
.
|
|
26
|
+
.option('-d, --dev', 'Running from local server')
|
|
27
|
+
.option('-v, --verbose', 'Verbose errors and warnings')
|
|
28
|
+
.option('-k, --key', 'Bypass the symbols.json key, overriding the key manually')
|
|
29
|
+
.option('-f, --fetch', 'Verbose errors and warnings', true)
|
|
30
|
+
.option('--convert', 'Verbose errors and warnings', true)
|
|
31
|
+
.option('--verbose-code', 'Verbose errors and warnings')
|
|
32
|
+
.action(async (opts) => {
|
|
33
|
+
const { dev, verbose, fetch: fetchOpt, convert: convertOpt } = opts
|
|
34
|
+
|
|
35
|
+
if (fetchOpt) {
|
|
36
|
+
await fetchFromCli(opts)
|
|
37
|
+
console.log(chalk.dim('\n----------------\n'))
|
|
38
|
+
}
|
|
39
|
+
|
|
20
40
|
if (!rc) {
|
|
21
41
|
console.error('symbols.json not found in the root of the repository')
|
|
22
42
|
return
|
|
23
43
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
44
|
+
|
|
45
|
+
// if (rc) return false /// /////////////////////
|
|
46
|
+
|
|
47
|
+
await rc.then(symbolsrc => {
|
|
48
|
+
const options = { ...symbolsrc, ...opts }
|
|
49
|
+
const { framework } = symbolsrc
|
|
50
|
+
const key = symbolsrc.key || opts.key
|
|
51
|
+
const socketUrl = dev ? SOCKET_API_URL_LOCAL : SOCKET_API_URL
|
|
52
|
+
|
|
53
|
+
console.log('Connecting to:', chalk.bold(socketUrl))
|
|
54
|
+
console.log()
|
|
55
|
+
|
|
27
56
|
socketClient.connect(key, {
|
|
57
|
+
source: 'cli',
|
|
58
|
+
socketUrl,
|
|
28
59
|
onConnect: (id, socket) => {
|
|
29
|
-
console.log(
|
|
60
|
+
console.log('Connected to', chalk.green(key), 'from', chalk.bold('Symbols'), 'socket server')
|
|
61
|
+
console.log('Socket id:', id)
|
|
62
|
+
console.log(chalk.dim('\nListening to updates...\n'))
|
|
30
63
|
},
|
|
31
64
|
onChange: (event, data) => {
|
|
65
|
+
if (event === 'clients') {
|
|
66
|
+
console.log(
|
|
67
|
+
'Active clients:',
|
|
68
|
+
chalk.green.bold(Object.keys(data).join(', '))
|
|
69
|
+
)
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
|
|
32
73
|
data = JSON.parse(data)
|
|
33
74
|
const d = {}
|
|
34
75
|
const {
|
|
@@ -36,19 +77,32 @@ program
|
|
|
36
77
|
PROJECT_STATE,
|
|
37
78
|
PROJECT_COMPONENTS,
|
|
38
79
|
PROJECT_SNIPPETS,
|
|
39
|
-
PROJECT_PAGES
|
|
80
|
+
PROJECT_PAGES,
|
|
81
|
+
DATA
|
|
40
82
|
} = data
|
|
41
83
|
if (PROJECT_DESIGN_SYSTEM) d.designSystem = PROJECT_DESIGN_SYSTEM
|
|
42
|
-
if (PROJECT_STATE) d.
|
|
43
|
-
if (PROJECT_COMPONENTS) d.
|
|
44
|
-
if (
|
|
45
|
-
if (
|
|
46
|
-
if (
|
|
84
|
+
if (PROJECT_STATE) d.state = PROJECT_STATE
|
|
85
|
+
if (PROJECT_COMPONENTS) d.components = PROJECT_COMPONENTS
|
|
86
|
+
if (DATA && DATA.components) d.components = DATA.components
|
|
87
|
+
if (PROJECT_SNIPPETS) d.snippets = PROJECT_SNIPPETS
|
|
88
|
+
if (PROJECT_PAGES) d.pages = PROJECT_PAGES
|
|
89
|
+
|
|
90
|
+
if (Object.keys(d).length) {
|
|
91
|
+
updateDynamycFile(d, { framework, ...options })
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (d.components && convertOpt && framework) {
|
|
95
|
+
convertFromCli(d.components, {
|
|
96
|
+
...options, framework
|
|
97
|
+
})
|
|
98
|
+
}
|
|
47
99
|
},
|
|
48
100
|
onError: (err, socket) => {
|
|
49
|
-
console.log(
|
|
101
|
+
console.log(chalk.bold.green('Error during connection'))
|
|
102
|
+
if (verbose) console.error(err)
|
|
103
|
+
else console.log(debugMsg)
|
|
50
104
|
},
|
|
51
|
-
...
|
|
105
|
+
...options
|
|
52
106
|
})
|
|
53
107
|
})
|
|
54
108
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/cli",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.164",
|
|
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": "943a48800e5959b8c1f15d5d8d49224565038c23"
|
|
29
29
|
}
|