textrun-workspace 0.1.0 → 0.2.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.
@@ -1,17 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.additionalFileContent = void 0;
4
- const color = require("colorette");
5
- const fs_1 = require("fs");
6
- const path = require("path");
7
- async function additionalFileContent(action) {
1
+ import * as color from "colorette";
2
+ import { promises as fs } from "fs";
3
+ import * as path from "path";
4
+ export async function additionalFileContent(action) {
8
5
  const fileName = action.region.textInNodeOfType("em", "strong");
9
6
  const fileRelPath = path.join(action.region[0].attributes["dir"] || ".", fileName);
10
7
  action.name(`append to file ${color.cyan(fileRelPath)}`);
11
8
  const content = action.region.textInNodeOfType("fence", "code");
12
9
  const fullPath = action.configuration.workspace.joinStr(fileRelPath);
13
10
  action.log(content);
14
- await fs_1.promises.appendFile(fullPath, content);
11
+ await fs.appendFile(fullPath, content);
15
12
  }
16
- exports.additionalFileContent = additionalFileContent;
17
13
  //# sourceMappingURL=additional-file-content.js.map
@@ -1,20 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.existingDirectory = void 0;
4
- const color = require("colorette");
5
- const fs_1 = require("fs");
6
- const path = require("path");
1
+ import * as color from "colorette";
2
+ import { promises as fs } from "fs";
3
+ import * as path from "path";
7
4
  /**
8
5
  * The "directory" action verifies that the test workspace
9
6
  * contains the given directory.
10
7
  */
11
- async function existingDirectory(action) {
8
+ export async function existingDirectory(action) {
12
9
  const dirName = action.region.text();
13
10
  const dirRelName = path.join(action.region[0].attributes["dir"] || ".", dirName);
14
11
  action.name(`directory ${color.cyan(dirRelName)} exists in the workspace`);
15
12
  const fullPath = action.configuration.workspace.joinStr(dirRelName);
16
13
  try {
17
- var stats = await fs_1.promises.lstat(fullPath);
14
+ var stats = await fs.lstat(fullPath);
18
15
  }
19
16
  catch (err) {
20
17
  throw new Error(`directory ${color.cyan(color.bold(dirRelName))} does not exist in the workspace`);
@@ -23,5 +20,4 @@ async function existingDirectory(action) {
23
20
  throw new Error(`${color.cyan(dirRelName)} exists but is not a directory`);
24
21
  }
25
22
  }
26
- exports.existingDirectory = existingDirectory;
27
23
  //# sourceMappingURL=existing-directory.js.map
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.existingFile = void 0;
4
- const assertNoDiff = require("assert-no-diff");
5
- const color = require("colorette");
6
- const fs_1 = require("fs");
7
- const path = require("path");
8
- const tr = require("text-runner-core");
9
- async function existingFile(action) {
1
+ import * as assertNoDiff from "assert-no-diff";
2
+ import * as color from "colorette";
3
+ import { promises as fs } from "fs";
4
+ import * as path from "path";
5
+ import * as textRunner from "text-runner-core";
6
+ export async function existingFile(action) {
10
7
  const fileName = action.region.textInNodeOfType("strong", "em");
11
8
  const fileRelPath = path.join(action.region[0].attributes["dir"] || ".", fileName);
12
9
  action.name(`verify content of file ${color.cyan(fileRelPath)}`);
@@ -14,12 +11,15 @@ async function existingFile(action) {
14
11
  const expectedContent = action.region.textInNodeOfType("fence", "code");
15
12
  action.log(expectedContent);
16
13
  try {
17
- var actualContent = await fs_1.promises.readFile(fullPath, "utf-8");
14
+ var actualContent = await fs.readFile(fullPath, "utf-8");
18
15
  }
19
16
  catch (e) {
17
+ if (!textRunner.isFsError(e)) {
18
+ throw e;
19
+ }
20
20
  if (e.code === "ENOENT") {
21
- const files = await fs_1.promises.readdir(action.configuration.sourceDir.platformified());
22
- throw new tr.UserError(`file not found: ${fileRelPath}`, `the workspace has these files: ${files.join(", ")}`);
21
+ const files = await fs.readdir(action.configuration.sourceDir.platformified());
22
+ throw new textRunner.UserError(`file not found: ${fileRelPath}`, `the workspace has these files: ${files.join(", ")}`);
23
23
  }
24
24
  else {
25
25
  throw e;
@@ -29,8 +29,7 @@ async function existingFile(action) {
29
29
  assertNoDiff.trimmedLines(actualContent.trim(), expectedContent.trim());
30
30
  }
31
31
  catch (err) {
32
- throw new tr.UserError(`mismatching content in ${color.cyan(color.bold(fileRelPath))}`, err.message);
32
+ throw new textRunner.UserError(`mismatching content in ${color.cyan(color.bold(fileRelPath))}`, textRunner.errorMessage(err));
33
33
  }
34
34
  }
35
- exports.existingFile = existingFile;
36
35
  //# sourceMappingURL=existing-file.js.map
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.newDirectory = void 0;
4
- const color = require("colorette");
5
- const fs = require("fs-extra");
6
- const path = require("path");
7
- async function newDirectory(action) {
1
+ import * as color from "colorette";
2
+ import { promises as fs } from "fs";
3
+ import * as path from "path";
4
+ export async function newDirectory(action) {
8
5
  const dirName = action.region.text().trim();
9
6
  if (!dirName) {
10
7
  throw new Error("empty directory name given");
@@ -12,7 +9,6 @@ async function newDirectory(action) {
12
9
  const dirRelName = path.join(action.region[0].attributes["dir"] || ".", dirName);
13
10
  action.name(`create directory ${color.cyan(dirRelName)}`);
14
11
  const fullPath = action.configuration.workspace.joinStr(dirRelName);
15
- await fs.ensureDir(fullPath);
12
+ await fs.mkdir(fullPath, { recursive: true });
16
13
  }
17
- exports.newDirectory = newDirectory;
18
14
  //# sourceMappingURL=new-directory.js.map
@@ -1,32 +1,34 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.newFile = void 0;
4
- const color = require("colorette");
5
- const fs = require("fs-extra");
6
- const path = require("path");
7
- const tr = require("text-runner-core");
8
- async function newFile(action) {
1
+ import * as color from "colorette";
2
+ import { promises as fs } from "fs";
3
+ import * as path from "path";
4
+ import * as textRunner from "text-runner-core";
5
+ export async function newFile(action) {
9
6
  var _a;
10
7
  try {
11
8
  var fileName = action.region.textInNodeOfType("em", "strong");
12
9
  }
13
10
  catch (e) {
11
+ if (!textRunner.isUserError(e)) {
12
+ throw e;
13
+ }
14
14
  const guidance = `Cannot determine the name of the file to create.\n${e.guidance}`;
15
- throw new tr.UserError(e.message, guidance);
15
+ throw new textRunner.UserError(e.message, guidance);
16
16
  }
17
17
  try {
18
18
  var content = action.region.textInNodeOfType("fence", "code");
19
19
  }
20
20
  catch (e) {
21
+ if (!textRunner.isUserError(e)) {
22
+ throw e;
23
+ }
21
24
  const guidance = `Cannot determine the content of the file to create.\n${e.guidance}`;
22
- throw new tr.UserError(e.message, guidance);
25
+ throw new textRunner.UserError(e.message, guidance);
23
26
  }
24
27
  const filePath = path.join((_a = action.region[0].attributes["dir"]) !== null && _a !== void 0 ? _a : ".", fileName);
25
28
  action.name(`create file ${color.cyan(filePath)}`);
26
29
  const fullPath = action.configuration.workspace.joinStr(filePath);
27
30
  action.log(`create file ${filePath}`);
28
- await fs.ensureDir(path.dirname(fullPath));
31
+ await fs.mkdir(path.dirname(fullPath), { recursive: true });
29
32
  await fs.writeFile(fullPath, content);
30
33
  }
31
- exports.newFile = newFile;
32
34
  //# sourceMappingURL=new-file.js.map
@@ -1,9 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.workingDir = void 0;
4
- const color = require("colorette");
1
+ import * as color from "colorette";
2
+ import * as textRunner from "text-runner-core";
5
3
  /** The "cd" action changes the current working directory to the one given in the hyperlink or code block. */
6
- function workingDir(action) {
4
+ export function workingDir(action) {
7
5
  const directory = action.region.text();
8
6
  action.name(`changing into the ${color.cyan(directory)} directory`);
9
7
  const fullPath = action.configuration.workspace.joinStr(directory);
@@ -12,11 +10,13 @@ function workingDir(action) {
12
10
  process.chdir(fullPath);
13
11
  }
14
12
  catch (e) {
13
+ if (!textRunner.isFsError(e)) {
14
+ throw e;
15
+ }
15
16
  if (e.code === "ENOENT") {
16
17
  throw new Error(`directory ${directory} not found`);
17
18
  }
18
19
  throw e;
19
20
  }
20
21
  }
21
- exports.workingDir = workingDir;
22
22
  //# sourceMappingURL=working-dir.js.map
package/dist/index.js CHANGED
@@ -1,18 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.textrunActions = void 0;
4
- const additional_file_content_1 = require("./actions/additional-file-content");
5
- const existing_directory_1 = require("./actions/existing-directory");
6
- const existing_file_1 = require("./actions/existing-file");
7
- const new_directory_1 = require("./actions/new-directory");
8
- const new_file_1 = require("./actions/new-file");
9
- const working_dir_1 = require("./actions/working-dir");
10
- exports.textrunActions = {
11
- additionalFileContent: additional_file_content_1.additionalFileContent,
12
- workingDir: working_dir_1.workingDir,
13
- newFile: new_file_1.newFile,
14
- existingDirectory: existing_directory_1.existingDirectory,
15
- existingFile: existing_file_1.existingFile,
16
- newDirectory: new_directory_1.newDirectory,
1
+ import { additionalFileContent } from "./actions/additional-file-content.js";
2
+ import { existingDirectory } from "./actions/existing-directory.js";
3
+ import { existingFile } from "./actions/existing-file.js";
4
+ import { newDirectory } from "./actions/new-directory.js";
5
+ import { newFile } from "./actions/new-file.js";
6
+ import { workingDir } from "./actions/working-dir.js";
7
+ export const textrunActions = {
8
+ additionalFileContent,
9
+ workingDir,
10
+ newFile,
11
+ existingDirectory,
12
+ existingFile,
13
+ newDirectory,
17
14
  };
18
15
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,24 +1,32 @@
1
1
  {
2
2
  "name": "textrun-workspace",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Text-Runner actions for the Text-Runner workspace",
5
- "main": "dist/index.js",
5
+ "license": "ISC",
6
+ "type": "module",
7
+ "exports": "./dist/index.js",
6
8
  "files": [
7
9
  "dist/**/*.js"
8
10
  ],
9
- "license": "ISC",
11
+ "scripts": {
12
+ "build": "tsc -p tsconfig-build.json",
13
+ "clean": "rm -rf dist",
14
+ "cuke": "cucumber-js --format=progress",
15
+ "doc": "text-run static --online --format=summary && text-run dynamic --format=progress",
16
+ "fix": "eslint . --fix --ext=.ts --ignore-path=../.eslintignore && prettier --write .",
17
+ "lint": "prettier -l . && eslint . --ext=.ts --ignore-path=../.eslintignore && depcheck"
18
+ },
10
19
  "dependencies": {
11
20
  "assert-no-diff": "3.0.6",
12
- "fs-extra": "9.1.0",
13
- "text-runner-core": "5.0.0"
21
+ "colorette": "2.0.19",
22
+ "text-runner-core": "6.0.0"
14
23
  },
15
24
  "devDependencies": {
16
- "colorette": "1.2.2",
17
- "cucumber": "6.0.5",
18
- "mocha": "8.3.0",
19
- "text-runner": "5.0.0",
20
- "textrun-action": "0.1.0",
21
- "textrun-extension": "0.1.0"
25
+ "shared-cucumber-steps": "*",
26
+ "text-runner": "6.0.0",
27
+ "textrun-action": "0.2.0",
28
+ "textrun-extension": "0.2.0",
29
+ "ts-node": "10.9.1"
22
30
  },
23
- "gitHead": "1196acaca38c929200160d352267f6e25b1df087"
31
+ "gitHead": "5434976346f2e02bc08c0a6ea9f7cbfa67d68c4e"
24
32
  }