@spark-ui/cli-utils 2.14.0-beta.6 → 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.
@@ -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', '.spark-ui.cjs')
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spark-ui/cli-utils",
3
- "version": "2.14.0-beta.6",
3
+ "version": "2.14.0-beta.8",
4
4
  "description": "Spark CLI utils",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,20 +1,50 @@
1
- /* eslint-disable no-console */
2
1
  import chalk from 'chalk'
3
2
 
4
3
  export class Logger {
5
- success(message) {
6
- console.log(chalk.green(message))
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
- error(message) {
10
- console.log(chalk.red(message))
39
+ info(...args) {
40
+ this.#log({ type: chalk.cyan, force: this.#force, verbose: this.verbose }, ...args)
11
41
  }
12
42
 
13
- info(message) {
14
- console.log(chalk.yellow(message))
43
+ success(...args) {
44
+ this.#log({ type: chalk.green, force: this.#force, verbose: this.verbose }, ...args)
15
45
  }
16
46
 
17
- warning(message) {
18
- console.log(chalk.green(message))
47
+ break() {
48
+ this.#log({ type: chalk.green, force: this.#force, verbose: this.verbose }, '')
19
49
  }
20
50
  }
@@ -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
- import { appendFileSync, existsSync, mkdirSync } from 'fs'
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 { Logger, scanDirectories } from './utils/index.mjs'
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(configFileRoute, { logger })
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.warn(
54
+ logger.warning(
54
55
  `âš ī¸ No files found with "${moduleName}" imports across directory ${directoryPath}.`
55
56
  )
56
57
  }
@@ -114,9 +115,9 @@ export async function adoption(options) {
114
115
  if (!existsSync(dir)) {
115
116
  mkdirSync(dir, { recursive: true })
116
117
  }
117
- appendFileSync(`${path.join(process.cwd(), output)}`, JSON.stringify(result, null, 2))
118
- } catch (err) {
119
- logger.error(`đŸ’Ĩ Error writing file: ${err}`)
118
+ writeFileSync(`${path.join(process.cwd(), output)}`, JSON.stringify(result, null, 2))
119
+ } catch (error) {
120
+ logger.error(`đŸ’Ĩ Error writing file: ${error}`)
120
121
  process.exit(1)
121
122
  }
122
123
  } else {
@@ -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(configFileRoute, { logger }) {
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
- logger.warn('âš ī¸ No custom configuration file found')
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
  }
@@ -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
- }