@dittowords/cli 4.4.0 → 4.4.1
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/.github/actions/install-node-dependencies/action.yml +24 -0
- package/.github/workflows/required-checks.yml +24 -0
- package/.sentryclirc +3 -0
- package/__mocks__/fs.js +2 -0
- package/bin/__mocks__/api.js +48 -0
- package/bin/__mocks__/api.js.map +1 -0
- package/bin/config.test.js +4 -3
- package/bin/config.test.js.map +1 -1
- package/bin/consts.js +19 -29
- package/bin/consts.js.map +1 -1
- package/bin/generate-suggestions.js +68 -58
- package/bin/generate-suggestions.js.map +1 -1
- package/bin/generate-suggestions.test.js +24 -13
- package/bin/generate-suggestions.test.js.map +1 -1
- package/bin/http/__mocks__/fetchComponentFolders.js +71 -0
- package/bin/http/__mocks__/fetchComponentFolders.js.map +1 -0
- package/bin/http/__mocks__/fetchComponents.js +73 -0
- package/bin/http/__mocks__/fetchComponents.js.map +1 -0
- package/bin/http/__mocks__/fetchVariants.js +71 -0
- package/bin/http/__mocks__/fetchVariants.js.map +1 -0
- package/bin/http/fetchComponentFolders.js +4 -4
- package/bin/http/fetchComponentFolders.js.map +1 -1
- package/bin/http/fetchComponents.js +4 -4
- package/bin/http/fetchComponents.js.map +1 -1
- package/bin/http/fetchVariants.js +2 -2
- package/bin/http/fetchVariants.js.map +1 -1
- package/bin/http/http.test.js +159 -0
- package/bin/http/http.test.js.map +1 -0
- package/bin/http/importComponents.js +9 -2
- package/bin/http/importComponents.js.map +1 -1
- package/bin/init/project.test.js +5 -28
- package/bin/init/project.test.js.map +1 -1
- package/bin/init/token.js +72 -27
- package/bin/init/token.js.map +1 -1
- package/bin/init/token.test.js +87 -9
- package/bin/init/token.test.js.map +1 -1
- package/bin/pull-lib.test.js +379 -0
- package/bin/pull-lib.test.js.map +1 -0
- package/bin/pull.js +9 -2
- package/bin/pull.js.map +1 -1
- package/bin/pull.test.js +73 -290
- package/bin/pull.test.js.map +1 -1
- package/bin/replace.js +22 -6
- package/bin/replace.js.map +1 -1
- package/bin/replace.test.js +53 -11
- package/bin/replace.test.js.map +1 -1
- package/bin/utils/determineModuleType.js +6 -7
- package/bin/utils/determineModuleType.js.map +1 -1
- package/bin/utils/determineModuleType.test.js +60 -0
- package/bin/utils/determineModuleType.test.js.map +1 -0
- package/bin/utils/getSelectedProjects.js +5 -5
- package/bin/utils/getSelectedProjects.js.map +1 -1
- package/bin/utils/quit.js +3 -3
- package/bin/utils/quit.js.map +1 -1
- package/jest.config.ts +16 -0
- package/lib/__mocks__/api.ts +12 -0
- package/lib/config.test.ts +3 -1
- package/lib/consts.ts +19 -17
- package/lib/generate-suggestions.test.ts +23 -11
- package/lib/generate-suggestions.ts +89 -79
- package/lib/http/__mocks__/fetchComponentFolders.ts +23 -0
- package/lib/http/__mocks__/fetchComponents.ts +24 -0
- package/lib/http/__mocks__/fetchVariants.ts +21 -0
- package/lib/http/fetchComponentFolders.ts +6 -4
- package/lib/http/fetchComponents.ts +5 -3
- package/lib/http/fetchVariants.ts +14 -3
- package/lib/http/http.test.ts +122 -0
- package/lib/http/importComponents.ts +8 -0
- package/lib/init/project.test.ts +4 -27
- package/lib/init/token.test.ts +55 -7
- package/lib/init/token.ts +76 -27
- package/lib/pull-lib.test.ts +367 -0
- package/lib/pull.test.ts +63 -316
- package/lib/pull.ts +7 -1
- package/lib/replace.test.ts +46 -10
- package/lib/replace.ts +20 -3
- package/lib/utils/determineModuleType.test.ts +48 -0
- package/lib/utils/determineModuleType.ts +4 -6
- package/lib/utils/getSelectedProjects.ts +3 -3
- package/lib/utils/quit.ts +1 -1
- package/package.json +4 -3
- package/jest.config.js +0 -6
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: "Install Node Dependencies"
|
|
2
|
+
description: "Attempts to install Node.js dependencing leveraging yarn and caching"
|
|
3
|
+
|
|
4
|
+
inputs:
|
|
5
|
+
working-directory:
|
|
6
|
+
required: false
|
|
7
|
+
description: "The directory to run the install command in"
|
|
8
|
+
default: ./
|
|
9
|
+
|
|
10
|
+
runs:
|
|
11
|
+
using: "composite"
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/cache@v3
|
|
14
|
+
env:
|
|
15
|
+
cache-name: node_modules-cache
|
|
16
|
+
with:
|
|
17
|
+
path: ${{ inputs.working-directory }}node_modules
|
|
18
|
+
key: ${{ runner.os }}-build-${{ hashFiles('**/yarn.lock') }}
|
|
19
|
+
restore-keys: |
|
|
20
|
+
${{ runner.os }}-build
|
|
21
|
+
|
|
22
|
+
- name: Install new dependencies
|
|
23
|
+
shell: bash
|
|
24
|
+
run: cd ${{ inputs.working-directory }} && yarn install --prefer-offline --frozen-lockfile
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: "Required Checks"
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
jest-tests:
|
|
10
|
+
runs-on: ubuntu-20.04
|
|
11
|
+
timeout-minutes: 5
|
|
12
|
+
strategy:
|
|
13
|
+
fail-fast: false
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v3
|
|
16
|
+
- name: Use Node.js
|
|
17
|
+
uses: actions/setup-node@v3
|
|
18
|
+
with:
|
|
19
|
+
node-version: 20
|
|
20
|
+
- uses: ./.github/actions/install-node-dependencies
|
|
21
|
+
- name: Jest Tests
|
|
22
|
+
run: |
|
|
23
|
+
npx jest --ci --silent --maxWorkers=1
|
|
24
|
+
shell: bash
|
package/.sentryclirc
ADDED
package/__mocks__/fs.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="51c68d0d-369a-5afd-94e3-53c6ae77c043")}catch(e){}}();
|
|
3
|
+
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
|
+
var api_exports = {};
|
|
32
|
+
__export(api_exports, {
|
|
33
|
+
createApiClient: () => createApiClient
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(api_exports);
|
|
36
|
+
var import_axios = __toESM(require("axios"));
|
|
37
|
+
var import_globals = require("@jest/globals");
|
|
38
|
+
import_globals.jest.mock("axios");
|
|
39
|
+
function createApiClient(_token) {
|
|
40
|
+
return import_axios.default;
|
|
41
|
+
}
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
createApiClient
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=api.js.map
|
|
47
|
+
|
|
48
|
+
//# debugId=51c68d0d-369a-5afd-94e3-53c6ae77c043
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../lib/__mocks__/api.ts"],"sourcesContent":["import axios from \"axios\";\nimport { jest } from \"@jest/globals\";\n\njest.mock(\"axios\");\n\n// by returning the mocked module directly, we can mock responses in tests\n// like `axios.get.mockResolvedValue()`; otherwise, we'd be unable to mock\n// responses because `createApiClient` would be returning an axios instance\n// unaffected by mocks applied to the `axios` module itself.\nexport function createApiClient(_token?: string) {\n return axios;\n}\n"],"names":["axios"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAClB,qBAAqB;AAErB,oBAAK,KAAK,OAAO;AAMV,SAAS,gBAAgB,QAAiB;AAC/C,SAAO,aAAAA;AACT","debug_id":"51c68d0d-369a-5afd-94e3-53c6ae77c043"}
|
package/bin/config.test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="7a21b9a5-efe4-50f7-9b1f-38b0ce5ffb19")}catch(e){}}();
|
|
3
3
|
|
|
4
4
|
var __create = Object.create;
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
@@ -27,7 +27,8 @@ var import_fs = __toESM(require("fs"));
|
|
|
27
27
|
var import_path = __toESM(require("path"));
|
|
28
28
|
var import_js_yaml = __toESM(require("js-yaml"));
|
|
29
29
|
var import_config = __toESM(require("./config"));
|
|
30
|
-
|
|
30
|
+
jest.mock("fs");
|
|
31
|
+
const fakeHomedir = import_fs.default.mkdtempSync("/config-testing");
|
|
31
32
|
describe("Config File", () => {
|
|
32
33
|
const expectedConfigDir = import_path.default.join(fakeHomedir, ".config");
|
|
33
34
|
beforeEach(() => {
|
|
@@ -89,4 +90,4 @@ describe("Tokens in config files", () => {
|
|
|
89
90
|
});
|
|
90
91
|
//# sourceMappingURL=config.test.js.map
|
|
91
92
|
|
|
92
|
-
//# debugId=
|
|
93
|
+
//# debugId=7a21b9a5-efe4-50f7-9b1f-38b0ce5ffb19
|
package/bin/config.test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../lib/config.test.ts"],"sourcesContent":["/* eslint-disable no-underscore-dangle */\nimport fs from \"fs\";\nimport path from \"path\";\nimport tempy from \"tempy\";\nimport yaml from \"js-yaml\";\nimport config from \"./config\";\n\nconst fakeHomedir = fs.mkdtempSync(
|
|
1
|
+
{"version":3,"sources":["../lib/config.test.ts"],"sourcesContent":["/* eslint-disable no-underscore-dangle */\nimport fs from \"fs\";\nimport path from \"path\";\nimport tempy from \"tempy\";\nimport yaml from \"js-yaml\";\nimport config from \"./config\";\n\njest.mock(\"fs\");\n\nconst fakeHomedir = fs.mkdtempSync(\"/config-testing\");\n\ndescribe(\"Config File\", () => {\n const expectedConfigDir = path.join(fakeHomedir, \".config\");\n\n beforeEach(() => {\n if (!fs.existsSync(fakeHomedir)) fs.mkdirSync(fakeHomedir);\n });\n\n afterEach(() => {\n fs.rmdirSync(fakeHomedir, { recursive: true });\n });\n\n describe(\"createFileIfMissing\", () => {\n const expectedConfigFile = path.join(expectedConfigDir, \"ditto\");\n\n it(\"creates a config file if the config dir is missing\", () => {\n config.createFileIfMissing(expectedConfigFile);\n expect(fs.existsSync(expectedConfigFile)).toBeTruthy();\n });\n it(\"creates a config file if it's missing\", () => {\n fs.mkdirSync(expectedConfigDir);\n config.createFileIfMissing(expectedConfigFile);\n expect(fs.existsSync(expectedConfigFile)).toBeTruthy();\n });\n\n it(\"does nothing if it already exists\", () => {\n fs.mkdirSync(expectedConfigDir);\n fs.closeSync(fs.openSync(expectedConfigFile, \"w\"));\n config.createFileIfMissing(expectedConfigFile);\n expect(fs.existsSync(expectedConfigFile)).toBeTruthy();\n });\n });\n});\n\ndescribe(\"Tokens in config files\", () => {\n const configFile = path.join(fakeHomedir, \"ditto\");\n\n beforeEach(() => {\n config.createFileIfMissing(configFile);\n config.saveToken(configFile, \"testing.dittowords.com\", \"faketoken\");\n });\n\n afterEach(() => {\n fs.rmdirSync(fakeHomedir, { recursive: true });\n });\n\n describe(\"saveToken\", () => {\n it(\"creates a config file with config data\", () => {\n const fileContents = fs.readFileSync(configFile, \"utf8\");\n const configData = yaml.load(fileContents) as Record<string, any>;\n if (configData && typeof configData === \"object\") {\n expect(configData[\"testing.dittowords.com\"]).toBeDefined();\n expect(configData[\"testing.dittowords.com\"][0].token).toEqual(\n \"faketoken\"\n );\n } else {\n fail(\"Config Data should have been an object!\");\n }\n });\n });\n\n describe(\"getToken\", () => {\n it(\"can retrieve the saved token value\", () => {\n expect(config.getToken(configFile, \"testing.dittowords.com\")).toEqual(\n \"faketoken\"\n );\n });\n });\n});\n"],"names":["fs","path","config","yaml"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,gBAAe;AACf,kBAAiB;AAEjB,qBAAiB;AACjB,oBAAmB;AAEnB,KAAK,KAAK,IAAI;AAEd,MAAM,cAAc,UAAAA,QAAG,YAAY,iBAAiB;AAEpD,SAAS,eAAe,MAAM;AAC5B,QAAM,oBAAoB,YAAAC,QAAK,KAAK,aAAa,SAAS;AAE1D,aAAW,MAAM;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AM;AACvD,YAAM,aAAa,eAAAG,QAAK,KAAK,YAAY;AACzC,UAAI,cAAc,OAAO,eAAe,UAAU;AAChD,eAAO,WAAW,wBAAwB,CAAC,EAAE,YAAY;AACzD,eAAO,WAAW,wBAAwB,EAAE,CAAC,EAAE,KAAK,EAAE;AAAA,UACpD;AAAA,QACF;AAAA,MACF,OAAO;AACL,aAAK,yCAAyC;AAAA,MAChD;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAED,WAAS,YAAY,MAAM;AACzB,OAAG,sCAAsC,MAAM;AAC7C,aAAO,cAAAD,QAAO,SAAS,YAAY,wBAAwB,CAAC,EAAE;AAAA,QAC5D;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH,CAAC","debug_id":"7a21b9a5-efe4-50f7-9b1f-38b0ce5ffb19"}
|
package/bin/consts.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="dff8f642-ef0f-5ab4-bf87-60f6f51ca2b4")}catch(e){}}();
|
|
3
3
|
|
|
4
4
|
var __create = Object.create;
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
@@ -30,38 +30,28 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
31
|
var consts_exports = {};
|
|
32
32
|
__export(consts_exports, {
|
|
33
|
-
API_HOST: () => API_HOST,
|
|
34
|
-
CONFIG_FILE: () => CONFIG_FILE,
|
|
35
|
-
PROJECT_CONFIG_FILE: () => PROJECT_CONFIG_FILE,
|
|
36
|
-
TEXT_DIR: () => TEXT_DIR,
|
|
37
|
-
TEXT_FILE: () => TEXT_FILE,
|
|
38
33
|
default: () => consts_default
|
|
39
34
|
});
|
|
40
35
|
module.exports = __toCommonJS(consts_exports);
|
|
41
36
|
var import_os = require("os");
|
|
42
37
|
var import_path = __toESM(require("path"));
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
CONFIG_FILE,
|
|
61
|
-
PROJECT_CONFIG_FILE,
|
|
62
|
-
TEXT_DIR,
|
|
63
|
-
TEXT_FILE
|
|
64
|
-
});
|
|
38
|
+
var consts_default = new class {
|
|
39
|
+
get API_HOST() {
|
|
40
|
+
return process.env.DITTO_API_HOST || "https://api.dittowords.com";
|
|
41
|
+
}
|
|
42
|
+
get CONFIG_FILE() {
|
|
43
|
+
return process.env.DITTO_CONFIG_FILE || import_path.default.join((0, import_os.homedir)(), ".config", "ditto");
|
|
44
|
+
}
|
|
45
|
+
get PROJECT_CONFIG_FILE() {
|
|
46
|
+
return import_path.default.normalize(import_path.default.join("ditto", "config.yml"));
|
|
47
|
+
}
|
|
48
|
+
get TEXT_DIR() {
|
|
49
|
+
return process.env.DITTO_TEXT_DIR || "ditto";
|
|
50
|
+
}
|
|
51
|
+
get TEXT_FILE() {
|
|
52
|
+
return import_path.default.normalize(import_path.default.join(this.TEXT_DIR, "text.json"));
|
|
53
|
+
}
|
|
54
|
+
}();
|
|
65
55
|
//# sourceMappingURL=consts.js.map
|
|
66
56
|
|
|
67
|
-
//# debugId=
|
|
57
|
+
//# debugId=dff8f642-ef0f-5ab4-bf87-60f6f51ca2b4
|
package/bin/consts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../lib/consts.ts"],"sourcesContent":["import { homedir } from \"os\";\nimport path from \"path\";\n\nexport
|
|
1
|
+
{"version":3,"sources":["../lib/consts.ts"],"sourcesContent":["import { homedir } from \"os\";\nimport path from \"path\";\n\nexport default new (class {\n get API_HOST() {\n return process.env.DITTO_API_HOST || \"https://api.dittowords.com\";\n }\n get CONFIG_FILE() {\n return (\n process.env.DITTO_CONFIG_FILE || path.join(homedir(), \".config\", \"ditto\")\n );\n }\n get PROJECT_CONFIG_FILE() {\n return path.normalize(path.join(\"ditto\", \"config.yml\"));\n }\n get TEXT_DIR() {\n return process.env.DITTO_TEXT_DIR || \"ditto\";\n }\n get TEXT_FILE() {\n return path.normalize(path.join(this.TEXT_DIR, \"text.json\"));\n }\n})();\n"],"names":["path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAwB;AACxB,kBAAiB;AAEjB,IAAO,iBAAQ,IAAK,MAAM;AAAA,EACxB,IAAI,WAAW;AACb,WAAO,QAAQ,IAAI,kBAAkB;AAAA,EACvC;AAAA,EACA,IAAI,cAAc;AAChB,WACE,QAAQ,IAAI,qBAAqB,YAAAA,QAAK,SAAK,mBAAQ,GAAG,WAAW,OAAO;AAAA,EAE5E;AAAA,EACA,IAAI,sBAAsB;AACxB,WAAO,YAAAA,QAAK,UAAU,YAAAA,QAAK,KAAK,SAAS,YAAY,CAAC;AAAA,EACxD;AAAA,EACA,IAAI,WAAW;AACb,WAAO,QAAQ,IAAI,kBAAkB;AAAA,EACvC;AAAA,EACA,IAAI,YAAY;AACd,WAAO,YAAAA,QAAK,UAAU,YAAAA,QAAK,KAAK,KAAK,UAAU,WAAW,CAAC;AAAA,EAC7D;AACF,EAAG","debug_id":"dff8f642-ef0f-5ab4-bf87-60f6f51ca2b4"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="c9f5e9e0-d691-51c4-b6ad-7649590ad798")}catch(e){}}();
|
|
3
3
|
|
|
4
4
|
var __create = Object.create;
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
@@ -71,7 +71,7 @@ __export(generate_suggestions_exports, {
|
|
|
71
71
|
generateSuggestions: () => generateSuggestions
|
|
72
72
|
});
|
|
73
73
|
module.exports = __toCommonJS(generate_suggestions_exports);
|
|
74
|
-
var
|
|
74
|
+
var import_fs = __toESM(require("fs"));
|
|
75
75
|
var import_glob = __toESM(require("glob"));
|
|
76
76
|
var import_parser = require("@babel/parser");
|
|
77
77
|
var import_traverse = __toESM(require("@babel/traverse"));
|
|
@@ -95,66 +95,76 @@ function findComponentsInJSXFiles(params) {
|
|
|
95
95
|
ignore: "**/node_modules/**"
|
|
96
96
|
});
|
|
97
97
|
const promises = [];
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
98
|
+
function handleFile(file) {
|
|
99
|
+
return __async(this, null, function* () {
|
|
100
|
+
const code = yield new Promise(
|
|
101
|
+
(resolve, reject) => import_fs.default.readFile(file, "utf-8", (err, data) => {
|
|
102
|
+
if (err) {
|
|
103
|
+
reject(err);
|
|
104
|
+
} else {
|
|
105
|
+
resolve(data);
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
);
|
|
109
|
+
const ast = (0, import_parser.parse)(code, {
|
|
110
|
+
sourceType: "module",
|
|
111
|
+
plugins: ["jsx", "typescript"]
|
|
112
|
+
});
|
|
113
|
+
(0, import_traverse.default)(ast, {
|
|
114
|
+
JSXText(path) {
|
|
115
|
+
for (const [compApiId, component] of Object.entries(
|
|
116
|
+
params.components
|
|
117
|
+
)) {
|
|
118
|
+
if (!result[compApiId]) {
|
|
119
|
+
result[compApiId] = __spreadProps(__spreadValues({
|
|
120
|
+
apiId: compApiId
|
|
121
|
+
}, component), {
|
|
122
|
+
occurrences: {}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
if (
|
|
126
|
+
// Skip white space lines
|
|
127
|
+
!/^\s*$/.test(path.node.value) && !/^\s*$/.test(component.text) && path.node.value.includes(component.text)
|
|
128
|
+
) {
|
|
129
|
+
const escapedText = component.text.replace(
|
|
130
|
+
/[.*+?^${}()|[\]\\]/g,
|
|
131
|
+
"\\$&"
|
|
132
|
+
);
|
|
133
|
+
const regex = new RegExp(escapedText, "g");
|
|
134
|
+
let match;
|
|
135
|
+
while ((match = regex.exec(path.node.value)) !== null) {
|
|
136
|
+
const lines = path.node.value.slice(0, match.index).split("\n");
|
|
137
|
+
if (!path.node.loc) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const lineNumber = path.node.loc.start.line + lines.length - 1;
|
|
141
|
+
const codeLines = code.split("\n");
|
|
142
|
+
const line = codeLines[lineNumber - 1];
|
|
143
|
+
const preview = replaceAt(
|
|
144
|
+
line,
|
|
145
|
+
match.index,
|
|
146
|
+
component.text,
|
|
147
|
+
`${component.text}`
|
|
124
148
|
);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
while ((match = regex.exec(path.node.value)) !== null) {
|
|
128
|
-
const lines = path.node.value.slice(0, match.index).split("\n");
|
|
129
|
-
if (!path.node.loc) {
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
const lineNumber = path.node.loc.start.line + lines.length - 1;
|
|
133
|
-
const codeLines = code.split("\n");
|
|
134
|
-
const line = codeLines[lineNumber - 1];
|
|
135
|
-
const preview = replaceAt(
|
|
136
|
-
line,
|
|
137
|
-
match.index,
|
|
138
|
-
component.text,
|
|
139
|
-
`${component.text}`
|
|
140
|
-
);
|
|
141
|
-
if (!result[compApiId]["occurrences"][file]) {
|
|
142
|
-
result[compApiId]["occurrences"][file] = [];
|
|
143
|
-
}
|
|
144
|
-
result[compApiId]["occurrences"][file].push({
|
|
145
|
-
lineNumber,
|
|
146
|
-
preview
|
|
147
|
-
});
|
|
149
|
+
if (!result[compApiId]["occurrences"][file]) {
|
|
150
|
+
result[compApiId]["occurrences"][file] = [];
|
|
148
151
|
}
|
|
152
|
+
result[compApiId]["occurrences"][file].push({
|
|
153
|
+
lineNumber,
|
|
154
|
+
preview
|
|
155
|
+
});
|
|
149
156
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
157
|
+
}
|
|
158
|
+
if (Object.keys(result[compApiId]["occurrences"]).length === 0) {
|
|
159
|
+
delete result[compApiId];
|
|
153
160
|
}
|
|
154
161
|
}
|
|
155
|
-
}
|
|
156
|
-
})
|
|
157
|
-
);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
for (const file of files) {
|
|
167
|
+
promises.push(handleFile(file));
|
|
158
168
|
}
|
|
159
169
|
yield Promise.all(promises);
|
|
160
170
|
return result;
|
|
@@ -170,4 +180,4 @@ function replaceAt(str, index, searchString, replacement) {
|
|
|
170
180
|
});
|
|
171
181
|
//# sourceMappingURL=generate-suggestions.js.map
|
|
172
182
|
|
|
173
|
-
//# debugId=
|
|
183
|
+
//# debugId=c9f5e9e0-d691-51c4-b6ad-7649590ad798
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../lib/generate-suggestions.ts"],"sourcesContent":["import fs from \"fs
|
|
1
|
+
{"version":3,"sources":["../lib/generate-suggestions.ts"],"sourcesContent":["import fs from \"fs\";\nimport glob from \"glob\";\nimport { parse } from \"@babel/parser\";\nimport traverse from \"@babel/traverse\";\n\nimport {\n FetchComponentResponse,\n FetchComponentResponseComponent,\n fetchComponents,\n} from \"./http/fetchComponents\";\n\ninterface Occurrence {\n lineNumber: number;\n preview: string;\n}\n\ninterface Result extends FetchComponentResponseComponent {\n apiId: string;\n occurrences: {\n [file: string]: Occurrence[];\n };\n}\n\nasync function generateSuggestions(flags: {\n directory?: string;\n files?: string[];\n componentFolder?: string;\n}) {\n const components = await fetchComponents({\n ...(flags.componentFolder\n ? { componentFolder: flags.componentFolder }\n : {}),\n });\n const directory = flags.directory || \".\";\n\n const results: { [apiId: string]: Result } = await findComponentsInJSXFiles({\n directory,\n files: flags.files,\n components,\n });\n\n // Display results to user\n console.log(JSON.stringify(results, null, 2));\n}\n\nasync function findComponentsInJSXFiles(\n params: (\n | { directory: string; files?: string[] }\n | { files: string[]; directory?: string }\n ) & {\n components: FetchComponentResponse;\n }\n): Promise<{ [apiId: string]: Result }> {\n const result: { [apiId: string]: Result } = {};\n const files =\n params.files ||\n glob.sync(`${params.directory}/**/*.+(jsx|tsx)`, {\n ignore: \"**/node_modules/**\",\n });\n\n const promises: Promise<any>[] = [];\n\n async function handleFile(file: string) {\n const code = await new Promise<string>((resolve, reject) =>\n fs.readFile(file, \"utf-8\", (err, data) => {\n if (err) {\n reject(err);\n } else {\n resolve(data);\n }\n })\n );\n\n const ast = parse(code, {\n sourceType: \"module\",\n plugins: [\"jsx\", \"typescript\"],\n });\n\n traverse(ast, {\n JSXText(path) {\n for (const [compApiId, component] of Object.entries(\n params.components\n )) {\n // If we haven't seen this component before, add it to the result\n if (!result[compApiId]) {\n result[compApiId] = {\n apiId: compApiId,\n ...component,\n occurrences: {},\n };\n }\n\n if (\n // Skip white space lines\n !/^\\s*$/.test(path.node.value) &&\n !/^\\s*$/.test(component.text) &&\n path.node.value.includes(component.text)\n ) {\n // Escape all special characters from the text so we can use it in a regex\n const escapedText = component.text.replace(\n /[.*+?^${}()|[\\]\\\\]/g,\n \"\\\\$&\"\n );\n const regex = new RegExp(escapedText, \"g\");\n let match;\n while ((match = regex.exec(path.node.value)) !== null) {\n const lines = path.node.value.slice(0, match.index).split(\"\\n\");\n\n if (!path.node.loc) {\n continue;\n }\n\n const lineNumber = path.node.loc.start.line + lines.length - 1;\n\n const codeLines = code.split(\"\\n\");\n const line = codeLines[lineNumber - 1];\n const preview = replaceAt(\n line,\n match.index,\n component.text,\n `${component.text}`\n );\n\n // Initialize the occurrences array if it doesn't exist\n if (!result[compApiId][\"occurrences\"][file]) {\n result[compApiId][\"occurrences\"][file] = [];\n }\n\n result[compApiId][\"occurrences\"][file].push({\n lineNumber,\n preview,\n });\n }\n }\n\n // Remove from result if no occurrences were found\n if (Object.keys(result[compApiId][\"occurrences\"]).length === 0) {\n delete result[compApiId];\n }\n }\n },\n });\n }\n\n for (const file of files) {\n promises.push(handleFile(file));\n }\n\n await Promise.all(promises);\n\n return result;\n}\n\nfunction replaceAt(\n str: string,\n index: number,\n searchString: string,\n replacement: string\n) {\n return (\n str.substring(0, index) +\n str.substring(index, str.length).replace(searchString, replacement)\n );\n}\n\nexport { findComponentsInJSXFiles, generateSuggestions };\n"],"names":["glob","fs","traverse"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAe;AACf,kBAAiB;AACjB,oBAAsB;AACtB,sBAAqB;AAErB,6BAIO;AAcP,SAAe,oBAAoB,OAIhC;AAAA;AACD,UAAM,aAAa,UAAM,wCAAgB,mBACnC,MAAM,kBACN,EAAE,iBAAiB,MAAM,gBAAgB,IACzC,CAAC,EACN;AACD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id":"c9f5e9e0-d691-51c4-b6ad-7649590ad798"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="bd23df8e-2e66-5de9-8b6b-5a3ca81ea0a8")}catch(e){}}();
|
|
3
3
|
|
|
4
4
|
var __create = Object.create;
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
@@ -43,21 +43,34 @@ var __async = (__this, __arguments, generator) => {
|
|
|
43
43
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
44
44
|
});
|
|
45
45
|
};
|
|
46
|
-
var
|
|
46
|
+
var import_fs = __toESM(require("fs"));
|
|
47
47
|
var import_path = __toESM(require("path"));
|
|
48
48
|
var import_generate_suggestions = require("./generate-suggestions");
|
|
49
|
+
jest.mock("fs");
|
|
49
50
|
describe("findTextInJSXFiles", () => {
|
|
50
51
|
function createTempFile(filename, content) {
|
|
51
52
|
return __async(this, null, function* () {
|
|
52
|
-
const filePath = import_path.default.join("
|
|
53
|
-
yield
|
|
53
|
+
const filePath = import_path.default.join("/", filename);
|
|
54
|
+
yield new Promise((resolve, reject) => {
|
|
55
|
+
try {
|
|
56
|
+
import_fs.default.writeFile(filePath, content, () => resolve(null));
|
|
57
|
+
} catch (e) {
|
|
58
|
+
reject(e);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
54
61
|
return filePath;
|
|
55
62
|
});
|
|
56
63
|
}
|
|
57
64
|
function deleteTempFile(filename) {
|
|
58
65
|
return __async(this, null, function* () {
|
|
59
|
-
const filePath = import_path.default.join("
|
|
60
|
-
yield
|
|
66
|
+
const filePath = import_path.default.join("/", filename);
|
|
67
|
+
yield new Promise((resolve, reject) => {
|
|
68
|
+
try {
|
|
69
|
+
import_fs.default.unlink(filePath, resolve);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
reject(e);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
61
74
|
});
|
|
62
75
|
}
|
|
63
76
|
it("should return an empty obj when no files are found", () => __async(exports, null, function* () {
|
|
@@ -112,7 +125,7 @@ describe("findTextInJSXFiles", () => {
|
|
|
112
125
|
}
|
|
113
126
|
};
|
|
114
127
|
const result = yield (0, import_generate_suggestions.findComponentsInJSXFiles)({
|
|
115
|
-
directory: "
|
|
128
|
+
directory: "/",
|
|
116
129
|
components: {
|
|
117
130
|
"search-string": {
|
|
118
131
|
name: "Search String",
|
|
@@ -152,8 +165,7 @@ describe("findTextInJSXFiles", () => {
|
|
|
152
165
|
}
|
|
153
166
|
};
|
|
154
167
|
const result = yield (0, import_generate_suggestions.findComponentsInJSXFiles)({
|
|
155
|
-
|
|
156
|
-
files: ["file1.jsx"],
|
|
168
|
+
files: ["/file1.jsx"],
|
|
157
169
|
components: {
|
|
158
170
|
"search-string": {
|
|
159
171
|
name: "Search String",
|
|
@@ -165,9 +177,8 @@ describe("findTextInJSXFiles", () => {
|
|
|
165
177
|
});
|
|
166
178
|
expect(result).toEqual(expectedResult);
|
|
167
179
|
try {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
files: ["file2.jsx"],
|
|
180
|
+
yield (0, import_generate_suggestions.findComponentsInJSXFiles)({
|
|
181
|
+
files: ["/file2.jsx"],
|
|
171
182
|
components: {
|
|
172
183
|
"search-string": {
|
|
173
184
|
name: "Search String",
|
|
@@ -186,4 +197,4 @@ describe("findTextInJSXFiles", () => {
|
|
|
186
197
|
});
|
|
187
198
|
//# sourceMappingURL=generate-suggestions.test.js.map
|
|
188
199
|
|
|
189
|
-
//# debugId=
|
|
200
|
+
//# debugId=bd23df8e-2e66-5de9-8b6b-5a3ca81ea0a8
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../lib/generate-suggestions.test.ts"],"sourcesContent":["import fs from \"fs
|
|
1
|
+
{"version":3,"sources":["../lib/generate-suggestions.test.ts"],"sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\nimport { findComponentsInJSXFiles } from \"./generate-suggestions\";\n\njest.mock(\"fs\");\n\ndescribe(\"findTextInJSXFiles\", () => {\n async function createTempFile(filename: string, content: string) {\n const filePath = path.join(\"/\", filename);\n await new Promise((resolve, reject) => {\n try {\n fs.writeFile(filePath, content, () => resolve(null));\n } catch (e) {\n reject(e);\n }\n });\n return filePath;\n }\n\n async function deleteTempFile(filename: string) {\n const filePath = path.join(\"/\", filename);\n await new Promise((resolve, reject) => {\n try {\n fs.unlink(filePath, resolve);\n } catch (e) {\n reject(e);\n }\n });\n }\n\n it(\"should return an empty obj when no files are found\", async () => {\n const result = await findComponentsInJSXFiles({\n directory: \".\",\n components: {},\n });\n\n expect(result).toEqual({});\n });\n\n it(\"should return an empty obj when searchString is not found in any file\", async () => {\n const file1 = await createTempFile(\"file1.jsx\", \"<div>No match</div>\");\n const file2 = await createTempFile(\"file2.tsx\", \"<div>No match</div>\");\n\n const result = await findComponentsInJSXFiles({\n directory: \".\",\n components: {\n acomponent: {\n name: \"A Component\",\n text: \"A Component\",\n status: \"NONE\",\n folder: null,\n },\n },\n });\n\n expect(result).toEqual({});\n\n await deleteTempFile(file1);\n await deleteTempFile(file2);\n });\n\n it(\"should return an array with correct occurrences when searchString is found\", async () => {\n const file1 = await createTempFile(\n \"file1.jsx\",\n `<div>Test searchString and another searchString</div>`\n );\n\n const expectedResult = {\n \"search-string\": {\n apiId: \"search-string\",\n folder: null,\n name: \"Search String\",\n occurrences: {\n [file1]: [\n {\n lineNumber: 1,\n preview: \"<div>Test searchString and another searchString</div>\",\n },\n {\n lineNumber: 1,\n preview: \"<div>Test searchString and another searchString</div>\",\n },\n ],\n },\n status: \"NONE\",\n text: \"searchString\",\n },\n };\n\n const result = await findComponentsInJSXFiles({\n directory: \"/\",\n components: {\n \"search-string\": {\n name: \"Search String\",\n text: \"searchString\",\n status: \"NONE\",\n folder: null,\n },\n },\n });\n\n expect(result).toEqual(expectedResult);\n\n await deleteTempFile(file1);\n });\n\n it(\"-f flag works\", async () => {\n const file1 = await createTempFile(\n \"file1.jsx\",\n `<div>Test searchString and another searchString</div>`\n );\n\n const expectedResult = {\n \"search-string\": {\n apiId: \"search-string\",\n folder: null,\n name: \"Search String\",\n occurrences: {\n [file1]: [\n {\n lineNumber: 1,\n preview: \"<div>Test searchString and another searchString</div>\",\n },\n {\n lineNumber: 1,\n preview: \"<div>Test searchString and another searchString</div>\",\n },\n ],\n },\n status: \"NONE\",\n text: \"searchString\",\n },\n };\n\n const result = await findComponentsInJSXFiles({\n files: [\"/file1.jsx\"],\n components: {\n \"search-string\": {\n name: \"Search String\",\n text: \"searchString\",\n status: \"NONE\",\n folder: null,\n },\n },\n });\n\n expect(result).toEqual(expectedResult);\n\n try {\n await findComponentsInJSXFiles({\n files: [\"/file2.jsx\"],\n components: {\n \"search-string\": {\n name: \"Search String\",\n text: \"searchString\",\n status: \"NONE\",\n folder: null,\n },\n },\n });\n\n expect(false).toEqual(true);\n } catch {\n expect(true).toEqual(true);\n }\n\n await deleteTempFile(file1);\n });\n});\n"],"names":["path","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gBAAe;AACf,kBAAiB;AACjB,kCAAyC;AAEzC,KAAK,KAAK,IAAI;AAEd,SAAS,sBAAsB,MAAM;AACnC,WAAe,eAAe,UAAkB,SAAiB;AAAA;AAC/D,YAAM,WAAW,YAAAA,QAAK,KAAK,KAAK,QAAQ;AACxC,YAAM,IAAI,QAAQ,CAAC,SAAS,WAAW;AACrC,YAAI;AACF,oBAAAC,QAAG,UAAU,UAAU,SAAS,MAAM,QAAQ,IAAI,CAAC;AAAA,QACrD,SAAS,GAAG;AACV,iBAAO,CAA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F;AAAA,MACF,CAAC;AAED,aAAO,KAAK,EAAE,QAAQ,IAAI;AAAA,IAC5B,SAAQ;AACN,aAAO,IAAI,EAAE,QAAQ,IAAI;AAAA,IAC3B;AAEA,UAAM,eAAe,KAAK;AAAA,EAC5B,EAAC;AACH,CAAC","debug_id":"bd23df8e-2e66-5de9-8b6b-5a3ca81ea0a8"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="5fd97f27-7cd5-5b60-98e1-52daff164017")}catch(e){}}();
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var __async = (__this, __arguments, generator) => {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
var fulfilled = (value) => {
|
|
24
|
+
try {
|
|
25
|
+
step(generator.next(value));
|
|
26
|
+
} catch (e) {
|
|
27
|
+
reject(e);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var rejected = (value) => {
|
|
31
|
+
try {
|
|
32
|
+
step(generator.throw(value));
|
|
33
|
+
} catch (e) {
|
|
34
|
+
reject(e);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
38
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
var fetchComponentFolders_exports = {};
|
|
42
|
+
__export(fetchComponentFolders_exports, {
|
|
43
|
+
MOCK_COMPONENT_FOLDERS: () => MOCK_COMPONENT_FOLDERS,
|
|
44
|
+
MOCK_COMPONENT_FOLDERS_WITH_SAMPLE_DATA: () => MOCK_COMPONENT_FOLDERS_WITH_SAMPLE_DATA,
|
|
45
|
+
fetchComponentFolders: () => fetchComponentFolders
|
|
46
|
+
});
|
|
47
|
+
module.exports = __toCommonJS(fetchComponentFolders_exports);
|
|
48
|
+
const MOCK_COMPONENT_FOLDERS = {
|
|
49
|
+
example_folder: "Example Folder"
|
|
50
|
+
};
|
|
51
|
+
const MOCK_COMPONENT_FOLDERS_WITH_SAMPLE_DATA = {
|
|
52
|
+
example_folder: "Example Folder",
|
|
53
|
+
example_folder_sample: "Sample Example Folder"
|
|
54
|
+
};
|
|
55
|
+
function fetchComponentFolders() {
|
|
56
|
+
return __async(this, arguments, function* (_options = {}) {
|
|
57
|
+
if (_options.showSampleData) {
|
|
58
|
+
return MOCK_COMPONENT_FOLDERS_WITH_SAMPLE_DATA;
|
|
59
|
+
}
|
|
60
|
+
return MOCK_COMPONENT_FOLDERS;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
MOCK_COMPONENT_FOLDERS,
|
|
66
|
+
MOCK_COMPONENT_FOLDERS_WITH_SAMPLE_DATA,
|
|
67
|
+
fetchComponentFolders
|
|
68
|
+
});
|
|
69
|
+
//# sourceMappingURL=fetchComponentFolders.js.map
|
|
70
|
+
|
|
71
|
+
//# debugId=5fd97f27-7cd5-5b60-98e1-52daff164017
|