@spark-ui/cli-utils 2.15.0 → 5.0.0

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/CHANGELOG.md CHANGED
@@ -3,6 +3,81 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # 5.0.0 (2024-07-18)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **cli-utils:** add some feedback when not loading a given config file ([1231fe6](https://github.com/adevinta/spark/commit/1231fe6cb94c15643a11278c3210836e81059364))
11
+ - **cli-utils:** cli command was failing ([719200e](https://github.com/adevinta/spark/commit/719200e62c210c7763950501553b9088187bd179))
12
+ - **cli-utils:** doc ([a9e50f2](https://github.com/adevinta/spark/commit/a9e50f203dfb4e3ba7c2f9b758c46eb923a222c6))
13
+ - **cli-utils:** fix binary file indicator ([02af669](https://github.com/adevinta/spark/commit/02af669d5f7a583ee36ba86902c182384460c346))
14
+ - **cli-utils:** fix config merge method to allow proper option override ([8b6a124](https://github.com/adevinta/spark/commit/8b6a124c6e70f05769305bf6ca84137c7a05510c))
15
+ - **cli-utils:** fix logger issue on generate script after changes ([083c9b0](https://github.com/adevinta/spark/commit/083c9b043d1837a807b159a8143fd16bf8d7087e))
16
+ - **cli-utils:** fix release ([e1c5ee0](https://github.com/adevinta/spark/commit/e1c5ee0923a2beaa8172be2c54c4cc4191ef13b7))
17
+ - **cli-utils:** fix tests ([91e7cd0](https://github.com/adevinta/spark/commit/91e7cd024e24b86738bd45180b812eac794df8e5))
18
+ - **cli-utils:** fix types ([4e4ee36](https://github.com/adevinta/spark/commit/4e4ee362b0af53c994c7b8c682d04c8160294854))
19
+ - **cli-utils:** improve log messages ([9623f94](https://github.com/adevinta/spark/commit/9623f9490cda5af0d00bbb10545e3769922cfc63))
20
+ - **cli-utils:** merge values ([a7e8129](https://github.com/adevinta/spark/commit/a7e81292d452d4ee026f3d4705198ac4ecc6363e))
21
+ - **cli-utils:** merging configs ([aeb6251](https://github.com/adevinta/spark/commit/aeb6251d23bc506674e4545ebad928081292f520))
22
+ - **cli-utils:** meta-tags ([0574960](https://github.com/adevinta/spark/commit/05749604ae830653c04209baa46bd39e11b6d44d))
23
+ - **cli-utils:** missalignment on the default config values nesting ([79729f7](https://github.com/adevinta/spark/commit/79729f722f4ecf6f0c671e2c1c1d5929a87d98c9))
24
+ - **cli-utils:** missing export ([9c7b61e](https://github.com/adevinta/spark/commit/9c7b61ee1ac3da9dd8838bda20a9cc906b927bee))
25
+ - **cli-utils:** modify entry file extension ([6f2671f](https://github.com/adevinta/spark/commit/6f2671f43edfa6082a8d3b9d377c1a7cbb1c67dc))
26
+ - **cli-utils:** output file creates new content ([973ffa8](https://github.com/adevinta/spark/commit/973ffa85e6987dbd87a119e9253db57556a705d4))
27
+ - **cli-utils:** remove betta tagging ([96cafae](https://github.com/adevinta/spark/commit/96cafae45e4a4759ef9ff4a763963f26cb898cb6))
28
+ - **cli-utils:** remove extra logs ([f588649](https://github.com/adevinta/spark/commit/f588649eb299fc42ef9d6dbf8f8f4eebd0cfd6a9))
29
+ - **cli-utils:** remove unnecesary log ([614d834](https://github.com/adevinta/spark/commit/614d834d5d7a0f3084b3097e2dee5436b369fbb6))
30
+ - **cli-utils:** small tweaks ([e83ff63](https://github.com/adevinta/spark/commit/e83ff634a212163d2a102d091b66c2c810d90387))
31
+ - **cli-utils:** update component template ([2e939ca](https://github.com/adevinta/spark/commit/2e939caef61ce616ff046a9eb00d2e720452502e))
32
+ - fix errors after eslint update ([3dae947](https://github.com/adevinta/spark/commit/3dae947dc169d9db3c7252f54a6224ded335980e))
33
+ - force new release to all packages ([d7f5136](https://github.com/adevinta/spark/commit/d7f513698cf48dd9c102fafaeb336096818c6b2b))
34
+ - **internal-utils:** missed dependency ([67b5a6b](https://github.com/adevinta/spark/commit/67b5a6b8ebe959686c611d0cf64efe1532b31422))
35
+ - log config setted ([190a058](https://github.com/adevinta/spark/commit/190a0581ab6219591c5d3a3ecde2ee46d504d7ca))
36
+ - priority of commands ([ed178a5](https://github.com/adevinta/spark/commit/ed178a51a8cea0255c96467b0d8760daf8f851dd))
37
+ - update vite config for package-level external dependencies ([fa21c73](https://github.com/adevinta/spark/commit/fa21c73d8ea579a1c5059f48cabca7188696d32e)), closes [#503](https://github.com/adevinta/spark/issues/503)
38
+ - wrong chmod on new ci script ([7b47919](https://github.com/adevinta/spark/commit/7b479196b0fcf5be21f2f067fdcb63e1d77c3496))
39
+
40
+ ### Code Refactoring
41
+
42
+ - **cli-utils:** clean up code following PR feedbacks ([724c83e](https://github.com/adevinta/spark/commit/724c83e771307addeabd1fcea45b810d56f41e2f))
43
+
44
+ ### Features
45
+
46
+ - **accordion:** accordion component ([023c2f9](https://github.com/adevinta/spark/commit/023c2f94cd5af6dc6ed48d39fe8224e3c7373847))
47
+ - add peerDeps field inside templates ([66791cc](https://github.com/adevinta/spark/commit/66791cc8f0af3ce561c11561e01b41e256ece242))
48
+ - **cli-utils:** add cli command to generate new components ([4e79fa1](https://github.com/adevinta/spark/commit/4e79fa19c2e84f98ac8fd7f9b75ecfaab2ea8227))
49
+ - **cli-utils:** add hook and utils template ([e22d672](https://github.com/adevinta/spark/commit/e22d672e349909cc4bc8673312846d10d77e7ea5))
50
+ - **cli-utils:** add new "spark setup-theme" cli command ([5b51126](https://github.com/adevinta/spark/commit/5b51126206ba0440d78f6429dcba3a7dd2f3af81)), closes [#253](https://github.com/adevinta/spark/issues/253)
51
+ - **cli-utils:** add scan adoption script ([203e05e](https://github.com/adevinta/spark/commit/203e05e02285be18e5d0c6211f3ec04e4322837d))
52
+ - **cli-utils:** bump version ([0f5664e](https://github.com/adevinta/spark/commit/0f5664e4c12bba0c8c7115109cbbe0a94e5220c1))
53
+ - **cli-utils:** component package template updated to match agreements ([10e7159](https://github.com/adevinta/spark/commit/10e71594f604f946e94c6f776f559ca0d0212860)), closes [#465](https://github.com/adevinta/spark/issues/465)
54
+ - **cli-utils:** doc ([d9446aa](https://github.com/adevinta/spark/commit/d9446aa20a054496042ff828f2b99dbf3c8c964f))
55
+ - **cli-utils:** exoposes all configuration parameters as a build argument ([3e88a99](https://github.com/adevinta/spark/commit/3e88a998c05da026cd196b3dd54a2ad50506266c))
56
+ - **cli-utils:** fix some issues ([cd0cc3e](https://github.com/adevinta/spark/commit/cd0cc3e31100316c2b544cc6ef74994e1a124fa0))
57
+ - **cli-utils:** fix some typos in component generation template ([d819446](https://github.com/adevinta/spark/commit/d8194465db48473f201e3634e1a149f91b5bb400))
58
+ - **cli-utils:** fix typo ([afcaf10](https://github.com/adevinta/spark/commit/afcaf1088284a7c87e7fdc8d36331ea4ab7571c8))
59
+ - **cli-utils:** flattened cli args for theme config ([ccb13de](https://github.com/adevinta/spark/commit/ccb13de785f2d6d2f8893bdff83b032af6416a38))
60
+ - **cli-utils:** handle overlooked edge cases ([d5c1ae3](https://github.com/adevinta/spark/commit/d5c1ae3d1eb41aa7c7c8a265d63e74dd7c416531))
61
+ - **cli-utils:** implement support for various base font sizes in theme building process ([7734203](https://github.com/adevinta/spark/commit/7734203330a411ba9c6898c6c1b4a84f6c168537)), closes [#385](https://github.com/adevinta/spark/issues/385)
62
+ - **cli-utils:** optimize DS configuration for spark consumers ([8d18892](https://github.com/adevinta/spark/commit/8d188920cffc3d24f96b1d5a9398eb22149c1640))
63
+ - **cli-utils:** prompt system for spark generate command ([12aec9b](https://github.com/adevinta/spark/commit/12aec9bb2af9aacdf2337e0de92e97ea608db962)), closes [#237](https://github.com/adevinta/spark/issues/237) [#237](https://github.com/adevinta/spark/issues/237)
64
+ - **cli-utils:** remove deprecated spark-setup-themes cli package ([a2efa9c](https://github.com/adevinta/spark/commit/a2efa9c15b3ece4285043fd25858435f455f257d))
65
+ - **cli-utils:** trigger script from bin alias ([c81f054](https://github.com/adevinta/spark/commit/c81f054ef2fb004203da3e5b77c02e4a83e2c191))
66
+ - **cli-utils:** update cli setup-themes functions ([8723891](https://github.com/adevinta/spark/commit/8723891243a11a81176a3cdefe7fadf2951ce613))
67
+ - **cli-utils:** update code and files structure ([be32555](https://github.com/adevinta/spark/commit/be325553849c51667ca1dad24042b8305775212f))
68
+ - **cli-utils:** update setup-themes transformer functions ([5c9a305](https://github.com/adevinta/spark/commit/5c9a3056807758e3178f1ae183b7d5718f06f3b7))
69
+ - **cli-utils:** update toTailwindConfig mapper to handle edge cases ([2af919a](https://github.com/adevinta/spark/commit/2af919a3dd7bbab02d00cd9892c1e9a7971aec38))
70
+ - mixing parameters ([da1bf1d](https://github.com/adevinta/spark/commit/da1bf1d838df2c577755eb3c651cd0bba8d07203))
71
+
72
+ ### BREAKING CHANGES
73
+
74
+ - **cli-utils:** update the way the cli spark-setup-theme command works
75
+ - **cli-utils:** update the way the cli spark-setup-theme command works
76
+
77
+ ## [2.15.1](https://github.com/adevinta/spark/compare/@spark-ui/cli-utils@2.15.0...@spark-ui/cli-utils@2.15.1) (2024-07-03)
78
+
79
+ **Note:** Version bump only for package @spark-ui/cli-utils
80
+
6
81
  # [2.15.0](https://github.com/adevinta/spark/compare/@spark-ui/cli-utils@2.14.0...@spark-ui/cli-utils@2.15.0) (2024-07-03)
7
82
 
8
83
  ### Bug Fixes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spark-ui/cli-utils",
3
- "version": "2.15.0",
3
+ "version": "5.0.0",
4
4
  "description": "Spark CLI utils",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -45,5 +45,5 @@
45
45
  "devDependencies": {
46
46
  "@types/fs-extra": "11.0.4"
47
47
  },
48
- "gitHead": "8a312bf6a9f20c8dd0cc3cc10649359c4313a2a7"
48
+ "gitHead": "cda68c4d65aa3f6f1bd4c47c42e8e72aadb263fd"
49
49
  }
@@ -0,0 +1,37 @@
1
+ module.exports = {
2
+ adoption: {
3
+ /**
4
+ * Shows (or not) details about each package adoption
5
+ * @param {boolean}
6
+ * @default false
7
+ */
8
+ details: false,
9
+ /**
10
+ * Sorts packages list, based on count or alphabetical order
11
+ * @param {'count'|'alphabetical'}
12
+ * @default 'count'
13
+ */
14
+ sort: 'count',
15
+ /**
16
+ * Packages pattern to be scanned
17
+ * @params {string[]}
18
+ */
19
+ imports: ['@spark-ui'],
20
+ /**
21
+ * File extensions to be scanned
22
+ * @params {string[]}
23
+ */
24
+ extensions: ['.tsx', '.ts'],
25
+ /**
26
+ * Directory to be scanned
27
+ * @param {string}
28
+ * @default '.''
29
+ */
30
+ directory: '.',
31
+ /**
32
+ * Output file path to export the results
33
+ * @param {string}
34
+ */
35
+ output: null,
36
+ },
37
+ }
@@ -6,7 +6,7 @@ import { existsSync, mkdirSync, writeFileSync } from 'fs'
6
6
  import path from 'path'
7
7
 
8
8
  import { Logger } from '../core/index.mjs'
9
- import * as defaultConfig from './config.mjs'
9
+ import defaultConfig from './config.cjs'
10
10
  import { loadConfig } from './loadConfig.mjs'
11
11
  import { scanCallback } from './scanCallback.mjs'
12
12
  import { scanDirectories } from './utils/index.mjs'
@@ -0,0 +1,157 @@
1
+ import path from 'node:path'
2
+
3
+ import fse from 'fs-extra'
4
+ import { fileURLToPath } from 'url'
5
+ import { beforeEach, describe, expect, it } from 'vitest'
6
+
7
+ import cmd, { ENTER } from '../../test/utils/cmd'
8
+
9
+ const __dirname = fileURLToPath(import.meta.url)
10
+ const cliPath = path.join(__dirname, '../../../bin/spark.mjs')
11
+
12
+ const cliProcess = cmd.create(cliPath)
13
+
14
+ describe('CLI `spark scan`', () => {
15
+ const OUTPUT_FILE = 'report.json'
16
+
17
+ const EXT_CONFIG_FILE_PATH = 'packages/utils/cli/test/stubs/scanConfigWithCustomExtensions.js'
18
+ const SORT_CONFIG_FILE_PATH = 'packages/utils/cli/test/stubs/scanConfigWithCustomSorting.js'
19
+ const DETAILED_OUTPUT_CONFIG_FILE_PATH =
20
+ 'packages/utils/cli/test/stubs/scanConfigWithDetailedOutput.js'
21
+ const IMPORTS_CONFIG_FILE_PATH = 'packages/utils/cli/test/stubs/scanConfigWithCustomImports.js'
22
+
23
+ const adoptionCommand = async (args: string[] = []) => {
24
+ /**
25
+ * We define here some common options such as custom directory (for performance reasons).
26
+ */
27
+ return await cliProcess.execute(
28
+ ['scan', 'adoption', '-dir', './packages/components', ...args],
29
+ [ENTER]
30
+ )
31
+ }
32
+
33
+ beforeEach(() => {
34
+ if (fse.existsSync(OUTPUT_FILE)) fse.removeSync(OUTPUT_FILE)
35
+ })
36
+
37
+ afterAll(() => {
38
+ if (fse.existsSync(OUTPUT_FILE)) fse.removeSync(OUTPUT_FILE)
39
+ })
40
+
41
+ describe('Adoption (components adoption)', () => {
42
+ it('should execute command with default config', async () => {
43
+ const response = await adoptionCommand(['-v'])
44
+
45
+ expect(response).toMatch(/Loading default configuration/i)
46
+ expect(response).toMatch(/Scanning adoption for @spark-ui/i)
47
+
48
+ expect(response).toMatch(/Found/i)
49
+
50
+ /**
51
+ * With no output option the adoption report will be simply logged
52
+ */
53
+ expect(
54
+ response.filter(
55
+ (entry: string | Record<string, unknown>) =>
56
+ entry['@spark-ui/button' as keyof typeof entry]
57
+ )
58
+ ).toBeDefined()
59
+ })
60
+
61
+ describe('Results details with output', () => {
62
+ it('should output results with packages details from command option', async () => {
63
+ await adoptionCommand(['-d', '-o', OUTPUT_FILE])
64
+
65
+ expect(fse.pathExistsSync(OUTPUT_FILE)).toBe(true)
66
+
67
+ const outputContent = JSON.parse(fse.readFileSync(OUTPUT_FILE, 'utf-8'))
68
+
69
+ Object.keys(outputContent).forEach(outputItem => {
70
+ expect(Object.keys(outputContent[outputItem]).includes('results')).toBeTruthy()
71
+ })
72
+ })
73
+
74
+ it('should output results with packages details from configuration file', async () => {
75
+ await adoptionCommand(['-c', DETAILED_OUTPUT_CONFIG_FILE_PATH])
76
+
77
+ expect(fse.pathExistsSync(OUTPUT_FILE)).toBe(true)
78
+
79
+ const outputContent = JSON.parse(fse.readFileSync(OUTPUT_FILE, 'utf-8'))
80
+
81
+ Object.keys(outputContent).forEach(outputItem => {
82
+ expect(Object.keys(outputContent[outputItem]).includes('results')).toBeTruthy()
83
+ })
84
+ })
85
+ })
86
+
87
+ describe('Results sorting', () => {
88
+ it('should sort results alphabetically from command option', async () => {
89
+ const response = await adoptionCommand(['-v', '-s', 'alphabetical'])
90
+
91
+ expect(response).toMatch(/Loading default configuration/i)
92
+ expect(response).toMatch(/Scanning adoption for @spark-ui/i)
93
+
94
+ const pkgList = Object.keys(
95
+ response.filter((entry: string | Record<string, unknown>) => typeof entry !== 'string')[0]
96
+ )
97
+
98
+ const sparkInputIndex = pkgList.indexOf('@spark-ui/input')
99
+ const sparkFormFieldIndex = pkgList.indexOf('@spark-ui/form-field')
100
+
101
+ expect(sparkInputIndex).toBeGreaterThan(sparkFormFieldIndex)
102
+ })
103
+
104
+ it('should sort results alphabetically from configuration file', async () => {
105
+ const response = await adoptionCommand(['-v', '-c', SORT_CONFIG_FILE_PATH])
106
+
107
+ expect(response).toMatch(/Loading spark-ui custom configuration file/i)
108
+ expect(response).toMatch(/Scanning adoption for @spark-ui/i)
109
+
110
+ const pkgList = Object.keys(
111
+ response.filter((entry: string | Record<string, unknown>) => typeof entry !== 'string')[0]
112
+ )
113
+
114
+ const sparkInputIndex = pkgList.indexOf('@spark-ui/input')
115
+ const sparkFormFieldIndex = pkgList.indexOf('@spark-ui/form-field')
116
+
117
+ expect(sparkInputIndex).toBeGreaterThan(sparkFormFieldIndex)
118
+ })
119
+ })
120
+
121
+ describe('File extensions', () => {
122
+ it('should execute command with custom extensions from command option', async () => {
123
+ const response = await adoptionCommand(['-v', '-ext', '.css'])
124
+
125
+ expect(response).toMatch(/Loading default configuration/i)
126
+ expect(response).toMatch(/Scanning adoption for @spark-ui/i)
127
+
128
+ expect(response).toMatch(/No files found with "@spark-ui" imports across directory/i)
129
+ })
130
+
131
+ it('should execute command with custom extensions from configuration file', async () => {
132
+ const response = await adoptionCommand(['-v', '-c', EXT_CONFIG_FILE_PATH])
133
+
134
+ expect(response).toMatch(/Loading spark-ui custom configuration file/i)
135
+ expect(response).toMatch(/Scanning adoption for @spark-ui/i)
136
+
137
+ expect(response).toMatch(/No files found with "@spark-ui" imports across directory/i)
138
+ })
139
+ })
140
+
141
+ describe('Imports patterns', () => {
142
+ it('should execute command for custom import patterns from command option', async () => {
143
+ const response = await adoptionCommand(['-v', '-i', '@react-aria', '@react-stately'])
144
+
145
+ expect(response).toMatch(/Scanning adoption for @react-aria/i)
146
+ expect(response).toMatch(/Scanning adoption for @react-stately/i)
147
+ })
148
+
149
+ it('should execute command for custom import patterns from configuration file', async () => {
150
+ const response = await adoptionCommand(['-v', '-c', IMPORTS_CONFIG_FILE_PATH])
151
+
152
+ expect(response).toMatch(/Scanning adoption for @react-aria/i)
153
+ expect(response).toMatch(/Scanning adoption for @react-stately/i)
154
+ })
155
+ })
156
+ })
157
+ })
@@ -3,21 +3,22 @@ import process from 'node:process'
3
3
  import { existsSync } from 'fs'
4
4
  import path from 'path'
5
5
 
6
- import * as defaultConfig from './config.mjs'
6
+ import defaultConfig from './config.cjs'
7
7
 
8
8
  export async function loadConfig(configuration, { logger }) {
9
9
  try {
10
10
  const configFileRoute = path.join(process.cwd(), configuration || '.spark-ui.cjs')
11
+
11
12
  if (existsSync(configFileRoute)) {
12
13
  logger.info('ℹ️ Loading spark-ui custom configuration file')
13
14
  const { default: customConfig } = await import(configFileRoute)
14
15
 
15
16
  const config = {
16
17
  adoption: {
17
- ...defaultConfig,
18
+ ...defaultConfig.adoption,
18
19
  ...customConfig.adoption,
19
- imports: customConfig.adoption.imports || defaultConfig.imports,
20
- extensions: customConfig.adoption.extensions || defaultConfig.extensions,
20
+ imports: customConfig.adoption.imports || defaultConfig.adoption.imports,
21
+ extensions: customConfig.adoption.extensions || defaultConfig.adoption.extensions,
21
22
  },
22
23
  }
23
24
 
@@ -45,7 +45,7 @@ describe('CLI `spark generate` (component package)', () => {
45
45
  '/src/Bar.stories.tsx',
46
46
  '/tsconfig.json',
47
47
  ].forEach((filePath: string) => {
48
- expect(response).toContain(`Created ${packagePath}${filePath}`)
48
+ expect(response.toString()).toContain(`Created ${packagePath}${filePath}`)
49
49
  expect(fse.pathExistsSync(`${packagePath}${filePath}`)).toBe(true)
50
50
  })
51
51
  })
@@ -53,7 +53,7 @@ describe('CLI `spark generate` (component package)', () => {
53
53
  it('should prevent generating package when argument are invalid', async () => {
54
54
  const response = await cliProcess.execute(['generate'], ['123', ENTER])
55
55
 
56
- expect(response).toContain(
56
+ expect(response.toString()).toContain(
57
57
  'Name name must contain letters and dash symbols only (ex: "my-package")'
58
58
  )
59
59
 
@@ -0,0 +1,10 @@
1
+ export default {
2
+ adoption: {
3
+ details: false,
4
+ sort: 'count',
5
+ imports: ['@spark-ui'],
6
+ extensions: ['.css'],
7
+ directory: '.',
8
+ output: null,
9
+ },
10
+ }
@@ -0,0 +1,10 @@
1
+ export default {
2
+ adoption: {
3
+ details: false,
4
+ sort: 'count',
5
+ imports: ['@react-aria', '@react-stately'],
6
+ extensions: ['.tsx', '.ts'],
7
+ directory: '.',
8
+ output: null,
9
+ },
10
+ }
@@ -0,0 +1,10 @@
1
+ export default {
2
+ adoption: {
3
+ details: false,
4
+ sort: 'alphabetical',
5
+ imports: ['@spark-ui'],
6
+ extensions: ['.tsx', '.ts'],
7
+ directory: '.',
8
+ output: null,
9
+ },
10
+ }
@@ -0,0 +1,10 @@
1
+ export default {
2
+ adoption: {
3
+ details: true,
4
+ sort: 'count',
5
+ imports: ['@spark-ui'],
6
+ extensions: ['.tsx', '.ts'],
7
+ directory: '.',
8
+ output: 'report.json',
9
+ },
10
+ }
package/test/utils/cmd.js CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-console */
1
2
  /**
2
3
  * CLI Integration Test Helper
3
4
  * @author Andrés Zorro <zorrodg@gmail.com>
@@ -11,11 +12,30 @@ import { constants } from 'os'
11
12
 
12
13
  const PATH = process.env.PATH
13
14
 
15
+ /**
16
+ * Format CMD response as a JSON object
17
+ */
18
+ function getReportFromData(data) {
19
+ const regex = /({[\s\S]*})/ // Regular expression to match object type
20
+ const match = data.match(regex)
21
+
22
+ const messages = data
23
+ .slice(0, match?.index ?? undefined)
24
+ .trim()
25
+ .split('\n')
26
+ .map(line => line.trim())
27
+ .filter(line => line)
28
+
29
+ const json = match ? JSON.parse(match[0]) : undefined
30
+
31
+ return [...messages, json]
32
+ }
33
+
14
34
  /**
15
35
  * Creates a child process with script path
16
- * @param processPath Path of the process to execute
17
- * @param args Arguments to the command
18
- * @param env (optional) Environment variables
36
+ * @param {string} processPath Path of the process to execute
37
+ * @param {Array} args Arguments to the command
38
+ * @param {Object} env (optional) Environment variables
19
39
  */
20
40
  function createProcess(processPath, args = [], env = null) {
21
41
  // Ensure that path exists
@@ -44,18 +64,18 @@ function createProcess(processPath, args = [], env = null) {
44
64
  * Creates a command and executes inputs (user responses) to the stdin
45
65
  * Returns a promise that resolves when all inputs are sent
46
66
  * Rejects the promise if any error
47
- * @param processPath Path of the process to execute
48
- * @param args Arguments to the command
49
- * @param inputs (Optional) Array of inputs (user responses)
50
- * @param opts (optional) Environment variables
67
+ * @param {string} processPath Path of the process to execute
68
+ * @param {Array} args Arguments to the command
69
+ * @param {Array} inputs (Optional) Array of inputs (user responses)
70
+ * @param {Object} opts (optional) Environment variables
51
71
  */
52
- function executeWithInput(processPath, args, inputs, opts = {}) {
72
+ function executeWithInput(processPath, args = [], inputs = [], opts = {}) {
53
73
  if (!Array.isArray(inputs)) {
54
74
  opts = inputs
55
75
  inputs = []
56
76
  }
57
77
 
58
- const { env = null, timeout = 100, maxTimeout = 10000 } = opts
78
+ const { env = null, timeout = 250, maxTimeout = 10000 } = opts
59
79
  const childProcess = createProcess(processPath, args, env)
60
80
  childProcess.stdin.setEncoding('utf-8')
61
81
 
@@ -64,12 +84,12 @@ function executeWithInput(processPath, args, inputs, opts = {}) {
64
84
  // Creates a loop to feed user inputs to the child process in order to get results from the tool
65
85
  // This code is heavily inspired (if not blantantly copied) from inquirer-test:
66
86
  // https://github.com/ewnd9/inquirer-test/blob/6e2c40bbd39a061d3e52a8b1ee52cdac88f8d7f7/index.js#L14
67
- const loop = ins => {
87
+ const loop = inputs => {
68
88
  if (killIOTimeout) {
69
89
  clearTimeout(killIOTimeout)
70
90
  }
71
91
 
72
- if (!ins.length) {
92
+ if (!inputs.length) {
73
93
  childProcess.stdin.end()
74
94
 
75
95
  // Set a timeout to wait for CLI response. If CLI takes longer than
@@ -83,12 +103,12 @@ function executeWithInput(processPath, args, inputs, opts = {}) {
83
103
  }
84
104
 
85
105
  currentInputTimeout = setTimeout(() => {
86
- childProcess.stdin.write(ins[0])
106
+ childProcess.stdin.write(inputs[0])
87
107
  // Log debug I/O statements on tests
88
108
  if (env && env.DEBUG) {
89
- console.log('input:', ins[0]) // eslint-disable-line no-console
109
+ console.log('input:', inputs[0])
90
110
  }
91
- loop(ins.slice(1))
111
+ loop(inputs.slice(1))
92
112
  }, timeout)
93
113
  }
94
114
 
@@ -97,7 +117,7 @@ function executeWithInput(processPath, args, inputs, opts = {}) {
97
117
  childProcess.stderr.on('data', data => {
98
118
  // Log debug I/O statements on tests
99
119
  if (env && env.DEBUG) {
100
- console.log('error:', data.toString()) // eslint-disable-line no-console
120
+ console.log('error:', data.toString())
101
121
  }
102
122
  })
103
123
 
@@ -105,7 +125,7 @@ function executeWithInput(processPath, args, inputs, opts = {}) {
105
125
  childProcess.stdout.on('data', data => {
106
126
  // Log debug I/O statements on tests
107
127
  if (env && env.DEBUG) {
108
- console.log('output:', data.toString()) // eslint-disable-line no-console
128
+ console.log('output:', data.toString())
109
129
  }
110
130
  })
111
131
 
@@ -130,7 +150,7 @@ function executeWithInput(processPath, args, inputs, opts = {}) {
130
150
  clearTimeout(killIOTimeout)
131
151
  }
132
152
 
133
- resolve(result.toString())
153
+ resolve(getReportFromData(result.toString()))
134
154
  })
135
155
  )
136
156
  })
@@ -1,7 +0,0 @@
1
- export const details = false
2
- export const sort = 'count'
3
- export const imports = ['@spark-ui']
4
- export const extensions = ['.tsx', '.ts']
5
- export const directory = '.'
6
- export const verbose = false
7
- export const output = null