@spark-ui/cli-utils 2.14.0-beta.7 â 2.14.0-beta.8
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/spark-scan.mjs +1 -1
- package/package.json +1 -1
- package/src/core/Logger.mjs +39 -9
- package/src/scan/index.mjs +9 -8
- package/src/scan/loadConfig.mjs +11 -3
- package/src/scan/utils/index.mjs +0 -1
- package/src/scan/utils/logger.mjs +0 -55
package/bin/spark-scan.mjs
CHANGED
|
@@ -8,7 +8,7 @@ const program = new Command()
|
|
|
8
8
|
program
|
|
9
9
|
.command('adoption')
|
|
10
10
|
.description('Scan @spark-ui adoption for .tsx files with given imports')
|
|
11
|
-
.option('-c, --configuration <config>', 'configuration file route'
|
|
11
|
+
.option('-c, --configuration <config>', 'configuration file route')
|
|
12
12
|
.option('-o, --output <output>', 'output file route')
|
|
13
13
|
.option('-v, --verbose', 'output log information', false)
|
|
14
14
|
.option('-d, --details', 'output information about each match', config.details)
|
package/package.json
CHANGED
package/src/core/Logger.mjs
CHANGED
|
@@ -1,20 +1,50 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
1
|
import chalk from 'chalk'
|
|
3
2
|
|
|
4
3
|
export class Logger {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
#force = false
|
|
5
|
+
|
|
6
|
+
constructor({ verbose }) {
|
|
7
|
+
this.verbose = verbose
|
|
8
|
+
|
|
9
|
+
if (typeof Logger.instance === 'object') {
|
|
10
|
+
return Logger.instance
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
Logger.instance = this
|
|
14
|
+
|
|
15
|
+
return this
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
#log({ type = v => v, force, verbose }, ...args) {
|
|
19
|
+
if (force || verbose) {
|
|
20
|
+
console.log(type(...args)) // eslint-disable-line no-console
|
|
21
|
+
}
|
|
22
|
+
this.#force = false
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
force() {
|
|
26
|
+
this.#force = true
|
|
27
|
+
|
|
28
|
+
return this
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
error(...args) {
|
|
32
|
+
this.#log({ type: chalk.red, force: this.#force, verbose: this.verbose }, ...args)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
warning(...args) {
|
|
36
|
+
this.#log({ type: chalk.yellow, force: this.#force, verbose: this.verbose }, ...args)
|
|
7
37
|
}
|
|
8
38
|
|
|
9
|
-
|
|
10
|
-
|
|
39
|
+
info(...args) {
|
|
40
|
+
this.#log({ type: chalk.cyan, force: this.#force, verbose: this.verbose }, ...args)
|
|
11
41
|
}
|
|
12
42
|
|
|
13
|
-
|
|
14
|
-
|
|
43
|
+
success(...args) {
|
|
44
|
+
this.#log({ type: chalk.green, force: this.#force, verbose: this.verbose }, ...args)
|
|
15
45
|
}
|
|
16
46
|
|
|
17
|
-
|
|
18
|
-
|
|
47
|
+
break() {
|
|
48
|
+
this.#log({ type: chalk.green, force: this.#force, verbose: this.verbose }, '')
|
|
19
49
|
}
|
|
20
50
|
}
|
package/src/scan/index.mjs
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
+
/* eslint-disable complexity */
|
|
2
|
+
/* eslint-disable max-lines-per-function */
|
|
1
3
|
import * as process from 'node:process'
|
|
2
4
|
|
|
3
5
|
import { existsSync, mkdirSync, writeFileSync } from 'fs'
|
|
4
6
|
import merge from 'lodash.merge'
|
|
5
7
|
import path from 'path'
|
|
6
8
|
|
|
9
|
+
import { Logger } from '../core/index.mjs'
|
|
7
10
|
import * as defaultConfig from './config.mjs'
|
|
8
11
|
import { loadConfig } from './loadConfig.mjs'
|
|
9
12
|
import { scanCallback } from './scanCallback.mjs'
|
|
10
|
-
import {
|
|
13
|
+
import { scanDirectories } from './utils/index.mjs'
|
|
11
14
|
|
|
12
|
-
export async function adoption(options) {
|
|
15
|
+
export async function adoption(options = {}) {
|
|
13
16
|
const { configuration, ...optionsConfig } = options
|
|
14
|
-
const configFileRoute = path.join(process.cwd(), configuration || '.spark-ui.cjs')
|
|
15
17
|
|
|
16
18
|
const logger = new Logger({ verbose: optionsConfig.verbose })
|
|
17
|
-
let config = await loadConfig(
|
|
19
|
+
let config = await loadConfig(configuration, { logger })
|
|
18
20
|
|
|
19
21
|
config = {
|
|
20
22
|
adoption: merge(
|
|
@@ -26,7 +28,6 @@ export async function adoption(options) {
|
|
|
26
28
|
}
|
|
27
29
|
),
|
|
28
30
|
}
|
|
29
|
-
console.log(JSON.stringify(config, null, 2))
|
|
30
31
|
|
|
31
32
|
let importCount = 0
|
|
32
33
|
const importResults = {}
|
|
@@ -50,7 +51,7 @@ export async function adoption(options) {
|
|
|
50
51
|
`đ Found ${response.importCount - importCount} imports with "${moduleName}" modules across directory ${directoryPath}.`
|
|
51
52
|
)
|
|
52
53
|
} else {
|
|
53
|
-
logger.
|
|
54
|
+
logger.warning(
|
|
54
55
|
`â ī¸ No files found with "${moduleName}" imports across directory ${directoryPath}.`
|
|
55
56
|
)
|
|
56
57
|
}
|
|
@@ -115,8 +116,8 @@ export async function adoption(options) {
|
|
|
115
116
|
mkdirSync(dir, { recursive: true })
|
|
116
117
|
}
|
|
117
118
|
writeFileSync(`${path.join(process.cwd(), output)}`, JSON.stringify(result, null, 2))
|
|
118
|
-
} catch (
|
|
119
|
-
logger.error(`đĨ Error writing file: ${
|
|
119
|
+
} catch (error) {
|
|
120
|
+
logger.error(`đĨ Error writing file: ${error}`)
|
|
120
121
|
process.exit(1)
|
|
121
122
|
}
|
|
122
123
|
} else {
|
package/src/scan/loadConfig.mjs
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import process from 'node:process'
|
|
2
|
+
|
|
1
3
|
import { existsSync } from 'fs'
|
|
2
4
|
import merge from 'lodash.merge'
|
|
5
|
+
import path from 'path'
|
|
3
6
|
|
|
4
7
|
import * as defaultConfig from './config.mjs'
|
|
5
8
|
|
|
6
|
-
export async function loadConfig(
|
|
9
|
+
export async function loadConfig(configuration, { logger }) {
|
|
7
10
|
try {
|
|
11
|
+
const configFileRoute = path.join(process.cwd(), configuration || '.spark-ui.cjs')
|
|
8
12
|
if (existsSync(configFileRoute)) {
|
|
9
13
|
logger.info('âšī¸ Loading spark-ui custom configuration file')
|
|
10
14
|
const { default: customConfig } = await import(configFileRoute)
|
|
@@ -19,13 +23,17 @@ export async function loadConfig(configFileRoute, { logger }) {
|
|
|
19
23
|
|
|
20
24
|
return config
|
|
21
25
|
} else {
|
|
22
|
-
|
|
26
|
+
if (configuration) {
|
|
27
|
+
logger.error('â ī¸ No custom configuration file found:', configFileRoute)
|
|
28
|
+
process.exit(1)
|
|
29
|
+
}
|
|
30
|
+
logger.warning('â ī¸ No custom configuration file found')
|
|
23
31
|
logger.info('âšī¸ Loading default configuration')
|
|
24
32
|
|
|
25
33
|
return { ...defaultConfig }
|
|
26
34
|
}
|
|
27
35
|
} catch (error) {
|
|
28
|
-
logger.error('đĨ Something went wrong loading the custom configuration file')
|
|
36
|
+
logger.error('đĨ Something went wrong loading the custom configuration file', error)
|
|
29
37
|
|
|
30
38
|
return { ...defaultConfig }
|
|
31
39
|
}
|
package/src/scan/utils/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { extractImports } from './extract-imports.mjs'
|
|
2
2
|
export { fileContainsImport } from './file-contains-import.mjs'
|
|
3
3
|
export { getFormatedTimestamp } from './get-formated-timestamp.mjs'
|
|
4
|
-
export { Logger } from './logger.mjs'
|
|
5
4
|
export { scanDirectories } from './scan-directories.mjs'
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
2
|
-
|
|
3
|
-
export class Logger {
|
|
4
|
-
#force = false
|
|
5
|
-
|
|
6
|
-
constructor({ verbose }) {
|
|
7
|
-
this.verbose = verbose
|
|
8
|
-
|
|
9
|
-
if (typeof Logger.instance === 'object') {
|
|
10
|
-
return Logger.instance
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
Logger.instance = this
|
|
14
|
-
|
|
15
|
-
return this
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
#log({ type = v => v, force, verbose }, ...args) {
|
|
19
|
-
if (force || verbose) {
|
|
20
|
-
console.log(type(...args)) // eslint-disable-line no-console
|
|
21
|
-
}
|
|
22
|
-
this.#force = false
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
force() {
|
|
26
|
-
this.#force = true
|
|
27
|
-
|
|
28
|
-
return this
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
error(...args) {
|
|
32
|
-
this.#log({ type: chalk.red, force: this.#force, verbose: this.verbose }, ...args)
|
|
33
|
-
// this.verbose && console.log(chalk.red(...args))
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
warn(...args) {
|
|
37
|
-
this.#log({ type: chalk.yellow, force: this.#force, verbose: this.verbose }, ...args)
|
|
38
|
-
// this.verbose && console.log(chalk.yellow(...args))
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
info(...args) {
|
|
42
|
-
this.#log({ type: chalk.cyan, force: this.#force, verbose: this.verbose }, ...args)
|
|
43
|
-
// this.verbose && console.log(chalk.cyan(...args))
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
success(...args) {
|
|
47
|
-
this.#log({ type: chalk.green, force: this.#force, verbose: this.verbose }, ...args)
|
|
48
|
-
// this.verbose && console.log(chalk.green(...args))
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
break() {
|
|
52
|
-
this.#log({ type: chalk.green, force: this.#force, verbose: this.verbose }, '')
|
|
53
|
-
// this.verbose && console.log('')
|
|
54
|
-
}
|
|
55
|
-
}
|