@symbo.ls/cli 2.10.122 → 2.10.125

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.
Files changed (3) hide show
  1. package/bin/fetch.js +41 -27
  2. package/bin/sync.js +24 -3
  3. package/package.json +2 -2
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://raw.githubusercontent.com/symbo-ls/default-config/main/src/config.json'
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 (source, destination) => {
69
- const response = await fetch(DEFAULT_REMOTE_CONFIG_PATH)
70
- const body = await response.json()
71
- const { version, ...config } = body
72
-
73
- console.log(chalk.dim('- Default config from:'), chalk.dim.underline(DEFAULT_REMOTE_REPOSITORY))
74
- console.log('')
75
- console.log(chalk.bold('Symbols'), 'config fetched:', chalk.green(version))
76
-
77
- console.log(chalk.dim('- symbols.json created:'), chalk.dim.underline(LOCAL_CONFIG_PATH))
78
- console.log('')
79
-
80
- const bodyString = JSON.stringify(body)
81
- fs.writeFile(LOCAL_CONFIG_PATH, bodyString, err => {
82
- if (err) {
83
- console.log('Error writing file', err)
84
- } else {
85
- console.log('Successfully wrote file')
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
- for (const t in config) {
90
- const type = config[t]
91
- console.log(chalk.bold(t))
92
- for (const v in type) console.log(' ', chalk.dim(v))
93
- console.log(Object.keys(type))
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 = rc.key || options.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.122",
3
+ "version": "2.10.125",
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": "6d969a3ea842c89f518ca5c43636ddb06055e8ba"
30
+ "gitHead": "57e1d4f1ba73357d2452a833b28ccdb51f219b2a"
31
31
  }