@symbo.ls/cli 2.11.375 → 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 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
 
@@ -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 (body.designsystem) {
94
- body.designSystem = body.designsystem
95
- delete body.designsystem
96
- }
101
+ if (!distDir) {
102
+ const bodyString = JSON.stringify(body, null, prettify ?? 2)
97
103
 
98
- const bodyString = JSON.stringify(body, null, prettify ?? 2)
104
+ try {
105
+ await fs.writeFileSync(LOCAL_CONFIG_PATH, bodyString)
99
106
 
100
- try {
101
- await fs.writeFileSync(LOCAL_CONFIG_PATH, bodyString)
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
- if (verbose) {
104
- console.log(chalk.dim('\ndynamic.json has been updated:'))
105
- console.log(chalk.dim.underline(LOCAL_CONFIG_PATH))
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(chalk.bold.green('\nSuccessfully wrote file'))
109
- } catch (e) {
110
- console.log(chalk.bold.red('\nError writing file'))
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,11 +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('--update', 'overriding changes from platform')
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
- // program
139
- // .command("push")
140
- // .description("Push changes to platform")
141
- // .action(fetchFromCli({ cache: true }));
149
+ program.command('push').description('Push changes to platform').action(fs2js)
package/bin/fs.js CHANGED
@@ -5,17 +5,20 @@ 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 {
11
+ deepDestringify,
12
+ objectToString,
13
+ joinArrays,
14
+ isString,
15
+ isObject,
16
+ removeValueFromArray
17
+ } = utils
16
18
 
17
19
  let singleFileKeys = ['designSystem', 'state', 'files']
18
- const keys = ['components', 'snippets', 'pages']
20
+ const directoryKeys = ['components', 'snippets', 'pages']
21
+
19
22
  const defaultExports = ['pages', 'designSystem', 'state', 'files', 'schema']
20
23
 
21
24
  export async function createFs (
@@ -41,7 +44,7 @@ export async function createFs (
41
44
  await fs.promises.mkdir(targetDir, { recursive: true })
42
45
 
43
46
  const promises = [
44
- ...keys.map((key) =>
47
+ ...directoryKeys.map((key) =>
45
48
  createKeyDirectoryAndFiles(key, body, targetDir, update)
46
49
  ),
47
50
  ...singleFileKeys.map((key) => {
@@ -53,11 +56,16 @@ export async function createFs (
53
56
  update
54
57
  )
55
58
  }
59
+ return undefined
56
60
  })
57
61
  ]
58
62
 
59
63
  await Promise.all(promises)
60
- await generateIndexjsFile(joinArrays(keys, singleFileKeys), targetDir, 'root')
64
+ await generateIndexjsFile(
65
+ joinArrays(singleFileKeys, directoryKeys),
66
+ targetDir,
67
+ 'root'
68
+ )
61
69
  }
62
70
 
63
71
  if (filesExist) {
@@ -65,18 +73,23 @@ export async function createFs (
65
73
  await fs.promises.mkdir(cacheDir, { recursive: true })
66
74
 
67
75
  const cachePromises = [
68
- ...keys.map((key) =>
76
+ ...directoryKeys.map((key) =>
69
77
  createKeyDirectoryAndFiles(key, body, cacheDir, true)
70
78
  ),
71
79
  ...singleFileKeys.map((key) => {
72
80
  if (body[key] && typeof body[key] === 'object') {
73
81
  return createSingleFileFolderAndFile(key, body[key], cacheDir, true)
74
82
  }
83
+ return undefined
75
84
  })
76
85
  ]
77
86
 
78
87
  await Promise.all(cachePromises)
79
- await generateIndexjsFile(joinArrays(keys, singleFileKeys), cacheDir, 'root')
88
+ await generateIndexjsFile(
89
+ joinArrays(directoryKeys, singleFileKeys),
90
+ cacheDir,
91
+ 'root'
92
+ )
80
93
 
81
94
  const diffs = await findDiff(cacheDir, targetDir)
82
95
  if (diffs.length > 0) {
@@ -114,7 +127,7 @@ export async function createFs (
114
127
 
115
128
  const dirs = []
116
129
 
117
- if (body[key] && typeof body[key] === 'object') {
130
+ if (body[key] && isObject(body[key])) {
118
131
  const promises = Object.entries(body[key]).map(
119
132
  async ([entryKey, value]) => {
120
133
  // if pages
@@ -134,7 +147,10 @@ export async function createFs (
134
147
  }
135
148
 
136
149
  async function createOrUpdateFile (dirPath, childKey, value, update) {
137
- const cleanKey = childKey.includes('-') || childKey.includes('/') ? removeChars(toCamelCase(childKey)) : childKey
150
+ const itemKey =
151
+ childKey.includes('-') || childKey.includes('/')
152
+ ? removeChars(toCamelCase(childKey))
153
+ : childKey
138
154
  const filePath = path.join(dirPath, `${childKey.replace('/', '-')}.js`)
139
155
 
140
156
  if (!update && fs.existsSync(filePath)) {
@@ -143,10 +159,14 @@ export async function createFs (
143
159
 
144
160
  let stringifiedContent
145
161
  if (isString(value)) {
146
- stringifiedContent = `export const ${cleanKey} = ${value}`
162
+ stringifiedContent = `export const ${itemKey} = ${value}`
147
163
  } else {
148
164
  const content = deepDestringify(value)
149
- stringifiedContent = `export const ${cleanKey} = ${objectToString(content)};`
165
+ // console.log('ON DEEPDESTR:')
166
+ // console.log(content.components.Configuration)
167
+ stringifiedContent = `export const ${itemKey} = ${objectToString(
168
+ content
169
+ )};`
150
170
  }
151
171
 
152
172
  await fs.promises.writeFile(filePath, stringifiedContent, 'utf8')
@@ -183,14 +203,12 @@ export async function createFs (
183
203
 
184
204
  // fs.writeFileSync(destPath, genStr)
185
205
  // }
186
-
187
- await fs.writeFileSync(LOCAL_CONFIG_PATH, '{}')
188
206
  }
189
207
 
190
208
  async function findDiff (targetDir, distDir) {
191
209
  const diffs = []
192
210
 
193
- for (const key of keys) {
211
+ for (const key of directoryKeys) {
194
212
  const targetDirPath = path.join(targetDir, key)
195
213
  const distDirPath = path.join(distDir, key)
196
214
 
@@ -218,10 +236,7 @@ async function findDiff (targetDir, distDir) {
218
236
  continue
219
237
  }
220
238
 
221
- const targetContent = await fs.promises.readFile(
222
- targetFilePath,
223
- 'utf8'
224
- )
239
+ const targetContent = await fs.promises.readFile(targetFilePath, 'utf8')
225
240
  const distContent = await fs.promises.readFile(distFilePath, 'utf8')
226
241
 
227
242
  if (targetContent !== distContent) {
@@ -269,26 +284,49 @@ async function generateIndexjsFile (dirs, dirPath, key) {
269
284
  let indexContent
270
285
  if (key === 'pages') {
271
286
  indexContent =
272
- dirs.map((d) => `import { ${d.includes('-') || d.includes('/') ? removeChars(toCamelCase(d)) : d} } from './${d.replace('/', '-')}';`).join('\n') + '\n' +
273
- `export default {
274
- ${dirs.map((d) => `'/${d === 'main' ? '' : d}': ${d.includes('-') || d.includes('/') ? removeChars(toCamelCase(d)) : d},`).join('\n') + '\n'}
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
+ }
275
311
  }`
276
312
  } else if (key === 'root') {
277
313
  indexContent =
278
- dirs.map((d) => {
279
- if (defaultExports.includes(d)) return `export { default as ${d} } from './${d}';`
280
- else return `export * as ${d} from './${d}';`
281
- }).join('\n') + '\n'
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'
282
321
  } else {
283
- indexContent =
284
- dirs.map((d) => `export * from './${d}';`).join('\n') + '\n'
322
+ indexContent = dirs.map((d) => `export * from './${d}';`).join('\n') + '\n'
285
323
  }
286
324
  const indexFilePath = path.join(dirPath, 'index.js')
287
325
  await fs.promises.writeFile(indexFilePath, indexContent, 'utf8')
288
326
  }
289
327
 
290
328
  async function overrideFiles (targetDir, distDir) {
291
- for (const key of keys) {
329
+ for (const key of directoryKeys) {
292
330
  const targetDirPath = path.join(targetDir, key)
293
331
  const distDirPath = path.join(distDir, key)
294
332
 
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.375",
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": "4fddad68b778dbfd8298ac6ca8d500bdabbb2282"
29
+ "gitHead": "0832ae608bf20ab45b988331e1b4bb88b4e449ba"
30
30
  }