@neurodevs/ndx-cli 0.1.55 → 0.1.58
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/build/__tests__/AbstractCommandRunnerTest.d.ts +66 -0
- package/build/__tests__/AbstractCommandRunnerTest.js +264 -0
- package/build/__tests__/AbstractCommandRunnerTest.js.map +1 -0
- package/build/__tests__/modules/CliCommandRunner.test.d.ts +2 -94
- package/build/__tests__/modules/CliCommandRunner.test.js +2 -675
- package/build/__tests__/modules/CliCommandRunner.test.js.map +1 -1
- package/build/__tests__/modules/commands/BindSnippetCommand.test.d.ts +20 -0
- package/build/__tests__/modules/commands/BindSnippetCommand.test.js +111 -0
- package/build/__tests__/modules/commands/BindSnippetCommand.test.js.map +1 -0
- package/build/__tests__/modules/commands/CreateImplCommand.test.d.ts +13 -0
- package/build/__tests__/modules/commands/CreateImplCommand.test.js +112 -0
- package/build/__tests__/modules/commands/CreateImplCommand.test.js.map +1 -0
- package/build/__tests__/modules/commands/CreatePackageCommand.test.d.ts +10 -0
- package/build/__tests__/modules/commands/CreatePackageCommand.test.js +98 -0
- package/build/__tests__/modules/commands/CreatePackageCommand.test.js.map +1 -0
- package/build/__tests__/modules/commands/CreateUiCommand.test.d.ts +22 -0
- package/build/__tests__/modules/commands/CreateUiCommand.test.js +220 -0
- package/build/__tests__/modules/commands/CreateUiCommand.test.js.map +1 -0
- package/build/__tests__/modules/commands/UpgradePackageCommand.test.d.ts +11 -0
- package/build/__tests__/modules/commands/UpgradePackageCommand.test.js +90 -0
- package/build/__tests__/modules/commands/UpgradePackageCommand.test.js.map +1 -0
- package/build/modules/CliCommandRunner.d.ts +4 -2
- package/build/modules/CliCommandRunner.js +18 -7
- package/build/modules/CliCommandRunner.js.map +1 -1
- package/build/modules/commands/BindSnippetCommand.d.ts +16 -0
- package/build/modules/commands/BindSnippetCommand.js +67 -0
- package/build/modules/commands/BindSnippetCommand.js.map +1 -0
- package/build/scripts/runCommandRunner.js +1 -1
- package/build/scripts/runCommandRunner.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/AbstractCommandRunnerTest.ts +321 -0
- package/src/__tests__/modules/CliCommandRunner.test.ts +3 -910
- package/src/__tests__/modules/commands/BindSnippetCommand.test.ts +129 -0
- package/src/__tests__/modules/commands/CreateImplCommand.test.ts +137 -0
- package/src/__tests__/modules/commands/CreatePackageCommand.test.ts +113 -0
- package/src/__tests__/modules/commands/CreateUiCommand.test.ts +297 -0
- package/src/__tests__/modules/commands/UpgradePackageCommand.test.ts +105 -0
- package/src/modules/CliCommandRunner.ts +19 -7
- package/src/modules/commands/BindSnippetCommand.ts +75 -0
- package/src/scripts/runCommandRunner.ts +1 -1
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { test, generateId, assert } from '@sprucelabs/test-utils'
|
|
2
|
+
import { FakeAutopackage } from '@neurodevs/meta-node'
|
|
3
|
+
import AbstractCommandRunnerTest from '../../AbstractCommandRunnerTest'
|
|
4
|
+
|
|
5
|
+
export default class UpgradePackageCommandTest extends AbstractCommandRunnerTest {
|
|
6
|
+
protected static async beforeEach() {
|
|
7
|
+
await super.beforeEach()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@test()
|
|
11
|
+
protected static async createsInstance() {
|
|
12
|
+
const instance = await this.run()
|
|
13
|
+
|
|
14
|
+
assert.isTruthy(
|
|
15
|
+
instance,
|
|
16
|
+
`Failed to create instance for ${this.upgradePackageCommand}!`
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@test()
|
|
21
|
+
protected static async createsNpmAutopackage() {
|
|
22
|
+
await this.run()
|
|
23
|
+
|
|
24
|
+
assert.isEqualDeep(
|
|
25
|
+
FakeAutopackage.callsToConstructor[0],
|
|
26
|
+
{
|
|
27
|
+
...this.infoFromPackageJson,
|
|
28
|
+
name: `${this.packageName}`,
|
|
29
|
+
gitNamespace: 'neurodevs',
|
|
30
|
+
npmNamespace: 'neurodevs',
|
|
31
|
+
installDir: this.expandHomeDir('~/dev'),
|
|
32
|
+
license: 'MIT',
|
|
33
|
+
author: 'Eric Yates <hello@ericthecurious.com>',
|
|
34
|
+
},
|
|
35
|
+
'Did not create NpmAutopackage with expected options!'
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@test()
|
|
40
|
+
protected static async runsNpmAutopackage() {
|
|
41
|
+
await this.run()
|
|
42
|
+
|
|
43
|
+
assert.isEqual(
|
|
44
|
+
FakeAutopackage.numCallsToRun,
|
|
45
|
+
1,
|
|
46
|
+
'Did not call run on NpmAutopackage!'
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@test()
|
|
51
|
+
protected static async addsDefaultKeywordsIfMissing() {
|
|
52
|
+
await this.run({
|
|
53
|
+
name: this.packageName,
|
|
54
|
+
description: this.description,
|
|
55
|
+
keywords: [] as string[],
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
assert.isEqualDeep(
|
|
59
|
+
FakeAutopackage.callsToConstructor[0]?.keywords,
|
|
60
|
+
this.defaultKeywords,
|
|
61
|
+
'Did not add default keywords!'
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@test()
|
|
66
|
+
protected static async doesNotOverwriteKeywordsEvenIfDefaultsMissing() {
|
|
67
|
+
const keywords = [generateId(), generateId()]
|
|
68
|
+
|
|
69
|
+
await this.run({
|
|
70
|
+
name: this.packageName,
|
|
71
|
+
description: this.description,
|
|
72
|
+
keywords,
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
assert.isEqualDeep(
|
|
76
|
+
FakeAutopackage.callsToConstructor[0]?.keywords,
|
|
77
|
+
[...this.defaultKeywords, ...keywords],
|
|
78
|
+
'Should not have overwritten keywords!'
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@test()
|
|
83
|
+
protected static async extractsPackageNameFromScopedName() {
|
|
84
|
+
await this.run({
|
|
85
|
+
name: this.packageName,
|
|
86
|
+
description: this.description,
|
|
87
|
+
keywords: this.keywordsWithDefaults,
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
assert.isEqualDeep(
|
|
91
|
+
FakeAutopackage.callsToConstructor[0]?.name,
|
|
92
|
+
this.packageName,
|
|
93
|
+
'Did not extract package name from scoped name!'
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private static async run(responses?: Record<string, string | string[]>) {
|
|
98
|
+
this.setFakePackageJson(responses)
|
|
99
|
+
|
|
100
|
+
const instance = this.CliCommandRunner([this.upgradePackageCommand])
|
|
101
|
+
await instance.run()
|
|
102
|
+
|
|
103
|
+
return instance
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -2,6 +2,7 @@ import { exec as execSync } from 'child_process'
|
|
|
2
2
|
import { mkdir, readFile, writeFile } from 'fs/promises'
|
|
3
3
|
import { promisify } from 'util'
|
|
4
4
|
import prompts from 'prompts'
|
|
5
|
+
import BindSnippetCommand from './commands/BindSnippetCommand'
|
|
5
6
|
import CreateImplCommand from './commands/CreateImplCommand'
|
|
6
7
|
import CreatePackageCommand from './commands/CreatePackageCommand'
|
|
7
8
|
import CreateUiCommand from './commands/CreateUiCommand'
|
|
@@ -18,21 +19,23 @@ export default class CliCommandRunner implements CommandRunner {
|
|
|
18
19
|
|
|
19
20
|
private args: string[]
|
|
20
21
|
|
|
22
|
+
private readonly bindSnippetCommand = 'bind.snippet'
|
|
21
23
|
private readonly createImplCommand = 'create.impl'
|
|
22
24
|
private readonly createPackageCommand = 'create.package'
|
|
23
25
|
private readonly createUiCommand = 'create.ui'
|
|
24
26
|
private readonly helpCommand = 'help'
|
|
25
|
-
private readonly
|
|
26
|
-
private readonly
|
|
27
|
+
private readonly helpFlagShort = '-h'
|
|
28
|
+
private readonly helpFlagLong = '--help'
|
|
27
29
|
private readonly upgradePackageCommand = 'upgrade.package'
|
|
28
30
|
|
|
29
31
|
private readonly supportedCommands = [
|
|
32
|
+
this.bindSnippetCommand,
|
|
30
33
|
this.createImplCommand,
|
|
31
34
|
this.createPackageCommand,
|
|
32
35
|
this.createUiCommand,
|
|
33
36
|
this.helpCommand,
|
|
34
|
-
this.
|
|
35
|
-
this.
|
|
37
|
+
this.helpFlagShort,
|
|
38
|
+
this.helpFlagLong,
|
|
36
39
|
this.upgradePackageCommand,
|
|
37
40
|
]
|
|
38
41
|
|
|
@@ -65,6 +68,9 @@ export default class CliCommandRunner implements CommandRunner {
|
|
|
65
68
|
|
|
66
69
|
private async runCommand() {
|
|
67
70
|
switch (this.command) {
|
|
71
|
+
case this.bindSnippetCommand:
|
|
72
|
+
await this.bindSnippet()
|
|
73
|
+
break
|
|
68
74
|
case this.createImplCommand:
|
|
69
75
|
await this.createImplModule()
|
|
70
76
|
break
|
|
@@ -77,10 +83,10 @@ export default class CliCommandRunner implements CommandRunner {
|
|
|
77
83
|
case this.helpCommand:
|
|
78
84
|
await this.help()
|
|
79
85
|
break
|
|
80
|
-
case this.
|
|
86
|
+
case this.helpFlagLong:
|
|
81
87
|
await this.help()
|
|
82
88
|
break
|
|
83
|
-
case this.
|
|
89
|
+
case this.helpFlagShort:
|
|
84
90
|
await this.help()
|
|
85
91
|
break
|
|
86
92
|
case this.upgradePackageCommand:
|
|
@@ -89,6 +95,11 @@ export default class CliCommandRunner implements CommandRunner {
|
|
|
89
95
|
}
|
|
90
96
|
}
|
|
91
97
|
|
|
98
|
+
private async bindSnippet() {
|
|
99
|
+
const command = new BindSnippetCommand()
|
|
100
|
+
await command.run()
|
|
101
|
+
}
|
|
102
|
+
|
|
92
103
|
private async createImplModule() {
|
|
93
104
|
const command = new CreateImplCommand()
|
|
94
105
|
await command.run()
|
|
@@ -121,6 +132,7 @@ export default class CliCommandRunner implements CommandRunner {
|
|
|
121
132
|
|
|
122
133
|
Available commands:
|
|
123
134
|
|
|
135
|
+
- bind.snippet Bind a text snippet to a keyboard shortcut in vscode.
|
|
124
136
|
- create.impl Create implementation for interface with test and fake.
|
|
125
137
|
- create.package Create npm package using latest template.
|
|
126
138
|
- create.ui Create React component with test and fake.
|
|
@@ -129,7 +141,7 @@ export default class CliCommandRunner implements CommandRunner {
|
|
|
129
141
|
|
|
130
142
|
Usage:
|
|
131
143
|
|
|
132
|
-
- ndx <command>
|
|
144
|
+
- ndx <command>
|
|
133
145
|
`
|
|
134
146
|
}
|
|
135
147
|
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { VscodeSnippetKeybinder } from '@neurodevs/meta-node'
|
|
2
|
+
import CliCommandRunner from '../CliCommandRunner'
|
|
3
|
+
|
|
4
|
+
export default class BindSnippetCommand {
|
|
5
|
+
private name!: string
|
|
6
|
+
private description!: string
|
|
7
|
+
private lines!: string
|
|
8
|
+
private keybinding!: string
|
|
9
|
+
|
|
10
|
+
public constructor() {}
|
|
11
|
+
|
|
12
|
+
public async run() {
|
|
13
|
+
const { name, description, lines, keybinding } =
|
|
14
|
+
await this.promptUserForInput()
|
|
15
|
+
|
|
16
|
+
this.name = name
|
|
17
|
+
this.description = description
|
|
18
|
+
this.lines = lines
|
|
19
|
+
this.keybinding = keybinding
|
|
20
|
+
|
|
21
|
+
if (!this.hasAllUserInput) {
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const keybinder = this.VscodeSnippetKeybinder()
|
|
26
|
+
await keybinder.run()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private async promptUserForInput() {
|
|
30
|
+
return await this.prompts([
|
|
31
|
+
{
|
|
32
|
+
type: 'text',
|
|
33
|
+
name: 'name',
|
|
34
|
+
message: this.nameMessage,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
type: 'text',
|
|
38
|
+
name: 'description',
|
|
39
|
+
message: this.descriptionMessage,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
type: 'text',
|
|
43
|
+
name: 'lines',
|
|
44
|
+
message: this.snippetMessage,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: 'text',
|
|
48
|
+
name: 'keybinding',
|
|
49
|
+
message: this.keybindingMessage,
|
|
50
|
+
},
|
|
51
|
+
])
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private get hasAllUserInput() {
|
|
55
|
+
return this.name && this.description && this.lines && this.keybinding
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private readonly nameMessage = `Snippet name? Example: Singleton class template`
|
|
59
|
+
private readonly descriptionMessage = `Snippet description? Example: A class template based on the singleton pattern`
|
|
60
|
+
private readonly snippetMessage = `Snippet text content? Use \\n for newlines. Example: line-1\\nline-2`
|
|
61
|
+
private readonly keybindingMessage = `Snippet keybinding? Examples: ctrl+alt+c, f4`
|
|
62
|
+
|
|
63
|
+
private get prompts() {
|
|
64
|
+
return CliCommandRunner.prompts
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private VscodeSnippetKeybinder() {
|
|
68
|
+
return VscodeSnippetKeybinder.Create({
|
|
69
|
+
name: this.name,
|
|
70
|
+
description: this.description,
|
|
71
|
+
lines: this.lines.split('\\n'),
|
|
72
|
+
keybinding: this.keybinding,
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
}
|