@plasmicapp/cli 0.1.162
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/.eslintrc.js +61 -0
- package/.idea/cli.iml +11 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/README +16 -0
- package/README.internal +46 -0
- package/README.md +17 -0
- package/build.sh +8 -0
- package/dist/__mocks__/api.d.ts +16 -0
- package/dist/__mocks__/api.js +297 -0
- package/dist/__tests__/code-utils-spec.d.ts +1 -0
- package/dist/__tests__/code-utils-spec.js +838 -0
- package/dist/__tests__/ftue-spec.d.ts +1 -0
- package/dist/__tests__/ftue-spec.js +39 -0
- package/dist/__tests__/project-api-token-spec.d.ts +1 -0
- package/dist/__tests__/project-api-token-spec.js +147 -0
- package/dist/__tests__/versioned-sync-spec.d.ts +1 -0
- package/dist/__tests__/versioned-sync-spec.js +145 -0
- package/dist/actions/auth.d.ts +8 -0
- package/dist/actions/auth.js +47 -0
- package/dist/actions/fix-imports.d.ts +4 -0
- package/dist/actions/fix-imports.js +25 -0
- package/dist/actions/init.d.ts +62 -0
- package/dist/actions/init.js +460 -0
- package/dist/actions/project-token.d.ts +6 -0
- package/dist/actions/project-token.js +42 -0
- package/dist/actions/sync-components.d.ts +10 -0
- package/dist/actions/sync-components.js +242 -0
- package/dist/actions/sync-global-variants.d.ts +3 -0
- package/dist/actions/sync-global-variants.js +89 -0
- package/dist/actions/sync-icons.d.ts +7 -0
- package/dist/actions/sync-icons.js +92 -0
- package/dist/actions/sync-images.d.ts +6 -0
- package/dist/actions/sync-images.js +137 -0
- package/dist/actions/sync-styles.d.ts +3 -0
- package/dist/actions/sync-styles.js +58 -0
- package/dist/actions/sync.d.ts +25 -0
- package/dist/actions/sync.js +417 -0
- package/dist/actions/upload-bundle.d.ts +15 -0
- package/dist/actions/upload-bundle.js +28 -0
- package/dist/actions/watch.d.ts +14 -0
- package/dist/actions/watch.js +90 -0
- package/dist/api.d.ts +182 -0
- package/dist/api.js +202 -0
- package/dist/deps.d.ts +2 -0
- package/dist/deps.js +20 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +247 -0
- package/dist/lib.d.ts +10 -0
- package/dist/lib.js +23 -0
- package/dist/migrations/0.1.110-fileLocks.d.ts +2 -0
- package/dist/migrations/0.1.110-fileLocks.js +15 -0
- package/dist/migrations/0.1.143-ensureImportModuleType.d.ts +2 -0
- package/dist/migrations/0.1.143-ensureImportModuleType.js +12 -0
- package/dist/migrations/0.1.146-addReactRuntime.d.ts +2 -0
- package/dist/migrations/0.1.146-addReactRuntime.js +10 -0
- package/dist/migrations/0.1.27-migrateInit.d.ts +1 -0
- package/dist/migrations/0.1.27-migrateInit.js +8 -0
- package/dist/migrations/0.1.28-tsToTsx.d.ts +3 -0
- package/dist/migrations/0.1.28-tsToTsx.js +33 -0
- package/dist/migrations/0.1.31-ensureProjectIcons.d.ts +2 -0
- package/dist/migrations/0.1.31-ensureProjectIcons.js +12 -0
- package/dist/migrations/0.1.42-ensureVersion.d.ts +2 -0
- package/dist/migrations/0.1.42-ensureVersion.js +12 -0
- package/dist/migrations/0.1.57-ensureJsBundleThemes.d.ts +2 -0
- package/dist/migrations/0.1.57-ensureJsBundleThemes.js +12 -0
- package/dist/migrations/0.1.64-imageFiles.d.ts +2 -0
- package/dist/migrations/0.1.64-imageFiles.js +17 -0
- package/dist/migrations/0.1.95-componentType.d.ts +2 -0
- package/dist/migrations/0.1.95-componentType.js +16 -0
- package/dist/migrations/migrations.d.ts +10 -0
- package/dist/migrations/migrations.js +119 -0
- package/dist/plasmic.schema.json +463 -0
- package/dist/test-common/fixtures.d.ts +13 -0
- package/dist/test-common/fixtures.js +165 -0
- package/dist/tsconfig-transform.json +68 -0
- package/dist/utils/auth-utils.d.ts +31 -0
- package/dist/utils/auth-utils.js +236 -0
- package/dist/utils/checksum.d.ts +4 -0
- package/dist/utils/checksum.js +63 -0
- package/dist/utils/code-utils.d.ts +46 -0
- package/dist/utils/code-utils.js +457 -0
- package/dist/utils/config-utils.d.ts +271 -0
- package/dist/utils/config-utils.js +178 -0
- package/dist/utils/envdetect.d.ts +4 -0
- package/dist/utils/envdetect.js +42 -0
- package/dist/utils/error.d.ts +14 -0
- package/dist/utils/error.js +42 -0
- package/dist/utils/file-utils.d.ts +71 -0
- package/dist/utils/file-utils.js +433 -0
- package/dist/utils/get-context.d.ts +40 -0
- package/dist/utils/get-context.js +339 -0
- package/dist/utils/help.d.ts +2 -0
- package/dist/utils/help.js +56 -0
- package/dist/utils/lang-utils.d.ts +10 -0
- package/dist/utils/lang-utils.js +52 -0
- package/dist/utils/npm-utils.d.ts +28 -0
- package/dist/utils/npm-utils.js +215 -0
- package/dist/utils/prompts.d.ts +6 -0
- package/dist/utils/prompts.js +23 -0
- package/dist/utils/resolve-utils.d.ts +13 -0
- package/dist/utils/resolve-utils.js +198 -0
- package/dist/utils/semver.d.ts +34 -0
- package/dist/utils/semver.js +61 -0
- package/dist/utils/test-utils.d.ts +22 -0
- package/dist/utils/test-utils.js +106 -0
- package/dist/utils/user-utils.d.ts +7 -0
- package/dist/utils/user-utils.js +48 -0
- package/jest.config.js +6 -0
- package/package.json +80 -0
- package/src/__mocks__/api.ts +394 -0
- package/src/__tests__/code-utils-spec.ts +881 -0
- package/src/__tests__/ftue-spec.ts +43 -0
- package/src/__tests__/project-api-token-spec.ts +208 -0
- package/src/__tests__/versioned-sync-spec.ts +176 -0
- package/src/actions/auth.ts +43 -0
- package/src/actions/fix-imports.ts +13 -0
- package/src/actions/init.ts +638 -0
- package/src/actions/project-token.ts +36 -0
- package/src/actions/sync-components.ts +405 -0
- package/src/actions/sync-global-variants.ts +129 -0
- package/src/actions/sync-icons.ts +135 -0
- package/src/actions/sync-images.ts +191 -0
- package/src/actions/sync-styles.ts +71 -0
- package/src/actions/sync.ts +747 -0
- package/src/actions/upload-bundle.ts +38 -0
- package/src/actions/watch.ts +95 -0
- package/src/api.ts +407 -0
- package/src/deps.ts +18 -0
- package/src/index.ts +300 -0
- package/src/lib.ts +10 -0
- package/src/migrations/0.1.110-fileLocks.ts +16 -0
- package/src/migrations/0.1.146-addReactRuntime.ts +8 -0
- package/src/migrations/0.1.27-migrateInit.ts +4 -0
- package/src/migrations/0.1.28-tsToTsx.ts +37 -0
- package/src/migrations/0.1.31-ensureProjectIcons.ts +10 -0
- package/src/migrations/0.1.42-ensureVersion.ts +10 -0
- package/src/migrations/0.1.57-ensureJsBundleThemes.ts +10 -0
- package/src/migrations/0.1.64-imageFiles.ts +15 -0
- package/src/migrations/0.1.95-componentType.ts +14 -0
- package/src/migrations/migrations.ts +147 -0
- package/src/test-common/fixtures.ts +178 -0
- package/src/utils/auth-utils.ts +276 -0
- package/src/utils/checksum.ts +106 -0
- package/src/utils/code-utils.ts +656 -0
- package/src/utils/config-utils.ts +551 -0
- package/src/utils/envdetect.ts +39 -0
- package/src/utils/error.ts +36 -0
- package/src/utils/file-utils.ts +526 -0
- package/src/utils/get-context.ts +451 -0
- package/src/utils/help.ts +75 -0
- package/src/utils/lang-utils.ts +52 -0
- package/src/utils/npm-utils.ts +223 -0
- package/src/utils/prompts.ts +22 -0
- package/src/utils/resolve-utils.ts +245 -0
- package/src/utils/semver.ts +67 -0
- package/src/utils/test-utils.ts +116 -0
- package/src/utils/user-utils.ts +37 -0
- package/testData/fixImports_plasmic.json +66 -0
- package/tsconfig-transform.json +68 -0
- package/tsconfig.json +67 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
jest.mock("../api");
|
|
13
|
+
const sync_1 = require("../actions/sync");
|
|
14
|
+
const fixtures_1 = require("../test-common/fixtures");
|
|
15
|
+
// Reset the test project directory
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
fixtures_1.standardTestSetup(false);
|
|
18
|
+
});
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
fixtures_1.standardTestTeardown();
|
|
21
|
+
});
|
|
22
|
+
describe("first-time-user-experience", () => {
|
|
23
|
+
test("missing auth", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
// Trying to sync is going to fail without a valid auth file
|
|
25
|
+
fixtures_1.tmpRepo.deletePlasmicAuth();
|
|
26
|
+
yield expect(sync_1.sync(fixtures_1.opts)).rejects.toThrow();
|
|
27
|
+
}));
|
|
28
|
+
test("no args", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
// No projects or components specified
|
|
30
|
+
yield expect(sync_1.sync(fixtures_1.opts)).rejects.toThrow();
|
|
31
|
+
}));
|
|
32
|
+
test("specify project", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
fixtures_1.opts.projects = ["projectId1"];
|
|
34
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
35
|
+
fixtures_1.expectProject1Components();
|
|
36
|
+
expect(fixtures_1.tmpRepo.checkFile("./src/DepComponent.tsx")).toBeFalsy();
|
|
37
|
+
fixtures_1.expectProject1PlasmicJson();
|
|
38
|
+
}));
|
|
39
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const sync_1 = require("../actions/sync");
|
|
13
|
+
const fixtures_1 = require("../test-common/fixtures");
|
|
14
|
+
jest.mock("../api");
|
|
15
|
+
// Reset the test project directory
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
fixtures_1.standardTestSetup(false);
|
|
18
|
+
});
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
fixtures_1.standardTestTeardown();
|
|
21
|
+
});
|
|
22
|
+
function removeAuth() {
|
|
23
|
+
fixtures_1.opts.auth = undefined;
|
|
24
|
+
// Don't need to remove this file, we just do for good measure.
|
|
25
|
+
fixtures_1.tmpRepo.deletePlasmicAuth();
|
|
26
|
+
}
|
|
27
|
+
describe("Project API tokens", () => {
|
|
28
|
+
test("is filled in by auth'd user so that a second run does not need auth", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
fixtures_1.opts.projects = ["projectId1"];
|
|
30
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
31
|
+
fixtures_1.expectProject1Components();
|
|
32
|
+
fixtures_1.expectProject1PlasmicJson();
|
|
33
|
+
// Re-run, this time with no auth.
|
|
34
|
+
removeAuth();
|
|
35
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
36
|
+
}));
|
|
37
|
+
test("can be passed in from command-line args", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
removeAuth();
|
|
39
|
+
// Without specifying version.
|
|
40
|
+
fixtures_1.opts.projects = ["projectId1:abc"];
|
|
41
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
42
|
+
// Specifying version.
|
|
43
|
+
fixtures_1.opts.projects = ["projectId1:abc@1.2.3"];
|
|
44
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
45
|
+
// Wrong token (should fail).
|
|
46
|
+
fixtures_1.opts.projects = ["projectId1:123"];
|
|
47
|
+
yield expect(sync_1.sync(fixtures_1.opts)).rejects.toThrow("No user+token, and project API tokens don't match");
|
|
48
|
+
}));
|
|
49
|
+
test("is corrected by auth'd user if token was initially incorrect", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
fixtures_1.opts.projects = ["projectId1"];
|
|
51
|
+
fixtures_1.tmpRepo.writePlasmicJson(Object.assign(Object.assign({}, fixtures_1.defaultPlasmicJson), { projects: [Object.assign(Object.assign({}, fixtures_1.project1Config), { projectApiToken: "blah" })] }));
|
|
52
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
53
|
+
fixtures_1.expectProject1Components();
|
|
54
|
+
fixtures_1.expectProject1PlasmicJson();
|
|
55
|
+
// Re-run, this time with no auth.
|
|
56
|
+
removeAuth();
|
|
57
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
58
|
+
}));
|
|
59
|
+
test("is filled in by auth'd user if project exists but token was initially missing", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
+
fixtures_1.opts.projects = ["projectId1"];
|
|
61
|
+
fixtures_1.tmpRepo.writePlasmicJson(Object.assign(Object.assign({}, fixtures_1.defaultPlasmicJson), { projects: [fixtures_1.project1Config] }));
|
|
62
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
63
|
+
fixtures_1.expectProject1Components();
|
|
64
|
+
fixtures_1.expectProject1PlasmicJson();
|
|
65
|
+
// Re-run, this time with no auth.
|
|
66
|
+
removeAuth();
|
|
67
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
68
|
+
}));
|
|
69
|
+
test("when not available, should prompt for auth", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
+
fixtures_1.opts.projects = ["projectId1"];
|
|
71
|
+
removeAuth();
|
|
72
|
+
yield expect(sync_1.sync(fixtures_1.opts)).rejects.toThrow("Unable to authenticate");
|
|
73
|
+
}));
|
|
74
|
+
// TODO: Would be nice to eventually make this not fail outright but to prompt for auth.
|
|
75
|
+
test("when incorrect, should fail", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
76
|
+
fixtures_1.opts.projects = ["projectId1"];
|
|
77
|
+
removeAuth();
|
|
78
|
+
fixtures_1.tmpRepo.writePlasmicJson(Object.assign(Object.assign({}, fixtures_1.defaultPlasmicJson), { projects: [Object.assign(Object.assign({}, fixtures_1.project1Config), { projectApiToken: "blah" })] }));
|
|
79
|
+
yield expect(sync_1.sync(fixtures_1.opts)).rejects.toThrow("No user+token, and project API tokens don't match");
|
|
80
|
+
}));
|
|
81
|
+
test("works even if you have tokens for base but not deps", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
82
|
+
// Make project1 have a dependency.
|
|
83
|
+
fixtures_1.standardTestSetup();
|
|
84
|
+
fixtures_1.opts.projects = ["projectId1"];
|
|
85
|
+
removeAuth();
|
|
86
|
+
fixtures_1.tmpRepo.writePlasmicJson(Object.assign(Object.assign({}, fixtures_1.defaultPlasmicJson), { projects: [Object.assign(Object.assign({}, fixtures_1.project1Config), { projectApiToken: "abc" })] }));
|
|
87
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
88
|
+
fixtures_1.expectProject1Components();
|
|
89
|
+
fixtures_1.expectProjectAndDepPlasmicJson();
|
|
90
|
+
}));
|
|
91
|
+
test("works even if dependency was determined to not need an update", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
92
|
+
// Make project1 have a dependency.
|
|
93
|
+
fixtures_1.standardTestSetup();
|
|
94
|
+
fixtures_1.opts.projects = ["projectId1"];
|
|
95
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
96
|
+
// We sync project1 which got updated, but the dependency is still same version.
|
|
97
|
+
fixtures_1.opts.force = false;
|
|
98
|
+
removeAuth();
|
|
99
|
+
fixtures_1.mockApi.getMockProject("projectId1", "1.2.3").version = "1.2.4";
|
|
100
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
101
|
+
}));
|
|
102
|
+
test("should prompt for auth if you have only irrelevant tokens", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
103
|
+
fixtures_1.opts.projects = ["dependencyId1"];
|
|
104
|
+
removeAuth();
|
|
105
|
+
fixtures_1.tmpRepo.writePlasmicJson(Object.assign(Object.assign({}, fixtures_1.defaultPlasmicJson), { projects: [Object.assign(Object.assign({}, fixtures_1.project1Config), { projectApiToken: "abc" })] }));
|
|
106
|
+
yield expect(sync_1.sync(fixtures_1.opts)).rejects.toThrow("Unable to authenticate");
|
|
107
|
+
}));
|
|
108
|
+
test("should use plasmic-loader.json for API tokens in loader mode", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
109
|
+
process.env.PLASMIC_LOADER = "1";
|
|
110
|
+
fixtures_1.opts.projects = ["projectId1"];
|
|
111
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
112
|
+
const loaderConfig = fixtures_1.tmpRepo.readPlasmicLoaderJson();
|
|
113
|
+
expect(loaderConfig).toEqual({
|
|
114
|
+
projects: [
|
|
115
|
+
{
|
|
116
|
+
projectId: "projectId1",
|
|
117
|
+
projectApiToken: "abc",
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
});
|
|
121
|
+
// Re-run, this time with no auth and no tokens in plasmic.json, only in plasmic-loader.json.
|
|
122
|
+
removeAuth();
|
|
123
|
+
fixtures_1.tmpRepo.writePlasmicJson(fixtures_1.defaultPlasmicJson);
|
|
124
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
125
|
+
delete process.env["PLASMIC_LOADER"];
|
|
126
|
+
}));
|
|
127
|
+
test("works in PlasmicLoader mode even if root project was determined to not need an update", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
128
|
+
process.env.PLASMIC_LOADER = "1";
|
|
129
|
+
// Make project1 have a dependency.
|
|
130
|
+
fixtures_1.standardTestSetup();
|
|
131
|
+
// Explicitly sync both - we had a bug writing back the plasmic-loader.json in this case.
|
|
132
|
+
fixtures_1.opts.projects = ["projectId1", "dependencyId1"];
|
|
133
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
134
|
+
// We sync project1 which got updated, but the dependency is still same version.
|
|
135
|
+
fixtures_1.opts.force = false;
|
|
136
|
+
removeAuth();
|
|
137
|
+
fixtures_1.mockApi.getMockProject("projectId1", "1.2.3").version = "1.2.4";
|
|
138
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
139
|
+
}));
|
|
140
|
+
test("should fail in loader mode if not available", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
141
|
+
process.env.PLASMIC_LOADER = "1";
|
|
142
|
+
fixtures_1.opts.projects = ["projectId1"];
|
|
143
|
+
removeAuth();
|
|
144
|
+
yield expect(sync_1.sync(fixtures_1.opts)).rejects.toThrow();
|
|
145
|
+
delete process.env["PLASMIC_LOADER"];
|
|
146
|
+
}));
|
|
147
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const sync_1 = require("../actions/sync");
|
|
13
|
+
const fixtures_1 = require("../test-common/fixtures");
|
|
14
|
+
jest.mock("../api");
|
|
15
|
+
// Reset the test project directory
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
fixtures_1.standardTestSetup();
|
|
18
|
+
});
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
// Remove the temporary directory
|
|
21
|
+
// TODO: Comment out to keep files for debugging
|
|
22
|
+
fixtures_1.standardTestTeardown();
|
|
23
|
+
});
|
|
24
|
+
describe("versioned-sync", () => {
|
|
25
|
+
test("syncs non-recursive case", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
fixtures_1.opts.projects = ["projectId1"];
|
|
27
|
+
fixtures_1.opts.nonRecursive = true;
|
|
28
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
29
|
+
fixtures_1.expectProject1Components();
|
|
30
|
+
expect(fixtures_1.tmpRepo.checkFile("./src/DepComponent.tsx")).toBeFalsy();
|
|
31
|
+
// Check plasmic.json
|
|
32
|
+
fixtures_1.expectProject1PlasmicJson();
|
|
33
|
+
}));
|
|
34
|
+
test("syncs missing components", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
fixtures_1.opts.projects = ["projectId1"];
|
|
36
|
+
fixtures_1.opts.nonRecursive = true;
|
|
37
|
+
// Simulates user deleting files by accident, since the project exists in plasmic.json,
|
|
38
|
+
// but not in the project directory
|
|
39
|
+
const plasmicJson = fixtures_1.tmpRepo.readPlasmicJson();
|
|
40
|
+
plasmicJson.projects.push(fixtures_1.project1Config);
|
|
41
|
+
fixtures_1.tmpRepo.writePlasmicJson(plasmicJson);
|
|
42
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
43
|
+
}));
|
|
44
|
+
test("syncs down new names", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
fixtures_1.opts.projects = ["projectId1"];
|
|
46
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
47
|
+
// Change component name server-side
|
|
48
|
+
const mockProject = fixtures_1.mockApi.getMockProject("projectId1", "1.2.3");
|
|
49
|
+
const buttonData = mockProject.components.find((c) => c.id === "buttonId");
|
|
50
|
+
buttonData.name = "NewButton";
|
|
51
|
+
mockProject.version = "2.0.0";
|
|
52
|
+
fixtures_1.mockApi.addMockProject(mockProject);
|
|
53
|
+
// Try syncing again and see if things show up
|
|
54
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
55
|
+
const plasmicJson = fixtures_1.tmpRepo.readPlasmicJson();
|
|
56
|
+
const projectInConfig = plasmicJson.projects.find((p) => p.projectId === "projectId1");
|
|
57
|
+
const componentInConfig = !!projectInConfig
|
|
58
|
+
? projectInConfig.components.find((c) => c.id === buttonData.id)
|
|
59
|
+
: undefined;
|
|
60
|
+
expect(componentInConfig).toBeTruthy();
|
|
61
|
+
expect(componentInConfig === null || componentInConfig === void 0 ? void 0 : componentInConfig.name).toEqual(buttonData.name);
|
|
62
|
+
}));
|
|
63
|
+
test("syncs latest", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
+
fixtures_1.opts.projects = ["projectId1"];
|
|
65
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
66
|
+
// Change component version server-side
|
|
67
|
+
const mockProject = fixtures_1.mockApi.getMockProject("projectId1", "1.2.3");
|
|
68
|
+
mockProject.version = "1.3.4";
|
|
69
|
+
fixtures_1.mockApi.addMockProject(mockProject);
|
|
70
|
+
// Try syncing again and see if things show up
|
|
71
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
72
|
+
const button = fixtures_1.mockApi.stringToMockComponent(fixtures_1.tmpRepo.getComponentFileContents("projectId1", "buttonId"));
|
|
73
|
+
expect(button).toBeTruthy();
|
|
74
|
+
expect(button === null || button === void 0 ? void 0 : button.name).toEqual("Button");
|
|
75
|
+
expect(button === null || button === void 0 ? void 0 : button.version).toEqual("1.3.4");
|
|
76
|
+
}));
|
|
77
|
+
test("syncs exact version", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
+
fixtures_1.opts.projects = ["projectId1"];
|
|
79
|
+
fixtures_1.opts.nonRecursive = true;
|
|
80
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
81
|
+
// Change component version server-side
|
|
82
|
+
const mockProject = fixtures_1.mockApi.getMockProject("projectId1", "1.2.3");
|
|
83
|
+
mockProject.version = "2.0.0";
|
|
84
|
+
fixtures_1.mockApi.addMockProject(mockProject);
|
|
85
|
+
// Read in updated plasmic.json post-sync
|
|
86
|
+
const plasmicJson = fixtures_1.tmpRepo.readPlasmicJson();
|
|
87
|
+
expect(plasmicJson.projects.length).toEqual(1); // projectId1
|
|
88
|
+
expect(plasmicJson.projects[0].components.length).toEqual(2); // Container+Button
|
|
89
|
+
// Try syncing non-existent version
|
|
90
|
+
plasmicJson.projects[0].version = "1.2.10"; // Doesn't exist
|
|
91
|
+
fixtures_1.tmpRepo.writePlasmicJson(plasmicJson);
|
|
92
|
+
yield expect(sync_1.sync(fixtures_1.opts)).rejects.toThrow();
|
|
93
|
+
// Try syncing existing version
|
|
94
|
+
plasmicJson.projects[0].version = "2.0.0"; // Doesn't exist
|
|
95
|
+
fixtures_1.tmpRepo.writePlasmicJson(plasmicJson);
|
|
96
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
97
|
+
const button = fixtures_1.mockApi.stringToMockComponent(fixtures_1.tmpRepo.getComponentFileContents("projectId1", "buttonId"));
|
|
98
|
+
expect(button).toBeTruthy();
|
|
99
|
+
expect(button === null || button === void 0 ? void 0 : button.name).toEqual("Button");
|
|
100
|
+
expect(button === null || button === void 0 ? void 0 : button.version).toEqual("2.0.0");
|
|
101
|
+
}));
|
|
102
|
+
test("syncs according to semver", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
103
|
+
fixtures_1.opts.projects = ["projectId1"];
|
|
104
|
+
fixtures_1.opts.nonRecursive = true;
|
|
105
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
106
|
+
// Change component version server-side
|
|
107
|
+
const mockProject = fixtures_1.mockApi.getMockProject("projectId1", "1.2.3");
|
|
108
|
+
mockProject.version = "1.10.1";
|
|
109
|
+
fixtures_1.mockApi.addMockProject(mockProject);
|
|
110
|
+
// Update plasmic.json to use semver
|
|
111
|
+
const plasmicJson = fixtures_1.tmpRepo.readPlasmicJson();
|
|
112
|
+
expect(plasmicJson.projects.length).toEqual(1);
|
|
113
|
+
expect(plasmicJson.projects[0].components.length).toEqual(2);
|
|
114
|
+
plasmicJson.projects[0].version = "^1.2.3";
|
|
115
|
+
// Try syncing again and see if things show up
|
|
116
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
117
|
+
const button = fixtures_1.mockApi.stringToMockComponent(fixtures_1.tmpRepo.getComponentFileContents("projectId1", "buttonId"));
|
|
118
|
+
expect(button).toBeTruthy();
|
|
119
|
+
expect(button === null || button === void 0 ? void 0 : button.name).toEqual("Button");
|
|
120
|
+
expect(button === null || button === void 0 ? void 0 : button.version).toEqual("1.10.1");
|
|
121
|
+
}));
|
|
122
|
+
});
|
|
123
|
+
describe("recursive-sync", () => {
|
|
124
|
+
test("non-recursive base case", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
|
+
// Should sync both Button+Container because of the dependency
|
|
126
|
+
fixtures_1.opts.projects = ["projectId1"];
|
|
127
|
+
fixtures_1.opts.nonRecursive = true;
|
|
128
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
129
|
+
fixtures_1.expectProject1Components();
|
|
130
|
+
expect(fixtures_1.tmpRepo.checkFile("./src/DepComponent.tsx")).toBeFalsy();
|
|
131
|
+
fixtures_1.expectProject1PlasmicJson();
|
|
132
|
+
}));
|
|
133
|
+
test("dependencies base case", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
134
|
+
fixtures_1.opts.projects = ["projectId1"];
|
|
135
|
+
yield expect(sync_1.sync(fixtures_1.opts)).resolves.toBeUndefined();
|
|
136
|
+
expect(fixtures_1.tmpRepo.checkFile("./src/Button.tsx")).toBeTruthy();
|
|
137
|
+
expect(fixtures_1.tmpRepo.checkFile("./src/Container.tsx")).toBeTruthy();
|
|
138
|
+
const depComponent = fixtures_1.mockApi.stringToMockComponent(fixtures_1.tmpRepo.getComponentFileContents("dependencyId1", "depComponentId"));
|
|
139
|
+
expect(depComponent).toBeTruthy();
|
|
140
|
+
expect(depComponent === null || depComponent === void 0 ? void 0 : depComponent.name).toEqual("DepComponent");
|
|
141
|
+
expect(depComponent === null || depComponent === void 0 ? void 0 : depComponent.version).toEqual("2.3.4");
|
|
142
|
+
// Check plasmic.json
|
|
143
|
+
fixtures_1.expectProjectAndDepPlasmicJson();
|
|
144
|
+
}));
|
|
145
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.auth = exports.checkCredentials = void 0;
|
|
13
|
+
const deps_1 = require("../deps");
|
|
14
|
+
const auth_utils_1 = require("../utils/auth-utils");
|
|
15
|
+
const error_1 = require("../utils/error");
|
|
16
|
+
function checkCredentials() {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
if (yield auth_utils_1.getCurrentAuth()) {
|
|
19
|
+
deps_1.logger.info("Plasmic credentials are ok.");
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
throw new error_1.HandledError("The authentication credentials are missing or invalid.");
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
exports.checkCredentials = checkCredentials;
|
|
26
|
+
function getEmail() {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const authCreds = yield auth_utils_1.getCurrentAuth();
|
|
29
|
+
if (authCreds) {
|
|
30
|
+
deps_1.logger.info(authCreds.user);
|
|
31
|
+
return authCreds.user;
|
|
32
|
+
}
|
|
33
|
+
throw new error_1.HandledError("The authentication credentials are missing or invalid.");
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function auth(args) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
if (args.check) {
|
|
39
|
+
return checkCredentials();
|
|
40
|
+
}
|
|
41
|
+
if (args.email) {
|
|
42
|
+
return getEmail();
|
|
43
|
+
}
|
|
44
|
+
return auth_utils_1.startAuth(args);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
exports.auth = auth;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.fixImports = void 0;
|
|
13
|
+
const code_utils_1 = require("../utils/code-utils");
|
|
14
|
+
const file_utils_1 = require("../utils/file-utils");
|
|
15
|
+
const get_context_1 = require("../utils/get-context");
|
|
16
|
+
function fixImports(opts) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
if (!opts.baseDir)
|
|
19
|
+
opts.baseDir = process.cwd();
|
|
20
|
+
const context = yield get_context_1.getContext(opts, { enableSkipAuth: true });
|
|
21
|
+
yield file_utils_1.fixAllFilePaths(context, opts.baseDir);
|
|
22
|
+
yield code_utils_1.fixAllImportStatements(context, opts.baseDir);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
exports.fixImports = fixImports;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { CommonArgs } from "..";
|
|
2
|
+
export interface InitArgs extends CommonArgs {
|
|
3
|
+
host: string;
|
|
4
|
+
platform: "" | "react" | "nextjs" | "gatsby";
|
|
5
|
+
codeLang: "" | "ts" | "js";
|
|
6
|
+
codeScheme: "" | "blackbox" | "direct";
|
|
7
|
+
styleScheme: "" | "css" | "css-modules";
|
|
8
|
+
imagesScheme: "" | "inlined" | "files" | "public-files";
|
|
9
|
+
imagesPublicDir: string;
|
|
10
|
+
imagesPublicUrlPrefix: string;
|
|
11
|
+
srcDir: string;
|
|
12
|
+
plasmicDir: string;
|
|
13
|
+
pagesDir?: string;
|
|
14
|
+
enableSkipAuth?: boolean;
|
|
15
|
+
reactRuntime?: "classic" | "automatic";
|
|
16
|
+
}
|
|
17
|
+
export declare function initPlasmic(opts: InitArgs & {
|
|
18
|
+
enableSkipAuth?: boolean;
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Get the short description, which exists for all args
|
|
22
|
+
* @param key
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export declare function getInitArgsShortDescription(key: keyof Omit<InitArgs, "baseDir">): string | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Try to get a long description, falling back to the short description
|
|
28
|
+
* @param key
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
export declare function getInitArgsLongDescription(key: keyof Omit<InitArgs, "baseDir">): string | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Try to get a question form, falling back to the description
|
|
34
|
+
* @param key
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
export declare function getInitArgsQuestion(key: keyof Omit<InitArgs, "baseDir">): string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Get the possible choices for an arg
|
|
40
|
+
* @param key
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
export declare function getInitArgsChoices(key: keyof Omit<InitArgs, "baseDir">): string[] | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Get a `opt` object for use with the `yargs` library.
|
|
46
|
+
* If no choices are specified, assume it's freeform string input
|
|
47
|
+
* All options use "" as the default, unless overridden
|
|
48
|
+
* @param key
|
|
49
|
+
* @param defaultOverride
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
export declare function getYargsOption(key: keyof Omit<InitArgs, "baseDir">, defaultOverride?: string): {
|
|
53
|
+
describe: string;
|
|
54
|
+
string: boolean;
|
|
55
|
+
default: string;
|
|
56
|
+
choices?: undefined;
|
|
57
|
+
} | {
|
|
58
|
+
describe: string;
|
|
59
|
+
choices: string[];
|
|
60
|
+
default: string;
|
|
61
|
+
string?: undefined;
|
|
62
|
+
};
|