diff --git a/package-lock.json b/package-lock.json index 1b3f1ac..e148245 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@coderoad/cli", - "version": "0.5.0", + "version": "0.6.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 7c8d6c2..3bef4cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@coderoad/cli", - "version": "0.5.1", + "version": "0.6.0", "description": "A CLI to build the configuration file for Coderoad Tutorials", "keywords": [ "coderoad", @@ -15,8 +15,9 @@ "url": "git+https://github.com/coderoad/coderoad-cli.git" }, "license": "SEE LICENSE IN LICENSE.md", - "author": "Argemiro Neto", + "author": "Shawn McKay", "contributors": [ + "Argemiro Neto", "Shawn McKay" ], "files": [ diff --git a/src/schema/meta.ts b/src/schema/meta.ts index 8a15a02..25b71d5 100644 --- a/src/schema/meta.ts +++ b/src/schema/meta.ts @@ -47,6 +47,25 @@ export default { type: "string", }, }, + vscode_command_array: { + type: "array", + description: + "An array of VSCode commands that can be called using the vscode commands API.", + items: { + anyOf: [ + { + type: "string", + description: "A VSCode command without params", + }, + { + type: "array", + description: "A VSCode command with params", + minLength: 2, + maxLength: 2, + }, + ], + }, + }, commit_array: { type: "array", description: @@ -105,6 +124,9 @@ export default { commands: { $ref: "#/definitions/command_array", }, + vscodeCommands: { + $ref: "#/definitions/vscode_command_array", + }, watchers: { type: "array", items: { diff --git a/src/schema/skeleton.ts b/src/schema/skeleton.ts index 6c04ee8..6d955bc 100644 --- a/src/schema/skeleton.ts +++ b/src/schema/skeleton.ts @@ -52,14 +52,25 @@ export default { description: "An optional folder for the test runner", examples: ["coderoad"], }, - setup: { - $ref: "#/definitions/setup_action_without_commits", - description: - "Setup actions or commands used for setting up the test runner on tutorial launch", - }, }, required: ["command", "args"], }, + setup: { + type: "object", + description: + "Setup commits or commands used for setting up the test runner on tutorial launch", + properties: { + commits: { + $ref: "#/definitions/commit_array", + }, + commands: { + $ref: "#/definitions/command_array", + }, + vscodeCommands: { + $ref: "#/definitions/vscode_command_array", + }, + }, + }, repo: { type: "object", description: "The repo holding the git commits for the tutorial", @@ -84,10 +95,11 @@ export default { type: "object", description: "Configuration options for resetting a tutorial", properties: { - command: { - type: "string", - description: "An optional command to run on reset", - examples: ["npm install"], + commands: { + $ref: "#/definitions/command_array", + }, + vscodeCommands: { + $ref: "#/definitions/vscode_command_array", }, }, additionalProperties: false, diff --git a/src/schema/tutorial.ts b/src/schema/tutorial.ts index 58711f9..915df70 100644 --- a/src/schema/tutorial.ts +++ b/src/schema/tutorial.ts @@ -71,14 +71,25 @@ export default { description: "An optional folder for the test runner", examples: ["coderoad"], }, - setup: { - $ref: "#/definitions/setup_action", - description: - "Setup commits or commands used for setting up the test runner on tutorial launch", - }, }, required: ["command", "args"], }, + setup: { + type: "object", + description: + "Setup commits or commands used for setting up the test runner on tutorial launch", + properties: { + commits: { + $ref: "#/definitions/commit_array", + }, + commands: { + $ref: "#/definitions/command_array", + }, + vscodeCommands: { + $ref: "#/definitions/vscode_command_array", + }, + }, + }, repo: { type: "object", description: "The repo holding the git commits for the tutorial", @@ -103,10 +114,11 @@ export default { type: "object", description: "Configuration options for resetting a tutorial", properties: { - command: { - type: "string", - description: "An optional command to run on reset", - examples: ["npm install"], + commands: { + $ref: "#/definitions/command_array", + }, + vscodeCommands: { + $ref: "#/definitions/vscode_command_array", }, }, additionalProperties: false, diff --git a/src/utils/parse.ts b/src/utils/parse.ts index c6e1a07..9d71442 100644 --- a/src/utils/parse.ts +++ b/src/utils/parse.ts @@ -153,8 +153,8 @@ export function parse(params: ParseParams): any { // add init commits if (params.commits.INIT && params.commits.INIT.length) { // @ts-ignore - parsed.config.testRunner.setup = { - ...(parsed.config?.testRunner?.setup || {}), + parsed.config.setup = { + ...(parsed.config?.setup || {}), commits: params.commits.INIT, }; } diff --git a/src/validate.ts b/src/validate.ts index f39a9d0..9413cf3 100644 --- a/src/validate.ts +++ b/src/validate.ts @@ -74,14 +74,10 @@ async function validate(args: string[]) { await cherryPick(commits.INIT); // run commands - if (skeleton.config?.testRunner?.setup?.commands) { + if (skeleton.config?.setup?.commands) { console.info("-- Running commands..."); - await runCommands( - skeleton.config?.testRunner?.setup?.commands, - // add optional setup directory - skeleton.config?.testRunner?.directory - ); + await runCommands(skeleton.config?.setup?.commands); } } diff --git a/tests/parse.test.ts b/tests/parse.test.ts index 7164c3f..ca2a8d5 100644 --- a/tests/parse.test.ts +++ b/tests/parse.test.ts @@ -987,9 +987,9 @@ Description. tap: "--reporter=mocha-tap-reporter", }, directory: "coderoad", - setup: { - commands: [], - }, + }, + setup: { + commands: [], }, appVersions: { vscode: ">=0.7.0", @@ -999,7 +999,7 @@ Description. branch: "aBranch", }, reset: { - command: "some command", + commands: ["some command"], }, dependencies: [ { @@ -1026,16 +1026,16 @@ Description. tap: "--reporter=mocha-tap-reporter", }, directory: "coderoad", - setup: { - commands: [], - }, + }, + setup: { + commands: [], }, repo: { uri: "https://path.to/repo", branch: "aBranch", }, reset: { - command: "some command", + commands: ["some command"], }, dependencies: [ { @@ -1101,9 +1101,9 @@ Description. tap: "--reporter=mocha-tap-reporter", }, directory: "coderoad", - setup: { - commits: ["abcdef1", "123456789"], - }, + }, + setup: { + commits: ["abcdef1", "123456789"], }, repo: { uri: "https://path.to/repo", diff --git a/tests/skeleton.test.ts b/tests/skeleton.test.ts index 57a5f3c..81fbfb6 100644 --- a/tests/skeleton.test.ts +++ b/tests/skeleton.test.ts @@ -8,15 +8,16 @@ const validJson = { config: { testRunner: { directory: "coderoad", - setup: { - commands: [], - }, + args: { filter: "--grep", tap: "--reporter=mocha-tap-reporter", }, command: "./node_modules/.bin/mocha", }, + setup: { + commands: [], + }, repo: { uri: "http://github.com/somePath/toRepo.git", branch: "codeBranch", diff --git a/tests/tutorial.test.ts b/tests/tutorial.test.ts index 60d97c1..3958267 100644 --- a/tests/tutorial.test.ts +++ b/tests/tutorial.test.ts @@ -13,10 +13,10 @@ const validJson: Partial = { tap: "tap", }, directory: "coderoad", - setup: { - commits: ["abcdef1"], - commands: ["npm install"], - }, + }, + setup: { + commits: ["abcdef1"], + commands: ["npm install"], }, repo: { uri: "https://github.com/some-repo.git", diff --git a/typings/tutorial.d.ts b/typings/tutorial.d.ts index 6ee6e5c..43596ca 100644 --- a/typings/tutorial.d.ts +++ b/typings/tutorial.d.ts @@ -10,6 +10,7 @@ export type TutorialConfig = { repo: TutorialRepo; dependencies?: TutorialDependency[]; reset?: ConfigReset; + setup?: StepActions; }; /** Logical groupings of tasks */ @@ -69,7 +70,6 @@ export interface TestRunnerConfig { command: string; args: TestRunnerArgs; directory?: string; - setup?: StepActions; } export interface TutorialRepo {