create-smbls 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/clean.js ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { sync } from '@symbo.ls/socket'
4
+ import { program } from './program.js'
5
+
6
+ program
7
+ .command('clean')
8
+ .description('Clean Symbols temp files')
9
+ .action(async () => {
10
+ sync()
11
+ })
package/bin/convert.js ADDED
@@ -0,0 +1,39 @@
1
+ 'use strict'
2
+
3
+ // import chalk from 'chalk'
4
+ import { program } from './program.js'
5
+ // import convert, { convertDomqlModule } from '@symbo.ls/convert'
6
+
7
+ const TMP_DIR_NAME = '.smbls_convert_tmp'
8
+
9
+ export function convertFromCli (data, opts) {
10
+ // const { framework, verbose, verboseCode } = opts
11
+ // // const convertedStrings = convertDomqlModule(data, null, framework)
12
+ // if (verboseCode) console.log(convertedStrings)
13
+ // return verbose
14
+ }
15
+
16
+ program
17
+ .command('convert')
18
+ .description('Convert and copy all DOMQL components under a directory')
19
+ .argument('[src]', 'Source directory/file. By default, it is "src/"')
20
+ .argument('[dest]',
21
+ 'Destination directory/file. Will be overwritten. By ' +
22
+ 'default, it becomes the name of the desired format')
23
+ .option('--react', 'Convert all DomQL components to React')
24
+ .option('--angular', 'Convert all DomQL components to Angular')
25
+ .option('--vue2', 'Convert all DomQL components to Vue2')
26
+ .option('--vue3', 'Convert all DomQL components to Vue3')
27
+ .option('-t, --tmp-dir <path>',
28
+ 'Use this directory for storing intermediate & build files instead of ' +
29
+ `the default (dest/${TMP_DIR_NAME})`)
30
+ .option('-o, --only <components>',
31
+ 'Only convert these components; comma separated ' +
32
+ '(for example: --only=Flex,Img)')
33
+ .option('-m, --merge <dir>',
34
+ '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')
35
+ .option('-v, --verbose', 'Run the converter in verbose-mode')
36
+ .option('--internal-uikit',
37
+ '(For internal use only). ' +
38
+ 'Excludes particular components from the conversion')
39
+ .action(convertFromCli)
package/bin/create.js ADDED
@@ -0,0 +1,98 @@
1
+ 'use strict'
2
+
3
+ import chalk from 'chalk'
4
+ import fs from 'fs'
5
+ import path from 'path'
6
+ import { exec, execSync } from 'child_process'
7
+ import { program } from './program.js'
8
+ import { addToJson } from './init-helpers/addToJson.js'
9
+
10
+ function folderExists (path) {
11
+ try {
12
+ fs.accessSync(path, fs.constants.F_OK)
13
+ return true // The folder exists
14
+ } catch (err) {
15
+ return false // The folder does not exist
16
+ }
17
+ }
18
+
19
+ const REPO_URLS = {
20
+ domql: 'https://github.com/symbo-ls/starter-kit',
21
+ react: 'https://github.com/symbo-ls/create-react-app.git',
22
+ angular: 'https://github.com/symbo-ls/create-angular-app.git',
23
+ vue2: 'https://github.com/symbo-ls/create-vue2-app.git',
24
+ vue3: 'https://github.com/symbo-ls/create-vue3-app.git'
25
+ }
26
+
27
+ program
28
+ .command('create')
29
+ .description('Create and initialize a new project')
30
+ .argument('dest', 'Project directory')
31
+ .option('--verbose', 'Verbose output')
32
+ .option('--remote', 'Fetch from platform', true)
33
+ .option('--domql', 'Use DOMQL in the project', true)
34
+ .option('--react', 'Use React in the project (default)')
35
+ .option('--angular', 'Use Angular in the project')
36
+ .option('--vue2', 'Use Vue2 in the project')
37
+ .option('--vue3', 'Use Vue3 in the project')
38
+ .option('--package-manager <manager>', 'Choose the package manager (e.g., npm, yarn)', 'npm')
39
+ .option('--clean-from-git', 'remove starter-kit git repository', true)
40
+ .action(async (dest = 'symbols-starter-kit', options) => {
41
+ // Determine framework
42
+ let framework = 'domql'
43
+ if (options.react) {
44
+ framework = 'react'
45
+ } else if (options.angular) {
46
+ framework = 'angular'
47
+ } else if (options.vue2) {
48
+ framework = 'vue2'
49
+ } else if (options.vue3) {
50
+ framework = 'vue3'
51
+ }
52
+ const cloneUrl = REPO_URLS[framework]
53
+ const packageManager = options.packageManager || 'yarn'
54
+
55
+ if (folderExists(dest)) {
56
+ console.error(`Folder ${dest} already exists!`)
57
+ return
58
+ }
59
+
60
+ console.log(`Cloning ${cloneUrl} into '${dest}'...`)
61
+ execSync(`git clone ${options.remote ? ' -b feature/remote' : ''} ${cloneUrl} ${dest}`)
62
+
63
+ process.chdir(dest)
64
+
65
+ const SYMBOLS_FILE_PATH = path.join(process.cwd(), 'symbols.json')
66
+ addToJson(SYMBOLS_FILE_PATH, 'key', `${dest}.symbo.ls`)
67
+ addToJson(SYMBOLS_FILE_PATH, 'packageManager', `${packageManager}`)
68
+
69
+ console.log(`Installing dependencies using ${packageManager}...`)
70
+
71
+ const exc = exec(packageManager === 'yarn' ? 'yarn' : 'npm i')
72
+
73
+ if (options.verbose) {
74
+ exc.stdout.on('data', (data) => {
75
+ console.log(data)
76
+ })
77
+ exc.stderr.on('data', (data) => {
78
+ console.error(data)
79
+ })
80
+ } else {
81
+ console.log(chalk.dim('Use --verbose to print the output'))
82
+ }
83
+
84
+ console.log()
85
+
86
+ exc.on('close', (code) => {
87
+ console.log()
88
+ console.log(chalk.green.bold(dest), 'successfuly created!')
89
+ console.log(`Done! run \`${chalk.bold('cd ' + dest + '; ' + packageManager + ' start')}\` to start the development server.`)
90
+ })
91
+
92
+ if (options.cleanFromGit) {
93
+ fs.rmSync('.git', {
94
+ recursive: true,
95
+ force: true
96
+ })
97
+ }
98
+ })
package/bin/fetch.js ADDED
@@ -0,0 +1,152 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'fs'
4
+ import chalk from 'chalk'
5
+ import { loadModule } from './require.js'
6
+ import { program } from './program.js'
7
+ import * as fetch from '@symbo.ls/fetch'
8
+ import * as utils from '@domql/utils'
9
+ import { convertFromCli } from './convert.js'
10
+ import { createFs } from './fs.js'
11
+
12
+ const { isObjectLike } = utils.default
13
+ const { fetchRemote } = fetch.default
14
+
15
+ const RC_PATH = process.cwd() + '/symbols.json'
16
+ const LOCAL_CONFIG_PATH =
17
+ process.cwd() + '/node_modules/@symbo.ls/init/dynamic.json'
18
+ const DEFAULT_REMOTE_REPOSITORY = 'https://github.com/symbo-ls/default-config/'
19
+ const DEFAULT_REMOTE_CONFIG_PATH = "https://api.symbols.app/"; // eslint-disable-line
20
+
21
+ const API_URL_LOCAL = 'http://localhost:13335/get'
22
+ const API_URL = 'https://api.symbols.app/get'
23
+
24
+ const rcFile = loadModule(RC_PATH); // eslint-disable-line
25
+ const localConfig = loadModule(LOCAL_CONFIG_PATH); // eslint-disable-line
26
+
27
+ const debugMsg = chalk.dim(
28
+ 'Use --verbose to debug the error or open the issue at https://github.com/symbo-ls/smbls'
29
+ )
30
+
31
+ let rc = {}
32
+ try {
33
+ rc = loadModule(RC_PATH); // eslint-disable-line
34
+ } catch (e) {
35
+ console.error('Please include symbols.json to your root of respository')
36
+ }
37
+
38
+ export const fetchFromCli = async (opts) => {
39
+ const { dev, verbose, prettify, convert: convertOpt, metadata: metadataOpt, update, force } = opts
40
+ await rc.then(async (data) => {
41
+ const { key, framework, distDir, metadata } = data
42
+
43
+ const endpoint = dev ? API_URL_LOCAL : API_URL
44
+
45
+ console.log('\nFetching from:', chalk.bold(endpoint), '\n')
46
+
47
+ const body = await fetchRemote(key, {
48
+ endpoint,
49
+ metadata: metadata || metadataOpt,
50
+ onError: (e) => {
51
+ console.log(chalk.red('Failed to fetch:'), key)
52
+ if (verbose) console.error(e)
53
+ else console.log(debugMsg)
54
+ }
55
+ })
56
+
57
+ // console.log('ON FETCH:')
58
+ // console.log(body.components.Configuration)
59
+
60
+ if (!body) return
61
+
62
+ const { version, ...config } = body
63
+
64
+ if (body.designsystem) {
65
+ body.designSystem = body.designsystem
66
+ delete body.designsystem
67
+ }
68
+
69
+ if (verbose) {
70
+ if (key) {
71
+ console.log(
72
+ chalk.bold('Symbols'),
73
+ 'data fetched for',
74
+ chalk.green(body.name)
75
+ )
76
+ } else {
77
+ console.log(
78
+ chalk.bold('Symbols'),
79
+ 'config fetched from',
80
+ chalk.bold('default-config from:'),
81
+ chalk.dim.underline(DEFAULT_REMOTE_REPOSITORY)
82
+ )
83
+ }
84
+ console.log()
85
+ }
86
+
87
+ for (const t in config) {
88
+ const type = config[t]
89
+ const arr = []
90
+ if (isObjectLike(type)) {
91
+ for (const v in type) arr.push(v)
92
+ if (arr.length) {
93
+ console.log(chalk.dim(t + ':'))
94
+ console.log(chalk.bold(arr.join(', ')))
95
+ } else {
96
+ console.log(chalk.dim(t + ':'), chalk.dim('- empty -'))
97
+ }
98
+ } else console.log(chalk.dim(t + ':'), chalk.bold(type))
99
+ }
100
+
101
+ if (!distDir) {
102
+ const bodyString = JSON.stringify(body, null, prettify ?? 2)
103
+
104
+ try {
105
+ await fs.writeFileSync(LOCAL_CONFIG_PATH, bodyString)
106
+
107
+ if (verbose) {
108
+ console.log(chalk.dim('\ndynamic.json has been updated:'))
109
+ console.log(chalk.dim.underline(LOCAL_CONFIG_PATH))
110
+ }
111
+
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)
117
+ }
118
+
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 {}
122
+ }
123
+
124
+ if (body.components && convertOpt && framework) {
125
+ convertFromCli(body.components, { ...opts, framework })
126
+ }
127
+
128
+ if (update || force) {
129
+ createFs(body, distDir, { update: true, metadata })
130
+ } else {
131
+ createFs(body, distDir, { metadata })
132
+ }
133
+ })
134
+ }
135
+
136
+ program
137
+ .command('fetch')
138
+ .description('Fetch Symbols')
139
+ .option('-d, --dev', 'Running from local server')
140
+ .option('-v, --verbose', 'Verbose errors and warnings')
141
+ .option('--convert', 'Verbose errors and warnings', true)
142
+ .option('--metadata', 'Include metadata', false)
143
+ .option('--force', 'Force overriding changes from platform')
144
+ .option('--update', 'Overriding changes from platform')
145
+ .option('--verbose-code', 'Verbose errors and warnings')
146
+ .option('--dist-dir', 'Directory to import files to.')
147
+ .action(fetchFromCli)
148
+
149
+ // program
150
+ // .command("push")
151
+ // .description("Push changes to platform")
152
+ // .action(fetchFromCli({ cache: true }));
package/bin/fs.js ADDED
@@ -0,0 +1,325 @@
1
+ import fs from 'fs'
2
+ import chalk from 'chalk'
3
+ import path from 'path'
4
+ import utils from '@domql/utils'
5
+ import * as smblsUtils from '@symbo.ls/utils'
6
+ import inquirer from 'inquirer'
7
+ import { createPatch } from 'diff'
8
+
9
+ const { removeChars, toCamelCase } = smblsUtils.default
10
+ const { deepDestringify, objectToString, joinArrays, isString, isObject, removeValueFromArray } = utils
11
+
12
+ let singleFileKeys = ['designSystem', 'state', 'files']
13
+ const directoryKeys = ['components', 'snippets', 'pages']
14
+
15
+ const defaultExports = ['pages', 'designSystem', 'state', 'files', 'schema']
16
+
17
+ export async function createFs (
18
+ body,
19
+ distDir = path.join(process.cwd(), 'smbls'),
20
+ opts = {}
21
+ ) {
22
+ if (!body) {
23
+ console.error('No JSON object provided. Exiting.')
24
+ return
25
+ }
26
+
27
+ const { update, metadata } = opts
28
+
29
+ singleFileKeys = removeValueFromArray(singleFileKeys, 'schema')
30
+ if (metadata) singleFileKeys.push('schema')
31
+
32
+ const targetDir = distDir
33
+
34
+ const filesExist = fs.existsSync(targetDir)
35
+
36
+ if (!filesExist || update) {
37
+ await fs.promises.mkdir(targetDir, { recursive: true })
38
+
39
+ const promises = [
40
+ ...directoryKeys.map((key) =>
41
+ createKeyDirectoryAndFiles(key, body, targetDir, update)
42
+ ),
43
+ ...singleFileKeys.map((key) => {
44
+ if (body[key] && typeof body[key] === 'object') {
45
+ return createSingleFileFolderAndFile(
46
+ key,
47
+ body[key],
48
+ targetDir,
49
+ update
50
+ )
51
+ }
52
+ })
53
+ ]
54
+
55
+ await Promise.all(promises)
56
+ await generateIndexjsFile(joinArrays(directoryKeys, singleFileKeys), targetDir, 'root')
57
+ } else if (filesExist) {
58
+ const cacheDir = path.join(distDir, '.cache')
59
+ await fs.promises.mkdir(cacheDir, { recursive: true })
60
+
61
+ const cachePromises = [
62
+ ...directoryKeys.map((key) =>
63
+ createKeyDirectoryAndFiles(key, body, cacheDir, true)
64
+ ),
65
+ ...singleFileKeys.map((key) => {
66
+ if (body[key] && typeof body[key] === 'object') {
67
+ return createSingleFileFolderAndFile(key, body[key], cacheDir, true)
68
+ }
69
+ })
70
+ ]
71
+
72
+ await Promise.all(cachePromises)
73
+ await generateIndexjsFile(joinArrays(directoryKeys, singleFileKeys), cacheDir, 'root')
74
+
75
+ const diffs = await findDiff(cacheDir, targetDir)
76
+ if (diffs.length > 0) {
77
+ console.log('Differences found:')
78
+ diffs.forEach((diff) => {
79
+ console.log(chalk.green(`File: ${diff.file}`))
80
+ console.log(chalk.yellow('Diff:'))
81
+ console.log(chalk.yellow(diff.diff))
82
+ console.log('---')
83
+ })
84
+ if (!update) {
85
+ const { consent } = await askForConsent()
86
+ if (consent) {
87
+ await overrideFiles(cacheDir, targetDir)
88
+ console.log('Files overridden successfully.')
89
+ } else {
90
+ console.log('Files not overridden.')
91
+ }
92
+ } else {
93
+ await overrideFiles(cacheDir, targetDir)
94
+ console.log('Files overridden successfully.')
95
+ console.log()
96
+ console.log(chalk.dim('\n----------------\n'))
97
+ }
98
+ } else {
99
+ console.log('No differences found.')
100
+ console.log()
101
+ console.log(chalk.dim('\n----------------\n'))
102
+ }
103
+ }
104
+
105
+ async function createKeyDirectoryAndFiles (key, body, distDir, update) {
106
+ const dirPath = path.join(distDir, key)
107
+ await fs.promises.mkdir(dirPath, { recursive: true })
108
+
109
+ const dirs = []
110
+
111
+ if (body[key] && isObject(body[key])) {
112
+ const promises = Object.entries(body[key]).map(
113
+ async ([entryKey, value]) => {
114
+ // if pages
115
+ if (entryKey.startsWith('/')) entryKey = entryKey.slice(1)
116
+ if (entryKey === '') entryKey = 'main'
117
+ if (entryKey.includes('*')) entryKey = 'fallback'
118
+
119
+ await createOrUpdateFile(dirPath, entryKey, value, update)
120
+ dirs.push(entryKey)
121
+ }
122
+ )
123
+
124
+ await Promise.all(promises)
125
+ }
126
+
127
+ await generateIndexjsFile(dirs, dirPath, key)
128
+ }
129
+
130
+ async function createOrUpdateFile (dirPath, childKey, value, update) {
131
+ const itemKey = childKey.includes('-') || childKey.includes('/') ? removeChars(toCamelCase(childKey)) : childKey
132
+ const filePath = path.join(dirPath, `${childKey.replace('/', '-')}.js`)
133
+
134
+ if (!update && fs.existsSync(filePath)) {
135
+ return
136
+ }
137
+
138
+ let stringifiedContent
139
+ if (isString(value)) {
140
+ stringifiedContent = `export const ${itemKey} = ${value}`
141
+ } else {
142
+ const content = deepDestringify(value)
143
+ // console.log('ON DEEPDESTR:')
144
+ // console.log(content.components.Configuration)
145
+ stringifiedContent = `export const ${itemKey} = ${objectToString(content)};`
146
+ }
147
+
148
+ await fs.promises.writeFile(filePath, stringifiedContent, 'utf8')
149
+ }
150
+
151
+ async function createSingleFileFolderAndFile (key, data, distDir, update) {
152
+ const filePath = path.join(distDir, `${key}.js`)
153
+
154
+ if (!update && fs.existsSync(filePath)) {
155
+ return
156
+ }
157
+
158
+ if (isString(data)) data = { default: data }
159
+ const content = deepDestringify(data)
160
+ const stringifiedContent = `export default ${objectToString(content)};`
161
+
162
+ await fs.promises.writeFile(filePath, stringifiedContent, 'utf8')
163
+ }
164
+
165
+ // Generate final package.json string
166
+ // function createPackageJson (key, data, distDir, update) {
167
+ // const genStr = JSON.stringify({
168
+ // name: `@symbo.ls/${desiredFormat}-${packageName}`,
169
+ // version: packageStruct.version ?? '1.0.0',
170
+ // license: packageStruct.license ?? 'UNLICENSED',
171
+ // dependencies: deps,
172
+ // peerDependencies: {
173
+ // smbls: '^18.2.0',
174
+ // 'react-dom': '^18.2.0'
175
+ // },
176
+ // main: 'index.js',
177
+ // source: 'index.js'
178
+ // }, undefined, 2)
179
+
180
+ // fs.writeFileSync(destPath, genStr)
181
+ // }
182
+ }
183
+
184
+ async function findDiff (targetDir, distDir) {
185
+ const diffs = []
186
+
187
+ for (const key of directoryKeys) {
188
+ const targetDirPath = path.join(targetDir, key)
189
+ const distDirPath = path.join(distDir, key)
190
+
191
+ if (!fs.existsSync(targetDirPath)) {
192
+ continue
193
+ }
194
+
195
+ const targetFiles = await fs.promises.readdir(targetDirPath)
196
+ for (const file of targetFiles) {
197
+ if (file === 'index.js') {
198
+ continue // Skip comparing index.js files
199
+ }
200
+
201
+ const targetFilePath = path.join(targetDirPath, file)
202
+ const distFilePath = path.join(distDirPath, file)
203
+
204
+ if (!fs.existsSync(distFilePath)) {
205
+ diffs.push({
206
+ file: path.join(key, file),
207
+ diff: `File ${path.join(
208
+ key,
209
+ file
210
+ )} does not exist in the dist directory.`
211
+ })
212
+ continue
213
+ }
214
+
215
+ const targetContent = await fs.promises.readFile(
216
+ targetFilePath,
217
+ 'utf8'
218
+ )
219
+ const distContent = await fs.promises.readFile(distFilePath, 'utf8')
220
+
221
+ if (targetContent !== distContent) {
222
+ const diff = createPatch(file, distContent, targetContent)
223
+ diffs.push({
224
+ file: path.join(key, file),
225
+ diff
226
+ })
227
+ }
228
+ }
229
+ }
230
+
231
+ for (const key of singleFileKeys) {
232
+ const targetFilePath = path.join(targetDir, `${key}.js`)
233
+ const distFilePath = path.join(distDir, `${key}.js`)
234
+
235
+ if (!fs.existsSync(targetFilePath)) {
236
+ continue
237
+ }
238
+
239
+ if (!fs.existsSync(distFilePath)) {
240
+ diffs.push({
241
+ file: `${key}.js`,
242
+ diff: `File ${key}.js does not exist in the dist directory.`
243
+ })
244
+ continue
245
+ }
246
+
247
+ const targetContent = await fs.promises.readFile(targetFilePath, 'utf8')
248
+ const distContent = await fs.promises.readFile(distFilePath, 'utf8')
249
+
250
+ if (targetContent !== distContent) {
251
+ const diff = createPatch(key, distContent, targetContent)
252
+ diffs.push({
253
+ file: `${key}.js`,
254
+ diff
255
+ })
256
+ }
257
+ }
258
+
259
+ return diffs
260
+ }
261
+
262
+ async function generateIndexjsFile (dirs, dirPath, key) {
263
+ let indexContent
264
+ if (key === 'pages') {
265
+ indexContent =
266
+ dirs.map((d) => `import { ${d.includes('-') || d.includes('/') ? removeChars(toCamelCase(d)) : d} } from './${d.replace('/', '-')}';`).join('\n') + '\n' +
267
+ `export default {
268
+ ${dirs.map((d) => `'/${d === 'main' ? '' : d}': ${d.includes('-') || d.includes('/') ? removeChars(toCamelCase(d)) : d},`).join('\n') + '\n'}
269
+ }`
270
+ } else if (key === 'root') {
271
+ indexContent =
272
+ dirs.map((d) => {
273
+ if (defaultExports.includes(d)) return `export { default as ${d} } from './${d}';`
274
+ else return `export * as ${d} from './${d}';`
275
+ }).join('\n') + '\n'
276
+ } else {
277
+ indexContent =
278
+ dirs.map((d) => `export * from './${d}';`).join('\n') + '\n'
279
+ }
280
+ const indexFilePath = path.join(dirPath, 'index.js')
281
+ await fs.promises.writeFile(indexFilePath, indexContent, 'utf8')
282
+ }
283
+
284
+ async function overrideFiles (targetDir, distDir) {
285
+ for (const key of directoryKeys) {
286
+ const targetDirPath = path.join(targetDir, key)
287
+ const distDirPath = path.join(distDir, key)
288
+
289
+ if (!fs.existsSync(targetDirPath)) {
290
+ continue
291
+ }
292
+
293
+ const targetFiles = await fs.promises.readdir(targetDirPath)
294
+ for (const file of targetFiles) {
295
+ const targetFilePath = path.join(targetDirPath, file)
296
+ const distFilePath = path.join(distDirPath, file)
297
+
298
+ await fs.promises.copyFile(targetFilePath, distFilePath)
299
+ }
300
+ }
301
+
302
+ for (const key of singleFileKeys) {
303
+ const targetFilePath = path.join(targetDir, `${key}.js`)
304
+ const distFilePath = path.join(distDir, `${key}.js`)
305
+
306
+ if (!fs.existsSync(targetFilePath)) {
307
+ continue
308
+ }
309
+
310
+ await fs.promises.copyFile(targetFilePath, distFilePath)
311
+ }
312
+ }
313
+
314
+ async function askForConsent () {
315
+ const questions = [
316
+ {
317
+ type: 'confirm',
318
+ name: 'consent',
319
+ message: 'Do you want to override the files?',
320
+ default: false
321
+ }
322
+ ]
323
+
324
+ return inquirer.prompt(questions)
325
+ }
package/bin/index.js ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+
3
+ import 'v8-compile-cache'
4
+
5
+ import { program } from './program.js'
6
+ import './install.js'
7
+ import './init.js'
8
+ import './fetch.js'
9
+ import './sync.js'
10
+ import './clean.js'
11
+ import './convert.js'
12
+ import './create.js'
13
+ import './link-packages.js'
14
+
15
+ const args = process.argv
16
+ program.parse(args)
@@ -0,0 +1,15 @@
1
+ export const CustomDesignSystem = {
2
+ ANIMATION: {},
3
+ COLOR: {},
4
+ GRADIENT: {},
5
+ THEME: {},
6
+ TYPOGRAPHY: {},
7
+ SPACING: {},
8
+ SVG: {},
9
+ ICONS: {},
10
+ FONT: {},
11
+ FONT_FAMILY: {},
12
+ TIMING: {},
13
+ MEDIA: {},
14
+ RESET: {}
15
+ }
@@ -0,0 +1,27 @@
1
+ 'use strict'
2
+
3
+ import fs from 'fs'
4
+
5
+ // Step 1: Read the JSON file
6
+ export const addToJson = (filePath, key, value) => {
7
+ const data = fs.readFileSync(filePath, { encoding: 'utf8' })
8
+ if (!data) {
9
+ console.error('Error reading file:', data)
10
+ return
11
+ }
12
+
13
+ try {
14
+ const jsonData = JSON.parse(data)
15
+
16
+ jsonData[key] = value
17
+
18
+ fs.writeFileSync(filePath, JSON.stringify(jsonData, null, 2), 'utf8', err => {
19
+ if (err) {
20
+ console.error('Error writing file:', err)
21
+ }
22
+ console.log(filePath, JSON.stringify(jsonData, null, 2))
23
+ })
24
+ } catch (parseError) {
25
+ console.error('Error parsing JSON:', parseError)
26
+ }
27
+ }
@@ -0,0 +1,62 @@
1
+ 'use strict'
2
+
3
+ import chalk from 'chalk'
4
+ import fs from 'fs'
5
+ import path from 'path'
6
+ import { execSync } from 'child_process'
7
+ import { fileURLToPath } from 'url'
8
+ import { addToJson } from './addToJson.js'
9
+
10
+ const __filename = fileURLToPath(import.meta.url)
11
+ const __dirname = path.dirname(__filename)
12
+ const SYMBOLS_FILE_PATH = path.join(
13
+ __dirname, 'symbols.json')
14
+ const DESIGN_SYSTEM_FILE_PATH = path.join(
15
+ __dirname, 'DesignSystem.js')
16
+
17
+ export async function initRepo (dest, framework) {
18
+ const cwd = process.cwd()
19
+
20
+ // Init NPM if necessary
21
+ if (!fs.existsSync(path.join(dest, 'package.json'))) {
22
+ process.chdir(dest)
23
+ console.log('Running npm init')
24
+ execSync('npm init -y')
25
+ process.chdir(cwd)
26
+ }
27
+
28
+ // Determine framework
29
+ let pkg = 'smbls'
30
+ if (framework === 'react') {
31
+ pkg = '@symbo.ls/react'
32
+ } else if (framework === 'angular') {
33
+ pkg = '@symbo.ls/react'
34
+ } else if (framework === 'vue2') {
35
+ pkg = '@symbo.ls/vue2'
36
+ } else if (framework === 'vue3') {
37
+ pkg = '@symbo.ls/vue3'
38
+ }
39
+
40
+ // TODO: inject smbls dependencies into package.json
41
+
42
+ // Install
43
+ console.log(`Installing \`${pkg}\` from NPM...`)
44
+ process.chdir(dest)
45
+ // execSync(`npm i ${pkg} --save`)
46
+ process.chdir(cwd)
47
+
48
+ // Copy design system file
49
+ console.log()
50
+ const dsfilePath = path.join(dest, 'DesignSystem.js')
51
+ console.log('Creating', chalk.bold(dsfilePath))
52
+ await fs.promises.copyFile(DESIGN_SYSTEM_FILE_PATH, dsfilePath)
53
+
54
+ // Copy design system file
55
+ const rcfilePath = path.join(dest, 'symbols.json')
56
+ console.log('Creating', chalk.bold(rcfilePath))
57
+ await fs.promises.copyFile(SYMBOLS_FILE_PATH, rcfilePath)
58
+ if (framework !== 'domql') addToJson(SYMBOLS_FILE_PATH, 'framework', framework)
59
+ console.log()
60
+
61
+ console.log(chalk.green.bold('Initialized project successfully.'))
62
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "key": "projectKey.symbo.ls"
3
+ }
package/bin/init.js ADDED
@@ -0,0 +1,32 @@
1
+ 'use strict'
2
+
3
+ import { program } from './program.js'
4
+ import { initRepo } from './init-helpers/init-repo.js'
5
+
6
+ program
7
+ .command('init')
8
+ .description('Initialize within the project')
9
+ .argument('[dest]', 'Project directory. By default, it is "."')
10
+ .option('--domql', 'Use Domql in the project', true)
11
+ .option('--react', 'Use React in the project (default)')
12
+ .option('--angular', 'Use Angular in the project')
13
+ .option('--vue2', 'Use Vue2 in the project')
14
+ .option('--vue3', 'Use Vue3 in the project')
15
+ .action(async (dest, options) => {
16
+ if (!dest) dest = '.'
17
+
18
+ // Determine framework
19
+ let framework = 'domql'
20
+ if (options.react) {
21
+ framework = 'react'
22
+ } else if (options.angular) {
23
+ framework = 'angular'
24
+ } else if (options.vue2) {
25
+ framework = 'vue2'
26
+ } else if (options.vue3) {
27
+ framework = 'vue3'
28
+ }
29
+
30
+ // Leave the rest to init
31
+ return await initRepo(dest, framework)
32
+ })
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,66 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'fs'
4
+ import { exec, execSync } from 'child_process'
5
+ import { program } from './program.js'
6
+
7
+ import packages from './linking/packages.js'
8
+
9
+ const COMMAND = 'npx lerna exec -- cat package.json | jq \'.name\''
10
+ const capture = (opts) => {
11
+ exec(COMMAND, (error, stdout, stderr) => {
12
+ if (error) {
13
+ console.error(`Error executing command: ${error}`)
14
+ return
15
+ }
16
+
17
+ const packageNames = stdout
18
+ .split('\n')
19
+ .map((line) => line.trim().replaceAll('"', '\''))
20
+ .filter(Boolean)
21
+
22
+ const output = `export default [
23
+ ${packageNames.map((name) => `${name}`).join(',\n ')}
24
+ ]\n`
25
+
26
+ try {
27
+ fs.writeFileSync(process.cwd() + '/packages/cli/bin/linking/packages.js', output)
28
+ console.log(`Packages list with ${packageNames.length} items successfully created\n`)
29
+ } catch (e) {
30
+ console.error('Error writing to file:')
31
+ console.error(e)
32
+ }
33
+
34
+ execSync(`yarn link ${packages.join(' ')} --force`, { stdio: 'inherit' })
35
+ })
36
+ }
37
+
38
+ program
39
+ .command('link-packages')
40
+ .description('Links all smbls packages into the project')
41
+ .option('-c, --capture', 'Capture and write all package names.')
42
+ .option('-j, --join', 'Join all links into one command.', true)
43
+ .action((opts) => {
44
+ if (opts.capture) return capture(opts)
45
+ if (opts.join) {
46
+ try {
47
+ console.log('Linking all smbls packages...')
48
+ execSync(`yarn link ${packages.join(' ')} --force`, { stdio: 'inherit' })
49
+ console.log('All packages linked successfully.')
50
+ } catch (error) {
51
+ console.error('Error linking packages:', error.message)
52
+ process.exit(1)
53
+ }
54
+ return
55
+ }
56
+ try {
57
+ for (const packageName of packages) {
58
+ console.log(`Linking ${packageName}...`)
59
+ execSync(`yarn link ${packageName} --force`, { stdio: 'inherit' })
60
+ }
61
+ console.log('All packages linked successfully.')
62
+ } catch (error) {
63
+ console.error('Error linking packages:', error.message)
64
+ process.exit(1)
65
+ }
66
+ })
@@ -0,0 +1,65 @@
1
+ export default [
2
+ 'attrs-in-props',
3
+ '@symbo.ls/cli',
4
+ '@symbo.ls/convert',
5
+ '@symbo.ls/create',
6
+ 'css-in-props',
7
+ '@symbo.ls/default-config',
8
+ '@symbo.ls/emotion',
9
+ '@symbo.ls/init',
10
+ '@symbo.ls/fetch',
11
+ '@symbo.ls/preview',
12
+ '@symbo.ls/scratch',
13
+ 'smbls',
14
+ '@symbo.ls/socket-ui',
15
+ '@symbo.ls/socket',
16
+ '@symbo.ls/uikit',
17
+ '@symbo.ls/utils',
18
+ '@symbo.ls/default-icons',
19
+ '@symbo.ls/feather-icons',
20
+ '@symbo.ls/fluent-icons',
21
+ '@symbo.ls/material-icons',
22
+ '@symbo.ls/google-maps',
23
+ '@symbo.ls/editorjs',
24
+ '@symbo.ls/helmet',
25
+ '@symbo.ls/markdown',
26
+ '@symbo.ls/atoms',
27
+ '@symbo.ls/avatar',
28
+ '@symbo.ls/banner',
29
+ '@symbo.ls/box',
30
+ '@symbo.ls/button',
31
+ '@symbo.ls/card',
32
+ '@symbo.ls/datepicker',
33
+ '@symbo.ls/dialog',
34
+ '@symbo.ls/doublehr',
35
+ '@symbo.ls/dropdown',
36
+ '@symbo.ls/field',
37
+ '@symbo.ls/form',
38
+ '@symbo.ls/hgroup',
39
+ '@symbo.ls/icon',
40
+ '@symbo.ls/indicator',
41
+ '@symbo.ls/input',
42
+ '@symbo.ls/label',
43
+ '@symbo.ls/link',
44
+ '@symbo.ls/list',
45
+ '@symbo.ls/modal',
46
+ '@symbo.ls/paragraphbutton',
47
+ '@symbo.ls/pills',
48
+ '@symbo.ls/notification',
49
+ '@symbo.ls/progress',
50
+ '@symbo.ls/range',
51
+ '@symbo.ls/select',
52
+ '@symbo.ls/sidebar',
53
+ '@symbo.ls/slider',
54
+ '@symbo.ls/sociallink',
55
+ '@symbo.ls/steps',
56
+ '@symbo.ls/table',
57
+ '@symbo.ls/tab',
58
+ '@symbo.ls/threejs',
59
+ '@symbo.ls/timepicker',
60
+ '@symbo.ls/tooltip',
61
+ '@symbo.ls/unitvalue',
62
+ '@symbo.ls/upload',
63
+ '@symbo.ls/user',
64
+ '@symbo.ls/video'
65
+ ]
package/bin/login.js ADDED
@@ -0,0 +1,18 @@
1
+ 'use strict'
2
+
3
+ const { program } = require('./program')
4
+ const API_URL = 'https://api.symbols.dev/' // eslint-disable-line
5
+
6
+ program
7
+ .command('login [destination]')
8
+ .description('Sign in to Symbols')
9
+ .argument('<username>', 'user to login')
10
+ .argument('[password]', 'password for user, if required', 'no password given')
11
+ .action(async (username, password) => {
12
+ console.log('username:', username)
13
+ console.log('password:', password)
14
+
15
+ const response = await fetch(API_URL)
16
+ const body = await response.json()
17
+ console.log(body)
18
+ })
package/bin/program.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from 'commander'
4
+ export const program = new Command()
package/bin/require.js ADDED
@@ -0,0 +1,13 @@
1
+ 'use strict'
2
+
3
+ import fs from 'fs'
4
+ import { createRequire } from 'module'
5
+
6
+ class ImportError extends Error {} /* Bring in the ability to create the 'require' method */ // eslint-disable-line
7
+ const require = createRequire(import.meta.url) // construct the require method
8
+
9
+ export const loadModule = async (modulePath) => {
10
+ if (fs.existsSync(modulePath)) {
11
+ return require(modulePath)
12
+ } else { return null }
13
+ }
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { sync } from '@symbo.ls/socket'
4
+ import { program } from './program.js'
5
+ import { loadModule } from './require.js'
6
+
7
+ const RC_PATH = process.cwd() + '/symbols.json'
8
+ let rc = {}
9
+ try {
10
+ rc = loadModule(RC_PATH) // eslint-disable-line
11
+ } catch (e) { console.error('Please include symbols.json to your root of respository') }
12
+
13
+ program
14
+ .command('socket-server')
15
+ .description('Realtime sync with Symbols')
16
+ .option('-l, --live', 'Bypass the local build')
17
+ .action(async (options) => {
18
+ rc.then(data => {
19
+ const opts = { ...data, ...options }
20
+ sync(null, opts)
21
+ })
22
+ })
@@ -0,0 +1 @@
1
+ {}
package/bin/sync.js ADDED
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env node
2
+
3
+ import chalk from 'chalk'
4
+ import { program } from './program.js'
5
+ import { loadModule } from './require.js'
6
+ import { updateDynamycFile } from '@symbo.ls/socket'
7
+ import * as utils from '@domql/utils'
8
+
9
+ import * as socketClient from '@symbo.ls/socket/client.js'
10
+ import { fetchFromCli } from './fetch.js'
11
+ import { convertFromCli } from './convert.js'
12
+
13
+ const { debounce } = utils.default
14
+
15
+ const SOCKET_API_URL_LOCAL = 'http://localhost:13336/'
16
+ const SOCKET_API_URL = 'https://socket.symbols.app/'
17
+
18
+ const debugMsg = chalk.dim('Use --verbose to debug the error or open the issue at https://github.com/symbo-ls/smbls')
19
+
20
+ const RC_PATH = process.cwd() + '/symbols.json'
21
+ let rc = {}
22
+ try {
23
+ rc = loadModule(RC_PATH) // eslint-disable-line
24
+ } catch (e) { console.error('Please include symbols.json to your root of respository') }
25
+
26
+ program
27
+ .command('sync')
28
+ .description('Realtime sync with Symbols')
29
+ .option('-d, --dev', 'Running from local server')
30
+ .option('-v, --verbose', 'Verbose errors and warnings')
31
+ .option('-k, --key', 'Bypass the symbols.json key, overriding the key manually')
32
+ .option('-f, --fetch', 'Verbose errors and warnings', true)
33
+ .option('--convert', 'Verbose errors and warnings', true)
34
+ .option('--update', 'overriding changes from platform', true)
35
+ .option('--verbose-code', 'Verbose errors and warnings')
36
+ .action(async (opts) => {
37
+ const { dev, verbose, fetch: fetchOpt, convert: convertOpt } = opts
38
+
39
+ if (fetchOpt) {
40
+ await fetchFromCli(opts)
41
+ console.log(chalk.dim('\n----------------\n'))
42
+ }
43
+
44
+ if (!rc) {
45
+ console.error('symbols.json not found in the root of the repository')
46
+ return
47
+ }
48
+
49
+ // if (rc) return false /// /////////////////////
50
+
51
+ await rc.then(symbolsrc => {
52
+ const options = { ...symbolsrc, ...opts }
53
+ const { framework, distDir, prettify, verboseCode } = options
54
+ const key = options.key || opts.key
55
+ const socketUrl = dev ? SOCKET_API_URL_LOCAL : SOCKET_API_URL
56
+
57
+ console.log('Connecting to:', chalk.bold(socketUrl))
58
+ console.log()
59
+
60
+ socketClient.connect(key, {
61
+ source: 'cli',
62
+ socketUrl,
63
+ onConnect: (id, socket) => {
64
+ console.log('Connected to', chalk.green(key), 'from', chalk.bold('Symbols'), 'socket server')
65
+ console.log('Socket id:', id)
66
+ console.log(chalk.dim('\nListening to updates...\n'))
67
+ },
68
+ onChange: debounce(async (event, data) => {
69
+ if (event === 'clients') {
70
+ console.log(
71
+ 'Active clients:',
72
+ chalk.green.bold(Object.keys(data).join(', '))
73
+ )
74
+ return
75
+ }
76
+
77
+ const parseData = JSON.parse(data)
78
+ const d = parseData && parseData.DATA
79
+
80
+ if (!d) return
81
+
82
+ if (Object.keys(d).length) {
83
+ console.log(chalk.dim('\n----------------\n'))
84
+ console.log(chalk.dim('Received update:'))
85
+ console.log(Object.keys(d).join(', '))
86
+ if (verboseCode) console.log(chalk.dim(JSON.stringify(d, null, prettify ?? 2)))
87
+
88
+ if (distDir) {
89
+ if (fetchOpt) {
90
+ await fetchFromCli(options)
91
+ console.log(chalk.dim('\n----------------\n'))
92
+ return
93
+ }
94
+ } else {
95
+ updateDynamycFile(d, { framework, ...options })
96
+ }
97
+ }
98
+
99
+ if (d.components && convertOpt && framework) {
100
+ convertFromCli(d.components, {
101
+ ...options, framework
102
+ })
103
+ }
104
+ }, 1500),
105
+ onError: (err, socket) => {
106
+ console.log(chalk.bold.green('Error during connection'))
107
+ if (verbose) console.error(err)
108
+ else console.log(debugMsg)
109
+ },
110
+ ...options
111
+ })
112
+ })
113
+ })
package/package.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "create-smbls",
3
+ "version": "2.11.378"
4
+ }