@symbo.ls/cli 2.11.375 → 2.11.378
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/fetch.js +29 -18
- package/bin/fs.js +16 -22
- package/package.json +2 -2
package/bin/fetch.js
CHANGED
|
@@ -36,7 +36,7 @@ try {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export const fetchFromCli = async (opts) => {
|
|
39
|
-
const { dev, verbose, prettify, convert: convertOpt, metadata: metadataOpt, update } = opts
|
|
39
|
+
const { dev, verbose, prettify, convert: convertOpt, metadata: metadataOpt, update, force } = opts
|
|
40
40
|
await rc.then(async (data) => {
|
|
41
41
|
const { key, framework, distDir, metadata } = data
|
|
42
42
|
|
|
@@ -54,10 +54,18 @@ export const fetchFromCli = async (opts) => {
|
|
|
54
54
|
}
|
|
55
55
|
})
|
|
56
56
|
|
|
57
|
+
// console.log('ON FETCH:')
|
|
58
|
+
// console.log(body.components.Configuration)
|
|
59
|
+
|
|
57
60
|
if (!body) return
|
|
58
61
|
|
|
59
62
|
const { version, ...config } = body
|
|
60
63
|
|
|
64
|
+
if (body.designsystem) {
|
|
65
|
+
body.designSystem = body.designsystem
|
|
66
|
+
delete body.designsystem
|
|
67
|
+
}
|
|
68
|
+
|
|
61
69
|
if (verbose) {
|
|
62
70
|
if (key) {
|
|
63
71
|
console.log(
|
|
@@ -90,33 +98,34 @@ export const fetchFromCli = async (opts) => {
|
|
|
90
98
|
} else console.log(chalk.dim(t + ':'), chalk.bold(type))
|
|
91
99
|
}
|
|
92
100
|
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
delete body.designsystem
|
|
96
|
-
}
|
|
101
|
+
if (!distDir) {
|
|
102
|
+
const bodyString = JSON.stringify(body, null, prettify ?? 2)
|
|
97
103
|
|
|
98
|
-
|
|
104
|
+
try {
|
|
105
|
+
await fs.writeFileSync(LOCAL_CONFIG_PATH, bodyString)
|
|
99
106
|
|
|
100
|
-
|
|
101
|
-
|
|
107
|
+
if (verbose) {
|
|
108
|
+
console.log(chalk.dim('\ndynamic.json has been updated:'))
|
|
109
|
+
console.log(chalk.dim.underline(LOCAL_CONFIG_PATH))
|
|
110
|
+
}
|
|
102
111
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
console.log(chalk.
|
|
112
|
+
console.log(chalk.bold.green('\nSuccessfully wrote file'))
|
|
113
|
+
} catch (e) {
|
|
114
|
+
console.log(chalk.bold.red('\nError writing file'))
|
|
115
|
+
if (verbose) console.error(e)
|
|
116
|
+
else console.log(debugMsg)
|
|
106
117
|
}
|
|
107
118
|
|
|
108
|
-
console.log(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (verbose) console.error(e)
|
|
112
|
-
else console.log(debugMsg)
|
|
119
|
+
console.log()
|
|
120
|
+
console.warn('No --dist-dir option or "distDir" in symbols.json provided. Saving in ./node_modules/@symbo.ls/init/dynamic.json.')
|
|
121
|
+
return {}
|
|
113
122
|
}
|
|
114
123
|
|
|
115
124
|
if (body.components && convertOpt && framework) {
|
|
116
125
|
convertFromCli(body.components, { ...opts, framework })
|
|
117
126
|
}
|
|
118
127
|
|
|
119
|
-
if (update) {
|
|
128
|
+
if (update || force) {
|
|
120
129
|
createFs(body, distDir, { update: true, metadata })
|
|
121
130
|
} else {
|
|
122
131
|
createFs(body, distDir, { metadata })
|
|
@@ -131,8 +140,10 @@ program
|
|
|
131
140
|
.option('-v, --verbose', 'Verbose errors and warnings')
|
|
132
141
|
.option('--convert', 'Verbose errors and warnings', true)
|
|
133
142
|
.option('--metadata', 'Include metadata', false)
|
|
134
|
-
.option('--
|
|
143
|
+
.option('--force', 'Force overriding changes from platform')
|
|
144
|
+
.option('--update', 'Overriding changes from platform')
|
|
135
145
|
.option('--verbose-code', 'Verbose errors and warnings')
|
|
146
|
+
.option('--dist-dir', 'Directory to import files to.')
|
|
136
147
|
.action(fetchFromCli)
|
|
137
148
|
|
|
138
149
|
// program
|
package/bin/fs.js
CHANGED
|
@@ -5,17 +5,13 @@ import utils from '@domql/utils'
|
|
|
5
5
|
import * as smblsUtils from '@symbo.ls/utils'
|
|
6
6
|
import inquirer from 'inquirer'
|
|
7
7
|
import { createPatch } from 'diff'
|
|
8
|
-
import { fileURLToPath } from 'url'
|
|
9
|
-
|
|
10
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
11
8
|
|
|
12
9
|
const { removeChars, toCamelCase } = smblsUtils.default
|
|
13
|
-
const { deepDestringify, objectToString, joinArrays, isString, removeValueFromArray } = utils
|
|
14
|
-
|
|
15
|
-
const LOCAL_CONFIG_PATH = __dirname + '/symbols.json'
|
|
10
|
+
const { deepDestringify, objectToString, joinArrays, isString, isObject, removeValueFromArray } = utils
|
|
16
11
|
|
|
17
12
|
let singleFileKeys = ['designSystem', 'state', 'files']
|
|
18
|
-
const
|
|
13
|
+
const directoryKeys = ['components', 'snippets', 'pages']
|
|
14
|
+
|
|
19
15
|
const defaultExports = ['pages', 'designSystem', 'state', 'files', 'schema']
|
|
20
16
|
|
|
21
17
|
export async function createFs (
|
|
@@ -41,7 +37,7 @@ export async function createFs (
|
|
|
41
37
|
await fs.promises.mkdir(targetDir, { recursive: true })
|
|
42
38
|
|
|
43
39
|
const promises = [
|
|
44
|
-
...
|
|
40
|
+
...directoryKeys.map((key) =>
|
|
45
41
|
createKeyDirectoryAndFiles(key, body, targetDir, update)
|
|
46
42
|
),
|
|
47
43
|
...singleFileKeys.map((key) => {
|
|
@@ -57,15 +53,13 @@ export async function createFs (
|
|
|
57
53
|
]
|
|
58
54
|
|
|
59
55
|
await Promise.all(promises)
|
|
60
|
-
await generateIndexjsFile(joinArrays(
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (filesExist) {
|
|
56
|
+
await generateIndexjsFile(joinArrays(directoryKeys, singleFileKeys), targetDir, 'root')
|
|
57
|
+
} else if (filesExist) {
|
|
64
58
|
const cacheDir = path.join(distDir, '.cache')
|
|
65
59
|
await fs.promises.mkdir(cacheDir, { recursive: true })
|
|
66
60
|
|
|
67
61
|
const cachePromises = [
|
|
68
|
-
...
|
|
62
|
+
...directoryKeys.map((key) =>
|
|
69
63
|
createKeyDirectoryAndFiles(key, body, cacheDir, true)
|
|
70
64
|
),
|
|
71
65
|
...singleFileKeys.map((key) => {
|
|
@@ -76,7 +70,7 @@ export async function createFs (
|
|
|
76
70
|
]
|
|
77
71
|
|
|
78
72
|
await Promise.all(cachePromises)
|
|
79
|
-
await generateIndexjsFile(joinArrays(
|
|
73
|
+
await generateIndexjsFile(joinArrays(directoryKeys, singleFileKeys), cacheDir, 'root')
|
|
80
74
|
|
|
81
75
|
const diffs = await findDiff(cacheDir, targetDir)
|
|
82
76
|
if (diffs.length > 0) {
|
|
@@ -114,7 +108,7 @@ export async function createFs (
|
|
|
114
108
|
|
|
115
109
|
const dirs = []
|
|
116
110
|
|
|
117
|
-
if (body[key] &&
|
|
111
|
+
if (body[key] && isObject(body[key])) {
|
|
118
112
|
const promises = Object.entries(body[key]).map(
|
|
119
113
|
async ([entryKey, value]) => {
|
|
120
114
|
// if pages
|
|
@@ -134,7 +128,7 @@ export async function createFs (
|
|
|
134
128
|
}
|
|
135
129
|
|
|
136
130
|
async function createOrUpdateFile (dirPath, childKey, value, update) {
|
|
137
|
-
const
|
|
131
|
+
const itemKey = childKey.includes('-') || childKey.includes('/') ? removeChars(toCamelCase(childKey)) : childKey
|
|
138
132
|
const filePath = path.join(dirPath, `${childKey.replace('/', '-')}.js`)
|
|
139
133
|
|
|
140
134
|
if (!update && fs.existsSync(filePath)) {
|
|
@@ -143,10 +137,12 @@ export async function createFs (
|
|
|
143
137
|
|
|
144
138
|
let stringifiedContent
|
|
145
139
|
if (isString(value)) {
|
|
146
|
-
stringifiedContent = `export const ${
|
|
140
|
+
stringifiedContent = `export const ${itemKey} = ${value}`
|
|
147
141
|
} else {
|
|
148
142
|
const content = deepDestringify(value)
|
|
149
|
-
|
|
143
|
+
// console.log('ON DEEPDESTR:')
|
|
144
|
+
// console.log(content.components.Configuration)
|
|
145
|
+
stringifiedContent = `export const ${itemKey} = ${objectToString(content)};`
|
|
150
146
|
}
|
|
151
147
|
|
|
152
148
|
await fs.promises.writeFile(filePath, stringifiedContent, 'utf8')
|
|
@@ -183,14 +179,12 @@ export async function createFs (
|
|
|
183
179
|
|
|
184
180
|
// fs.writeFileSync(destPath, genStr)
|
|
185
181
|
// }
|
|
186
|
-
|
|
187
|
-
await fs.writeFileSync(LOCAL_CONFIG_PATH, '{}')
|
|
188
182
|
}
|
|
189
183
|
|
|
190
184
|
async function findDiff (targetDir, distDir) {
|
|
191
185
|
const diffs = []
|
|
192
186
|
|
|
193
|
-
for (const key of
|
|
187
|
+
for (const key of directoryKeys) {
|
|
194
188
|
const targetDirPath = path.join(targetDir, key)
|
|
195
189
|
const distDirPath = path.join(distDir, key)
|
|
196
190
|
|
|
@@ -288,7 +282,7 @@ async function generateIndexjsFile (dirs, dirPath, key) {
|
|
|
288
282
|
}
|
|
289
283
|
|
|
290
284
|
async function overrideFiles (targetDir, distDir) {
|
|
291
|
-
for (const key of
|
|
285
|
+
for (const key of directoryKeys) {
|
|
292
286
|
const targetDirPath = path.join(targetDir, key)
|
|
293
287
|
const distDirPath = path.join(distDir, key)
|
|
294
288
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/cli",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.378",
|
|
4
4
|
"description": "Fetch your Symbols configuration",
|
|
5
5
|
"main": "bin/fetch.js",
|
|
6
6
|
"author": "Symbols",
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"node-fetch": "^3.1.0",
|
|
27
27
|
"v8-compile-cache": "^2.3.0"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "52bd85217084c8bbfa6222526edb36930ce7106d"
|
|
30
30
|
}
|