@symbo.ls/cli 2.10.121 → 2.10.123
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 +50 -21
- package/bin/fetch.js +41 -27
- package/bin/sync.js +24 -3
- package/package.json +2 -2
package/bin/convert.js
CHANGED
|
@@ -14,6 +14,17 @@ global.document = window.document
|
|
|
14
14
|
|
|
15
15
|
const TMP_DIR_NAME = ".smbls_convert_tmp"
|
|
16
16
|
|
|
17
|
+
async function mkdirp(dir) {
|
|
18
|
+
try {
|
|
19
|
+
return await fs.promises.mkdir(dir)
|
|
20
|
+
} catch (err) {
|
|
21
|
+
if (err.code !== 'EEXIST') {
|
|
22
|
+
throw err
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return null
|
|
26
|
+
}
|
|
27
|
+
|
|
17
28
|
program
|
|
18
29
|
.command('convert')
|
|
19
30
|
.description('Recursively convert and copy all DomQL components under a directory')
|
|
@@ -36,18 +47,12 @@ program
|
|
|
36
47
|
|
|
37
48
|
// Resolve source & destination directories
|
|
38
49
|
const srcPath = path.resolve(src || './src')
|
|
39
|
-
const destPath = path.resolve(dest ||
|
|
50
|
+
const destPath = path.resolve(dest || desiredFormat)
|
|
40
51
|
const tmpDirPath = path.resolve(path.dirname(destPath), TMP_DIR_NAME)
|
|
41
52
|
|
|
42
|
-
// Make tmp
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
} catch (err) {
|
|
46
|
-
if (err.code !== 'EEXIST') {
|
|
47
|
-
console.log(err)
|
|
48
|
-
return 1;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
53
|
+
// Make tmp and dist directories
|
|
54
|
+
await mkdirp(tmpDirPath)
|
|
55
|
+
await mkdirp(destPath)
|
|
51
56
|
|
|
52
57
|
const origFiles = await fs.promises.readdir(srcPath)
|
|
53
58
|
|
|
@@ -62,24 +67,48 @@ program
|
|
|
62
67
|
})
|
|
63
68
|
|
|
64
69
|
// Convert components
|
|
65
|
-
const
|
|
66
|
-
for (const
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const importPath = `${filePath}/index.js`
|
|
70
|
+
const componentDirs = await fs.promises.readdir(tmpDirPath)
|
|
71
|
+
for (const componentDir of componentDirs) {
|
|
72
|
+
if (componentDir === 'Atoms') continue
|
|
73
|
+
let importDir = path.join(tmpDirPath, componentDir)
|
|
74
|
+
if ((await fs.promises.stat(importDir)).isDirectory()) {
|
|
75
|
+
// Import the module
|
|
76
|
+
const importPath = `${importDir}/index.js`
|
|
73
77
|
console.log(`importing ${importPath}`)
|
|
74
78
|
const domqlModule = (await import(importPath)).default
|
|
75
79
|
console.log(domqlModule)
|
|
80
|
+
|
|
81
|
+
// Create directory for component in dest dir
|
|
82
|
+
const destComponentDirPath = `${destPath}/${componentDir}`
|
|
83
|
+
await mkdirp(destComponentDirPath)
|
|
84
|
+
|
|
85
|
+
// Convert & append each exported domql object
|
|
86
|
+
const uniqueImports = []
|
|
87
|
+
let fileContents = ""
|
|
88
|
+
let first = true
|
|
76
89
|
for (const key in domqlModule) {
|
|
77
90
|
const component = domqlModule[key]
|
|
78
|
-
|
|
91
|
+
component.__name = key
|
|
92
|
+
const out = convert(component, desiredFormat, {
|
|
79
93
|
verbose: false,
|
|
80
|
-
exportDefault:
|
|
94
|
+
exportDefault: false,
|
|
95
|
+
returnMitosisIR: true,
|
|
96
|
+
importsToRemove: uniqueImports,
|
|
97
|
+
removeReactImport: !first
|
|
81
98
|
})
|
|
82
|
-
|
|
99
|
+
|
|
100
|
+
fileContents = fileContents + out.str + '\n'
|
|
101
|
+
uniqueImports.push(...out.mitosisIR.imports)
|
|
102
|
+
first = false
|
|
103
|
+
}
|
|
104
|
+
console.log(uniqueImports)
|
|
105
|
+
|
|
106
|
+
// Write file
|
|
107
|
+
if (fileContents.length > 0) {
|
|
108
|
+
const fh = await fs.promises
|
|
109
|
+
.open(`${destComponentDirPath}/index.js`, 'w')
|
|
110
|
+
await fh.writeFile(fileContents, 'utf8')
|
|
111
|
+
await fh.close()
|
|
83
112
|
}
|
|
84
113
|
}
|
|
85
114
|
}
|
package/bin/fetch.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import fs from 'fs'
|
|
4
|
-
import fetch from 'node-fetch'
|
|
5
4
|
import chalk from 'chalk'
|
|
6
5
|
import { loadModule } from './require.js'
|
|
7
6
|
import { exec } from 'child_process'
|
|
8
7
|
import { program } from './program.js'
|
|
9
8
|
|
|
9
|
+
import * as fetch from '@symbo.ls/fetch'
|
|
10
|
+
const { fetchRemote } = fetch
|
|
11
|
+
|
|
10
12
|
const PACKAGE_PATH = process.cwd() + '/package.json'
|
|
11
13
|
const RC_PATH = process.cwd() + '/symbols.json'
|
|
12
14
|
const LOCAL_CONFIG_PATH = process.cwd() + '/node_modules/@symbo.ls/init/dynamic.json'
|
|
13
15
|
const DEFAULT_REMOTE_REPOSITORY = 'https://github.com/symbo-ls/default-config/'
|
|
14
|
-
const DEFAULT_REMOTE_CONFIG_PATH = 'https://
|
|
16
|
+
const DEFAULT_REMOTE_CONFIG_PATH = 'https://api.symbols.dev/'
|
|
15
17
|
|
|
16
18
|
const API_URL = 'https://api.symbols.dev/' // eslint-disable-line
|
|
17
19
|
|
|
@@ -19,6 +21,11 @@ const pkg = loadModule(PACKAGE_PATH)
|
|
|
19
21
|
const rc_file = loadModule(RC_PATH) // eslint-disable-line
|
|
20
22
|
const local_config = loadModule(LOCAL_CONFIG_PATH) // eslint-disable-line
|
|
21
23
|
|
|
24
|
+
let rc = {}
|
|
25
|
+
try {
|
|
26
|
+
rc = loadModule(RC_PATH) // eslint-disable-line
|
|
27
|
+
} catch (e) { console.error('Please include symbols.json to your root of respository') }
|
|
28
|
+
|
|
22
29
|
program
|
|
23
30
|
.version(pkg.version)
|
|
24
31
|
|
|
@@ -65,31 +72,38 @@ program
|
|
|
65
72
|
program
|
|
66
73
|
.command('fetch [destination]')
|
|
67
74
|
.description('Fetch symbols')
|
|
68
|
-
.action(async (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
75
|
+
.action(async (options) => {
|
|
76
|
+
rc.then(async data => {
|
|
77
|
+
const opts = { ...data, ...options }
|
|
78
|
+
const key = data.key || options.key
|
|
79
|
+
|
|
80
|
+
const body = await fetchRemote(key, { endpoint: 'api.symbols.dev' })
|
|
81
|
+
const { version, ...config } = body
|
|
82
|
+
|
|
83
|
+
console.log(chalk.bold('Symbols'), 'config fetched:')
|
|
84
|
+
if (key) console.log(chalk.green(key))
|
|
85
|
+
else console.log(chalk.dim('- Default config from:'), chalk.dim.underline(DEFAULT_REMOTE_REPOSITORY))
|
|
86
|
+
console.log('')
|
|
87
|
+
|
|
88
|
+
console.log(chalk.dim('- symbols.json created:'), chalk.dim.underline(LOCAL_CONFIG_PATH))
|
|
89
|
+
console.log('')
|
|
90
|
+
|
|
91
|
+
for (const t in config) {
|
|
92
|
+
const type = config[t]
|
|
93
|
+
console.log(chalk.bold(t))
|
|
94
|
+
const arr = []
|
|
95
|
+
for (const v in type) arr.push(v)
|
|
96
|
+
console.log(' ', chalk.dim(arr.join(', ')))
|
|
86
97
|
}
|
|
87
|
-
})
|
|
88
98
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
99
|
+
const bodyString = JSON.stringify(body)
|
|
100
|
+
fs.writeFile(LOCAL_CONFIG_PATH, bodyString, err => {
|
|
101
|
+
console.log('')
|
|
102
|
+
if (err) {
|
|
103
|
+
console.log('Error writing file', err)
|
|
104
|
+
} else {
|
|
105
|
+
console.log('Successfully wrote file')
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
})
|
|
95
109
|
})
|
package/bin/sync.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import { updateDynamycFile } from '@symbo.ls/socket'
|
|
3
4
|
import * as asd from '@symbo.ls/socket/client.js'
|
|
4
5
|
import { program } from './program.js'
|
|
5
6
|
import { loadModule } from './require.js'
|
|
@@ -18,12 +19,32 @@ program
|
|
|
18
19
|
.action(async (options) => {
|
|
19
20
|
rc.then(data => {
|
|
20
21
|
const opts = { ...data, ...options }
|
|
21
|
-
const key =
|
|
22
|
+
const key = data.key || options.key
|
|
22
23
|
asd.connect(key, {
|
|
23
|
-
socketUrl: 'socket.symbols.app',
|
|
24
24
|
onConnect: (id, socket) => {
|
|
25
25
|
console.log(id)
|
|
26
|
-
}
|
|
26
|
+
},
|
|
27
|
+
onChange: (event, data) => {
|
|
28
|
+
data = JSON.parse(data)
|
|
29
|
+
let d = {}
|
|
30
|
+
const {
|
|
31
|
+
PROJECT_SYSTEM,
|
|
32
|
+
PROJECT_STATE,
|
|
33
|
+
PROJECT_COMPONENTS,
|
|
34
|
+
PROJECT_SNIPPETS,
|
|
35
|
+
PROJECT_PAGES
|
|
36
|
+
} = data
|
|
37
|
+
if (PROJECT_SYSTEM) d.system = PROJECT_SYSTEM
|
|
38
|
+
if (PROJECT_STATE) d.system = PROJECT_STATE
|
|
39
|
+
if (PROJECT_COMPONENTS) d.system = PROJECT_COMPONENTS
|
|
40
|
+
if (PROJECT_SNIPPETS) d.system = PROJECT_SNIPPETS
|
|
41
|
+
if (PROJECT_PAGES) d.system = PROJECT_PAGES
|
|
42
|
+
if (Object.keys(d).length) updateDynamycFile(d)
|
|
43
|
+
},
|
|
44
|
+
onError: (err, socket) => {
|
|
45
|
+
console.log(err)
|
|
46
|
+
},
|
|
47
|
+
...opts
|
|
27
48
|
})
|
|
28
49
|
})
|
|
29
50
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/cli",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.123",
|
|
4
4
|
"description": "Fetch your Symbols configuration",
|
|
5
5
|
"main": "bin/fetch.js",
|
|
6
6
|
"author": "Symbols",
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"standard": {
|
|
28
28
|
"parser": "babel-eslint"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "8e7c8dada6686b012c70e414cada2dd249790ab2"
|
|
31
31
|
}
|