@symbo.ls/cli 2.11.378 → 2.11.384
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 +2 -5
- package/bin/fs.js +63 -19
- package/bin/fs2.js +85 -0
- package/package.json +2 -2
package/bin/fetch.js
CHANGED
|
@@ -8,7 +8,7 @@ import * as fetch from '@symbo.ls/fetch'
|
|
|
8
8
|
import * as utils from '@domql/utils'
|
|
9
9
|
import { convertFromCli } from './convert.js'
|
|
10
10
|
import { createFs } from './fs.js'
|
|
11
|
-
|
|
11
|
+
import { fs2js } from './fs2.js'
|
|
12
12
|
const { isObjectLike } = utils.default
|
|
13
13
|
const { fetchRemote } = fetch.default
|
|
14
14
|
|
|
@@ -146,7 +146,4 @@ program
|
|
|
146
146
|
.option('--dist-dir', 'Directory to import files to.')
|
|
147
147
|
.action(fetchFromCli)
|
|
148
148
|
|
|
149
|
-
|
|
150
|
-
// .command("push")
|
|
151
|
-
// .description("Push changes to platform")
|
|
152
|
-
// .action(fetchFromCli({ cache: true }));
|
|
149
|
+
program.command('push').description('Push changes to platform').action(fs2js)
|
package/bin/fs.js
CHANGED
|
@@ -7,7 +7,14 @@ import inquirer from 'inquirer'
|
|
|
7
7
|
import { createPatch } from 'diff'
|
|
8
8
|
|
|
9
9
|
const { removeChars, toCamelCase } = smblsUtils.default
|
|
10
|
-
const {
|
|
10
|
+
const {
|
|
11
|
+
deepDestringify,
|
|
12
|
+
objectToString,
|
|
13
|
+
joinArrays,
|
|
14
|
+
isString,
|
|
15
|
+
isObject,
|
|
16
|
+
removeValueFromArray
|
|
17
|
+
} = utils
|
|
11
18
|
|
|
12
19
|
let singleFileKeys = ['designSystem', 'state', 'files']
|
|
13
20
|
const directoryKeys = ['components', 'snippets', 'pages']
|
|
@@ -49,12 +56,19 @@ export async function createFs (
|
|
|
49
56
|
update
|
|
50
57
|
)
|
|
51
58
|
}
|
|
59
|
+
return undefined
|
|
52
60
|
})
|
|
53
61
|
]
|
|
54
62
|
|
|
55
63
|
await Promise.all(promises)
|
|
56
|
-
await generateIndexjsFile(
|
|
57
|
-
|
|
64
|
+
await generateIndexjsFile(
|
|
65
|
+
joinArrays(singleFileKeys, directoryKeys),
|
|
66
|
+
targetDir,
|
|
67
|
+
'root'
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (filesExist) {
|
|
58
72
|
const cacheDir = path.join(distDir, '.cache')
|
|
59
73
|
await fs.promises.mkdir(cacheDir, { recursive: true })
|
|
60
74
|
|
|
@@ -66,11 +80,16 @@ export async function createFs (
|
|
|
66
80
|
if (body[key] && typeof body[key] === 'object') {
|
|
67
81
|
return createSingleFileFolderAndFile(key, body[key], cacheDir, true)
|
|
68
82
|
}
|
|
83
|
+
return undefined
|
|
69
84
|
})
|
|
70
85
|
]
|
|
71
86
|
|
|
72
87
|
await Promise.all(cachePromises)
|
|
73
|
-
await generateIndexjsFile(
|
|
88
|
+
await generateIndexjsFile(
|
|
89
|
+
joinArrays(directoryKeys, singleFileKeys),
|
|
90
|
+
cacheDir,
|
|
91
|
+
'root'
|
|
92
|
+
)
|
|
74
93
|
|
|
75
94
|
const diffs = await findDiff(cacheDir, targetDir)
|
|
76
95
|
if (diffs.length > 0) {
|
|
@@ -128,7 +147,10 @@ export async function createFs (
|
|
|
128
147
|
}
|
|
129
148
|
|
|
130
149
|
async function createOrUpdateFile (dirPath, childKey, value, update) {
|
|
131
|
-
const itemKey =
|
|
150
|
+
const itemKey =
|
|
151
|
+
childKey.includes('-') || childKey.includes('/')
|
|
152
|
+
? removeChars(toCamelCase(childKey))
|
|
153
|
+
: childKey
|
|
132
154
|
const filePath = path.join(dirPath, `${childKey.replace('/', '-')}.js`)
|
|
133
155
|
|
|
134
156
|
if (!update && fs.existsSync(filePath)) {
|
|
@@ -142,7 +164,9 @@ export async function createFs (
|
|
|
142
164
|
const content = deepDestringify(value)
|
|
143
165
|
// console.log('ON DEEPDESTR:')
|
|
144
166
|
// console.log(content.components.Configuration)
|
|
145
|
-
stringifiedContent = `export const ${itemKey} = ${objectToString(
|
|
167
|
+
stringifiedContent = `export const ${itemKey} = ${objectToString(
|
|
168
|
+
content
|
|
169
|
+
)};`
|
|
146
170
|
}
|
|
147
171
|
|
|
148
172
|
await fs.promises.writeFile(filePath, stringifiedContent, 'utf8')
|
|
@@ -212,10 +236,7 @@ async function findDiff (targetDir, distDir) {
|
|
|
212
236
|
continue
|
|
213
237
|
}
|
|
214
238
|
|
|
215
|
-
const targetContent = await fs.promises.readFile(
|
|
216
|
-
targetFilePath,
|
|
217
|
-
'utf8'
|
|
218
|
-
)
|
|
239
|
+
const targetContent = await fs.promises.readFile(targetFilePath, 'utf8')
|
|
219
240
|
const distContent = await fs.promises.readFile(distFilePath, 'utf8')
|
|
220
241
|
|
|
221
242
|
if (targetContent !== distContent) {
|
|
@@ -263,19 +284,42 @@ async function generateIndexjsFile (dirs, dirPath, key) {
|
|
|
263
284
|
let indexContent
|
|
264
285
|
if (key === 'pages') {
|
|
265
286
|
indexContent =
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
287
|
+
dirs
|
|
288
|
+
.map(
|
|
289
|
+
(d) =>
|
|
290
|
+
`import { ${
|
|
291
|
+
d.includes('-') || d.includes('/')
|
|
292
|
+
? removeChars(toCamelCase(d))
|
|
293
|
+
: d
|
|
294
|
+
} } from './${d.replace('/', '-')}';`
|
|
295
|
+
)
|
|
296
|
+
.join('\n') +
|
|
297
|
+
'\n' +
|
|
298
|
+
`export default {
|
|
299
|
+
${
|
|
300
|
+
dirs
|
|
301
|
+
.map(
|
|
302
|
+
(d) =>
|
|
303
|
+
`'/${d === 'main' ? '' : d}': ${
|
|
304
|
+
d.includes('-') || d.includes('/')
|
|
305
|
+
? removeChars(toCamelCase(d))
|
|
306
|
+
: d
|
|
307
|
+
},`
|
|
308
|
+
)
|
|
309
|
+
.join('\n') + '\n'
|
|
310
|
+
}
|
|
269
311
|
}`
|
|
270
312
|
} else if (key === 'root') {
|
|
271
313
|
indexContent =
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
314
|
+
dirs
|
|
315
|
+
.map((d) => {
|
|
316
|
+
if (defaultExports.includes(d)) {
|
|
317
|
+
return `export { default as ${d} } from './${d}';`
|
|
318
|
+
} else return `export * as ${d} from './${d}';`
|
|
319
|
+
})
|
|
320
|
+
.join('\n') + '\n'
|
|
276
321
|
} else {
|
|
277
|
-
indexContent =
|
|
278
|
-
dirs.map((d) => `export * from './${d}';`).join('\n') + '\n'
|
|
322
|
+
indexContent = dirs.map((d) => `export * from './${d}';`).join('\n') + '\n'
|
|
279
323
|
}
|
|
280
324
|
const indexFilePath = path.join(dirPath, 'index.js')
|
|
281
325
|
await fs.promises.writeFile(indexFilePath, indexContent, 'utf8')
|
package/bin/fs2.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import { build } from 'esbuild'
|
|
4
|
+
import { loadModule } from './require.js'
|
|
5
|
+
|
|
6
|
+
const RC_PATH = process.cwd() + '/symbols.json'
|
|
7
|
+
|
|
8
|
+
let rc = {}
|
|
9
|
+
try {
|
|
10
|
+
rc = loadModule(RC_PATH); // eslint-disable-line
|
|
11
|
+
} catch (e) {
|
|
12
|
+
console.error('Please include symbols.json to your root of respository')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function fs2js () {
|
|
16
|
+
const directoryPath = './toko'
|
|
17
|
+
const outputDirectory = './toko/dist'
|
|
18
|
+
buildDirectory(directoryPath, outputDirectory)
|
|
19
|
+
.then(() => {
|
|
20
|
+
console.log('All files built successfully')
|
|
21
|
+
})
|
|
22
|
+
.catch((error) => {
|
|
23
|
+
console.error('Error:', error)
|
|
24
|
+
})
|
|
25
|
+
const kleo = await import(process.cwd() + '/toko/dist/index.js')
|
|
26
|
+
console.log(JSON.stringify(kleo))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function buildDirectory (directoryPath, outputDirectory) {
|
|
30
|
+
try {
|
|
31
|
+
const files = await getFilesRecursively(directoryPath)
|
|
32
|
+
const buildPromises = files.map(async (filePath) => {
|
|
33
|
+
const relativePath = path.relative(directoryPath, filePath)
|
|
34
|
+
const outputFile = path.join(outputDirectory, relativePath)
|
|
35
|
+
await buildFromFile(filePath, outputFile)
|
|
36
|
+
})
|
|
37
|
+
await Promise.all(buildPromises)
|
|
38
|
+
console.log('All files built successfully')
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error('Error building directory:', error)
|
|
41
|
+
throw error
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function buildFromFile (inputFilePath, outputFilePath) {
|
|
46
|
+
try {
|
|
47
|
+
const fileContents = await fs.readFileSync(inputFilePath, 'utf8')
|
|
48
|
+
await build({
|
|
49
|
+
stdin: {
|
|
50
|
+
contents: fileContents,
|
|
51
|
+
sourcefile: inputFilePath,
|
|
52
|
+
loader: 'js',
|
|
53
|
+
resolveDir: path.dirname(inputFilePath)
|
|
54
|
+
},
|
|
55
|
+
minify: false,
|
|
56
|
+
outfile: outputFilePath,
|
|
57
|
+
target: 'node14',
|
|
58
|
+
platform: 'node',
|
|
59
|
+
format: 'cjs'
|
|
60
|
+
})
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error('Error building file:', error)
|
|
63
|
+
throw error
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function getFilesRecursively (directoryPath) {
|
|
68
|
+
const files = []
|
|
69
|
+
async function traverseDirectory (currentPath) {
|
|
70
|
+
const entries = await fs.readdirSync(currentPath, { withFileTypes: true })
|
|
71
|
+
for (const entry of entries) {
|
|
72
|
+
if (entry.name.startsWith('dist')) {
|
|
73
|
+
continue
|
|
74
|
+
}
|
|
75
|
+
const fullPath = path.join(currentPath, entry.name)
|
|
76
|
+
if (entry.isDirectory()) {
|
|
77
|
+
await traverseDirectory(fullPath)
|
|
78
|
+
} else if (entry.isFile() && entry.name.endsWith('.js')) {
|
|
79
|
+
files.push(fullPath)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
await traverseDirectory(directoryPath)
|
|
84
|
+
return files
|
|
85
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/cli",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.384",
|
|
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": "0832ae608bf20ab45b988331e1b4bb88b4e449ba"
|
|
30
30
|
}
|