@toptal/davinci-code 2.0.8-alpha-CRT-5891-create-coverage-command-3e3ae146.46 → 2.0.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/CHANGELOG.md +12 -0
- package/package.json +8 -3
- package/src/commands/__snapshots__/component.test.mjs.snap +67 -0
- package/src/commands/__snapshots__/module.test.mjs.snap +55 -0
- package/src/commands/__snapshots__/stories.test.mjs.snap +54 -0
- package/src/commands/component.mjs +10 -26
- package/src/commands/component.test.mjs +24 -0
- package/src/commands/module.mjs +15 -23
- package/src/commands/module.test.mjs +24 -0
- package/src/commands/stories.mjs +8 -20
- package/src/commands/stories.test.mjs +24 -0
- package/src/index.mjs +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 2.0.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#2021](https://github.com/toptal/davinci/pull/2021) [`97abce92`](https://github.com/toptal/davinci/commit/97abce922d3a0720e0806ae9cd2f2866f355a1bc) Thanks [@dmaklygin](https://github.com/dmaklygin)!
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
- standardize command syntax for consistency
|
|
12
|
+
- Updated dependencies [[`97abce92`](https://github.com/toptal/davinci/commit/97abce922d3a0720e0806ae9cd2f2866f355a1bc)]:
|
|
13
|
+
- @toptal/davinci-cli-shared@2.3.1
|
|
14
|
+
|
|
3
15
|
## 2.0.7
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toptal/davinci-code",
|
|
3
|
-
"version": "2.0.8
|
|
3
|
+
"version": "2.0.8",
|
|
4
4
|
"description": "Code generation package for frontend applications",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
"bin": {
|
|
17
17
|
"davinci-code": "./bin/davinci-code.mjs"
|
|
18
18
|
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' yarn jest"
|
|
21
|
+
},
|
|
19
22
|
"main": "src/index.mjs",
|
|
20
23
|
"files": [
|
|
21
24
|
"src",
|
|
@@ -32,10 +35,12 @@
|
|
|
32
35
|
"url": "https://github.com/toptal/davinci/issues"
|
|
33
36
|
},
|
|
34
37
|
"dependencies": {
|
|
35
|
-
"@toptal/davinci-cli-shared": "2.3.1
|
|
38
|
+
"@toptal/davinci-cli-shared": "2.3.1",
|
|
36
39
|
"hygen": "^6.2.11",
|
|
37
40
|
"lodash.camelcase": "^4.3.0",
|
|
38
41
|
"lodash.kebabcase": "^4.1.1"
|
|
39
42
|
},
|
|
40
|
-
"
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@jest/globals": "^29.4.2"
|
|
45
|
+
}
|
|
41
46
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`createNewCommand creates a command with the correct parameters 1`] = `
|
|
4
|
+
"{
|
|
5
|
+
"_events": {},
|
|
6
|
+
"_eventsCount": 0,
|
|
7
|
+
"commands": [],
|
|
8
|
+
"options": [],
|
|
9
|
+
"parent": null,
|
|
10
|
+
"_allowUnknownOption": false,
|
|
11
|
+
"_allowExcessArguments": true,
|
|
12
|
+
"_args": [
|
|
13
|
+
{
|
|
14
|
+
"description": "Name of template: component, page etc.",
|
|
15
|
+
"variadic": false,
|
|
16
|
+
"required": true,
|
|
17
|
+
"_name": "templateName"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"description": "Name of a folder",
|
|
21
|
+
"variadic": false,
|
|
22
|
+
"required": true,
|
|
23
|
+
"_name": "name"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"description": "Module where a new folder will be created",
|
|
27
|
+
"variadic": false,
|
|
28
|
+
"defaultValue": "core",
|
|
29
|
+
"required": false,
|
|
30
|
+
"_name": "moduleName"
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
"args": [],
|
|
34
|
+
"rawArgs": [],
|
|
35
|
+
"processedArgs": [],
|
|
36
|
+
"_scriptPath": null,
|
|
37
|
+
"_name": "new",
|
|
38
|
+
"_optionValues": {},
|
|
39
|
+
"_optionValueSources": {},
|
|
40
|
+
"_storeOptionsAsProperties": false,
|
|
41
|
+
"_executableHandler": false,
|
|
42
|
+
"_executableFile": null,
|
|
43
|
+
"_executableDir": null,
|
|
44
|
+
"_defaultCommandName": null,
|
|
45
|
+
"_exitCallback": null,
|
|
46
|
+
"_aliases": [],
|
|
47
|
+
"_combineFlagAndOptionalValue": true,
|
|
48
|
+
"_description": "Generate a component",
|
|
49
|
+
"_summary": "",
|
|
50
|
+
"_enablePositionalOptions": false,
|
|
51
|
+
"_passThroughOptions": false,
|
|
52
|
+
"_lifeCycleHooks": {},
|
|
53
|
+
"_showHelpAfterError": false,
|
|
54
|
+
"_showSuggestionAfterError": true,
|
|
55
|
+
"_outputConfiguration": {},
|
|
56
|
+
"_hidden": false,
|
|
57
|
+
"_hasHelpOption": true,
|
|
58
|
+
"_helpFlags": "-h, --help",
|
|
59
|
+
"_helpDescription": "display help for command",
|
|
60
|
+
"_helpShortFlag": "-h",
|
|
61
|
+
"_helpLongFlag": "--help",
|
|
62
|
+
"_helpCommandName": "help",
|
|
63
|
+
"_helpCommandnameAndArgs": "help [command]",
|
|
64
|
+
"_helpCommandDescription": "display help for command",
|
|
65
|
+
"_helpConfiguration": {}
|
|
66
|
+
}"
|
|
67
|
+
`;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`createModuleCommand creates a command with the correct parameters 1`] = `
|
|
4
|
+
"{
|
|
5
|
+
"_events": {},
|
|
6
|
+
"_eventsCount": 0,
|
|
7
|
+
"commands": [],
|
|
8
|
+
"options": [],
|
|
9
|
+
"parent": null,
|
|
10
|
+
"_allowUnknownOption": false,
|
|
11
|
+
"_allowExcessArguments": true,
|
|
12
|
+
"_args": [
|
|
13
|
+
{
|
|
14
|
+
"description": "Module name",
|
|
15
|
+
"variadic": false,
|
|
16
|
+
"defaultValue": "core",
|
|
17
|
+
"required": false,
|
|
18
|
+
"_name": "name"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"args": [],
|
|
22
|
+
"rawArgs": [],
|
|
23
|
+
"processedArgs": [],
|
|
24
|
+
"_scriptPath": null,
|
|
25
|
+
"_name": "module",
|
|
26
|
+
"_optionValues": {},
|
|
27
|
+
"_optionValueSources": {},
|
|
28
|
+
"_storeOptionsAsProperties": false,
|
|
29
|
+
"_executableHandler": false,
|
|
30
|
+
"_executableFile": null,
|
|
31
|
+
"_executableDir": null,
|
|
32
|
+
"_defaultCommandName": null,
|
|
33
|
+
"_exitCallback": null,
|
|
34
|
+
"_aliases": [],
|
|
35
|
+
"_combineFlagAndOptionalValue": true,
|
|
36
|
+
"_description": "Generate a module",
|
|
37
|
+
"_summary": "",
|
|
38
|
+
"_enablePositionalOptions": false,
|
|
39
|
+
"_passThroughOptions": false,
|
|
40
|
+
"_lifeCycleHooks": {},
|
|
41
|
+
"_showHelpAfterError": false,
|
|
42
|
+
"_showSuggestionAfterError": true,
|
|
43
|
+
"_outputConfiguration": {},
|
|
44
|
+
"_hidden": false,
|
|
45
|
+
"_hasHelpOption": true,
|
|
46
|
+
"_helpFlags": "-h, --help",
|
|
47
|
+
"_helpDescription": "display help for command",
|
|
48
|
+
"_helpShortFlag": "-h",
|
|
49
|
+
"_helpLongFlag": "--help",
|
|
50
|
+
"_helpCommandName": "help",
|
|
51
|
+
"_helpCommandnameAndArgs": "help [command]",
|
|
52
|
+
"_helpCommandDescription": "display help for command",
|
|
53
|
+
"_helpConfiguration": {}
|
|
54
|
+
}"
|
|
55
|
+
`;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`createStoriesCommand creates a command with the correct parameters 1`] = `
|
|
4
|
+
"{
|
|
5
|
+
"_events": {},
|
|
6
|
+
"_eventsCount": 0,
|
|
7
|
+
"commands": [],
|
|
8
|
+
"options": [],
|
|
9
|
+
"parent": null,
|
|
10
|
+
"_allowUnknownOption": false,
|
|
11
|
+
"_allowExcessArguments": true,
|
|
12
|
+
"_args": [
|
|
13
|
+
{
|
|
14
|
+
"description": "Pathname to component directory",
|
|
15
|
+
"variadic": false,
|
|
16
|
+
"required": true,
|
|
17
|
+
"_name": "componentDirectory"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"args": [],
|
|
21
|
+
"rawArgs": [],
|
|
22
|
+
"processedArgs": [],
|
|
23
|
+
"_scriptPath": null,
|
|
24
|
+
"_name": "stories",
|
|
25
|
+
"_optionValues": {},
|
|
26
|
+
"_optionValueSources": {},
|
|
27
|
+
"_storeOptionsAsProperties": false,
|
|
28
|
+
"_executableHandler": false,
|
|
29
|
+
"_executableFile": null,
|
|
30
|
+
"_executableDir": null,
|
|
31
|
+
"_defaultCommandName": null,
|
|
32
|
+
"_exitCallback": null,
|
|
33
|
+
"_aliases": [],
|
|
34
|
+
"_combineFlagAndOptionalValue": true,
|
|
35
|
+
"_description": "Generate Storybook stories for the component",
|
|
36
|
+
"_summary": "",
|
|
37
|
+
"_enablePositionalOptions": false,
|
|
38
|
+
"_passThroughOptions": false,
|
|
39
|
+
"_lifeCycleHooks": {},
|
|
40
|
+
"_showHelpAfterError": false,
|
|
41
|
+
"_showSuggestionAfterError": true,
|
|
42
|
+
"_outputConfiguration": {},
|
|
43
|
+
"_hidden": false,
|
|
44
|
+
"_hasHelpOption": true,
|
|
45
|
+
"_helpFlags": "-h, --help",
|
|
46
|
+
"_helpDescription": "display help for command",
|
|
47
|
+
"_helpShortFlag": "-h",
|
|
48
|
+
"_helpLongFlag": "--help",
|
|
49
|
+
"_helpCommandName": "help",
|
|
50
|
+
"_helpCommandnameAndArgs": "help [command]",
|
|
51
|
+
"_helpCommandDescription": "display help for command",
|
|
52
|
+
"_helpConfiguration": {}
|
|
53
|
+
}"
|
|
54
|
+
`;
|
|
@@ -1,37 +1,21 @@
|
|
|
1
1
|
import kebabCase from 'lodash.kebabcase'
|
|
2
2
|
import camelCase from 'lodash.camelcase'
|
|
3
3
|
import { print, createArgument } from '@toptal/davinci-cli-shared'
|
|
4
|
-
|
|
5
4
|
import templates from '../templates.mjs'
|
|
6
5
|
import { CORE_MODULE } from '../constants.mjs'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
createArgument('<templateName>', 'Name of template: component, page etc.'),
|
|
13
|
-
createArgument('<name>', 'Name of a folder'),
|
|
14
|
-
createArgument('[moduleName]', 'Module where a new folder will be created').default(CORE_MODULE)
|
|
15
|
-
],
|
|
16
|
-
description: 'Generate a component',
|
|
17
|
-
action: (templateName, name, moduleName) => {
|
|
6
|
+
export const createNewCommand = (program) => {
|
|
7
|
+
return program
|
|
8
|
+
.createCommand("new", { isDefault: true })
|
|
9
|
+
.description('Generate a component')
|
|
10
|
+
.action((templateName, name, moduleName) => {
|
|
18
11
|
const componentName = camelCase(name)
|
|
19
12
|
const componentModuleName = kebabCase(moduleName)
|
|
20
13
|
const template = camelCase(templateName)
|
|
21
|
-
|
|
22
|
-
print.header(
|
|
23
|
-
'Creating new',
|
|
24
|
-
componentName,
|
|
25
|
-
'in the module',
|
|
26
|
-
componentModuleName,
|
|
27
|
-
'with template',
|
|
28
|
-
template
|
|
29
|
-
)
|
|
30
|
-
|
|
14
|
+
print.header('Creating new', componentName, 'in the module', componentModuleName, 'with template', template)
|
|
31
15
|
templates.generate(template, componentName, componentModuleName)
|
|
32
|
-
|
|
33
16
|
print.success('Done!')
|
|
34
|
-
}
|
|
17
|
+
})
|
|
18
|
+
.addArgument(createArgument('<templateName>', 'Name of template: component, page etc.'))
|
|
19
|
+
.addArgument(createArgument('<name>', 'Name of a folder'))
|
|
20
|
+
.addArgument(createArgument('[moduleName]', 'Module where a new folder will be created').default(CORE_MODULE))
|
|
35
21
|
}
|
|
36
|
-
|
|
37
|
-
export default componentCommandCreator
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
+
import { jest } from '@jest/globals'
|
|
3
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
4
|
+
import { Command } from 'commander'
|
|
5
|
+
|
|
6
|
+
const { createNewCommand } = await import('./component.mjs')
|
|
7
|
+
|
|
8
|
+
describe('createNewCommand', () => {
|
|
9
|
+
let program
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
program = new Command()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
jest.clearAllMocks()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('creates a command with the correct parameters', () => {
|
|
20
|
+
const command = createNewCommand(program)
|
|
21
|
+
|
|
22
|
+
expect(JSON.stringify(command, null, 2)).toMatchSnapshot()
|
|
23
|
+
})
|
|
24
|
+
})
|
package/src/commands/module.mjs
CHANGED
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
import kebabCase from 'lodash.kebabcase'
|
|
2
|
-
import { print } from '@toptal/davinci-cli-shared'
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
print.header('Creating new module:', moduleName)
|
|
17
|
-
|
|
18
|
-
templates.generateModule(moduleName)
|
|
19
|
-
|
|
20
|
-
print.success('Done!')
|
|
21
|
-
},
|
|
1
|
+
import kebabCase from 'lodash.kebabcase';
|
|
2
|
+
import { print, createArgument } from '@toptal/davinci-cli-shared';
|
|
3
|
+
import templates from '../templates.mjs';
|
|
4
|
+
import { CORE_MODULE } from '../constants.mjs';
|
|
5
|
+
export const createModuleCommand = (program) => {
|
|
6
|
+
return program
|
|
7
|
+
.createCommand("module")
|
|
8
|
+
.description('Generate a module')
|
|
9
|
+
.action(name => {
|
|
10
|
+
const moduleName = kebabCase(name);
|
|
11
|
+
print.header('Creating new module:', moduleName);
|
|
12
|
+
templates.generateModule(moduleName);
|
|
13
|
+
print.success('Done!');
|
|
14
|
+
})
|
|
15
|
+
.addArgument(createArgument('[name]', 'Module name').default(CORE_MODULE))
|
|
22
16
|
}
|
|
23
|
-
|
|
24
|
-
export default moduleCommandCreator
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
+
import { jest } from '@jest/globals'
|
|
3
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
4
|
+
import { Command } from 'commander'
|
|
5
|
+
|
|
6
|
+
const { createModuleCommand } = await import('./module.mjs')
|
|
7
|
+
|
|
8
|
+
describe('createModuleCommand', () => {
|
|
9
|
+
let program
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
program = new Command()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
jest.clearAllMocks()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('creates a command with the correct parameters', () => {
|
|
20
|
+
const command = createModuleCommand(program)
|
|
21
|
+
|
|
22
|
+
expect(JSON.stringify(command, null, 2)).toMatchSnapshot()
|
|
23
|
+
})
|
|
24
|
+
})
|
package/src/commands/stories.mjs
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
import { print } from '@toptal/davinci-cli-shared'
|
|
2
2
|
import fs from 'fs/promises'
|
|
3
|
-
|
|
4
3
|
import templates from '../templates.mjs'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
description
|
|
9
|
-
|
|
10
|
-
['<componentDirectory>', 'Pathname to component directory']
|
|
11
|
-
],
|
|
12
|
-
action: async (componentDirectory) => {
|
|
4
|
+
export function createStoriesCommand(program) {
|
|
5
|
+
return program
|
|
6
|
+
.createCommand("stories")
|
|
7
|
+
.description('Generate Storybook stories for the component')
|
|
8
|
+
.action(async componentDirectory => {
|
|
13
9
|
try {
|
|
14
10
|
const fileStat = await fs.stat(componentDirectory)
|
|
15
|
-
|
|
16
11
|
if (!fileStat.isDirectory()) {
|
|
17
12
|
throw Error('path is not a directory')
|
|
18
13
|
}
|
|
@@ -20,16 +15,9 @@ const storiesCommandCreator = {
|
|
|
20
15
|
print.red(`Path ${componentDirectory} is not a valid component directory`)
|
|
21
16
|
throw e
|
|
22
17
|
}
|
|
23
|
-
|
|
24
|
-
print.header(
|
|
25
|
-
'Creating new stories file for component at:',
|
|
26
|
-
componentDirectory
|
|
27
|
-
)
|
|
28
|
-
|
|
18
|
+
print.header('Creating new stories file for component at:', componentDirectory)
|
|
29
19
|
templates.generate('stories', componentDirectory)
|
|
30
|
-
|
|
31
20
|
print.success('Done!')
|
|
32
|
-
}
|
|
21
|
+
})
|
|
22
|
+
.argument('<componentDirectory>', 'Pathname to component directory')
|
|
33
23
|
}
|
|
34
|
-
|
|
35
|
-
export default storiesCommandCreator
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
+
import { jest } from '@jest/globals'
|
|
3
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
4
|
+
import { Command } from 'commander'
|
|
5
|
+
|
|
6
|
+
const { createStoriesCommand } = await import('./stories.mjs')
|
|
7
|
+
|
|
8
|
+
describe('createStoriesCommand', () => {
|
|
9
|
+
let program
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
program = new Command()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
jest.clearAllMocks()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('creates a command with the correct parameters', () => {
|
|
20
|
+
const command = createStoriesCommand(program)
|
|
21
|
+
|
|
22
|
+
expect(JSON.stringify(command, null, 2)).toMatchSnapshot()
|
|
23
|
+
})
|
|
24
|
+
})
|
package/src/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { createModuleCommand } from './commands/module.mjs'
|
|
2
|
+
import { createNewCommand } from './commands/component.mjs'
|
|
3
|
+
import { createStoriesCommand} from './commands/stories.mjs'
|
|
4
4
|
|
|
5
5
|
export const commands = [
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
createModuleCommand,
|
|
7
|
+
createStoriesCommand,
|
|
8
|
+
createNewCommand,
|
|
9
9
|
]
|
|
10
10
|
|
|
11
11
|
export default {
|
|
12
12
|
commands
|
|
13
|
-
}
|
|
13
|
+
}
|