@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.
Files changed (162) hide show
  1. package/.eslintrc.js +61 -0
  2. package/.idea/cli.iml +11 -0
  3. package/.idea/misc.xml +6 -0
  4. package/.idea/modules.xml +8 -0
  5. package/.idea/vcs.xml +6 -0
  6. package/README +16 -0
  7. package/README.internal +46 -0
  8. package/README.md +17 -0
  9. package/build.sh +8 -0
  10. package/dist/__mocks__/api.d.ts +16 -0
  11. package/dist/__mocks__/api.js +297 -0
  12. package/dist/__tests__/code-utils-spec.d.ts +1 -0
  13. package/dist/__tests__/code-utils-spec.js +838 -0
  14. package/dist/__tests__/ftue-spec.d.ts +1 -0
  15. package/dist/__tests__/ftue-spec.js +39 -0
  16. package/dist/__tests__/project-api-token-spec.d.ts +1 -0
  17. package/dist/__tests__/project-api-token-spec.js +147 -0
  18. package/dist/__tests__/versioned-sync-spec.d.ts +1 -0
  19. package/dist/__tests__/versioned-sync-spec.js +145 -0
  20. package/dist/actions/auth.d.ts +8 -0
  21. package/dist/actions/auth.js +47 -0
  22. package/dist/actions/fix-imports.d.ts +4 -0
  23. package/dist/actions/fix-imports.js +25 -0
  24. package/dist/actions/init.d.ts +62 -0
  25. package/dist/actions/init.js +460 -0
  26. package/dist/actions/project-token.d.ts +6 -0
  27. package/dist/actions/project-token.js +42 -0
  28. package/dist/actions/sync-components.d.ts +10 -0
  29. package/dist/actions/sync-components.js +242 -0
  30. package/dist/actions/sync-global-variants.d.ts +3 -0
  31. package/dist/actions/sync-global-variants.js +89 -0
  32. package/dist/actions/sync-icons.d.ts +7 -0
  33. package/dist/actions/sync-icons.js +92 -0
  34. package/dist/actions/sync-images.d.ts +6 -0
  35. package/dist/actions/sync-images.js +137 -0
  36. package/dist/actions/sync-styles.d.ts +3 -0
  37. package/dist/actions/sync-styles.js +58 -0
  38. package/dist/actions/sync.d.ts +25 -0
  39. package/dist/actions/sync.js +417 -0
  40. package/dist/actions/upload-bundle.d.ts +15 -0
  41. package/dist/actions/upload-bundle.js +28 -0
  42. package/dist/actions/watch.d.ts +14 -0
  43. package/dist/actions/watch.js +90 -0
  44. package/dist/api.d.ts +182 -0
  45. package/dist/api.js +202 -0
  46. package/dist/deps.d.ts +2 -0
  47. package/dist/deps.js +20 -0
  48. package/dist/index.d.ts +7 -0
  49. package/dist/index.js +247 -0
  50. package/dist/lib.d.ts +10 -0
  51. package/dist/lib.js +23 -0
  52. package/dist/migrations/0.1.110-fileLocks.d.ts +2 -0
  53. package/dist/migrations/0.1.110-fileLocks.js +15 -0
  54. package/dist/migrations/0.1.143-ensureImportModuleType.d.ts +2 -0
  55. package/dist/migrations/0.1.143-ensureImportModuleType.js +12 -0
  56. package/dist/migrations/0.1.146-addReactRuntime.d.ts +2 -0
  57. package/dist/migrations/0.1.146-addReactRuntime.js +10 -0
  58. package/dist/migrations/0.1.27-migrateInit.d.ts +1 -0
  59. package/dist/migrations/0.1.27-migrateInit.js +8 -0
  60. package/dist/migrations/0.1.28-tsToTsx.d.ts +3 -0
  61. package/dist/migrations/0.1.28-tsToTsx.js +33 -0
  62. package/dist/migrations/0.1.31-ensureProjectIcons.d.ts +2 -0
  63. package/dist/migrations/0.1.31-ensureProjectIcons.js +12 -0
  64. package/dist/migrations/0.1.42-ensureVersion.d.ts +2 -0
  65. package/dist/migrations/0.1.42-ensureVersion.js +12 -0
  66. package/dist/migrations/0.1.57-ensureJsBundleThemes.d.ts +2 -0
  67. package/dist/migrations/0.1.57-ensureJsBundleThemes.js +12 -0
  68. package/dist/migrations/0.1.64-imageFiles.d.ts +2 -0
  69. package/dist/migrations/0.1.64-imageFiles.js +17 -0
  70. package/dist/migrations/0.1.95-componentType.d.ts +2 -0
  71. package/dist/migrations/0.1.95-componentType.js +16 -0
  72. package/dist/migrations/migrations.d.ts +10 -0
  73. package/dist/migrations/migrations.js +119 -0
  74. package/dist/plasmic.schema.json +463 -0
  75. package/dist/test-common/fixtures.d.ts +13 -0
  76. package/dist/test-common/fixtures.js +165 -0
  77. package/dist/tsconfig-transform.json +68 -0
  78. package/dist/utils/auth-utils.d.ts +31 -0
  79. package/dist/utils/auth-utils.js +236 -0
  80. package/dist/utils/checksum.d.ts +4 -0
  81. package/dist/utils/checksum.js +63 -0
  82. package/dist/utils/code-utils.d.ts +46 -0
  83. package/dist/utils/code-utils.js +457 -0
  84. package/dist/utils/config-utils.d.ts +271 -0
  85. package/dist/utils/config-utils.js +178 -0
  86. package/dist/utils/envdetect.d.ts +4 -0
  87. package/dist/utils/envdetect.js +42 -0
  88. package/dist/utils/error.d.ts +14 -0
  89. package/dist/utils/error.js +42 -0
  90. package/dist/utils/file-utils.d.ts +71 -0
  91. package/dist/utils/file-utils.js +433 -0
  92. package/dist/utils/get-context.d.ts +40 -0
  93. package/dist/utils/get-context.js +339 -0
  94. package/dist/utils/help.d.ts +2 -0
  95. package/dist/utils/help.js +56 -0
  96. package/dist/utils/lang-utils.d.ts +10 -0
  97. package/dist/utils/lang-utils.js +52 -0
  98. package/dist/utils/npm-utils.d.ts +28 -0
  99. package/dist/utils/npm-utils.js +215 -0
  100. package/dist/utils/prompts.d.ts +6 -0
  101. package/dist/utils/prompts.js +23 -0
  102. package/dist/utils/resolve-utils.d.ts +13 -0
  103. package/dist/utils/resolve-utils.js +198 -0
  104. package/dist/utils/semver.d.ts +34 -0
  105. package/dist/utils/semver.js +61 -0
  106. package/dist/utils/test-utils.d.ts +22 -0
  107. package/dist/utils/test-utils.js +106 -0
  108. package/dist/utils/user-utils.d.ts +7 -0
  109. package/dist/utils/user-utils.js +48 -0
  110. package/jest.config.js +6 -0
  111. package/package.json +80 -0
  112. package/src/__mocks__/api.ts +394 -0
  113. package/src/__tests__/code-utils-spec.ts +881 -0
  114. package/src/__tests__/ftue-spec.ts +43 -0
  115. package/src/__tests__/project-api-token-spec.ts +208 -0
  116. package/src/__tests__/versioned-sync-spec.ts +176 -0
  117. package/src/actions/auth.ts +43 -0
  118. package/src/actions/fix-imports.ts +13 -0
  119. package/src/actions/init.ts +638 -0
  120. package/src/actions/project-token.ts +36 -0
  121. package/src/actions/sync-components.ts +405 -0
  122. package/src/actions/sync-global-variants.ts +129 -0
  123. package/src/actions/sync-icons.ts +135 -0
  124. package/src/actions/sync-images.ts +191 -0
  125. package/src/actions/sync-styles.ts +71 -0
  126. package/src/actions/sync.ts +747 -0
  127. package/src/actions/upload-bundle.ts +38 -0
  128. package/src/actions/watch.ts +95 -0
  129. package/src/api.ts +407 -0
  130. package/src/deps.ts +18 -0
  131. package/src/index.ts +300 -0
  132. package/src/lib.ts +10 -0
  133. package/src/migrations/0.1.110-fileLocks.ts +16 -0
  134. package/src/migrations/0.1.146-addReactRuntime.ts +8 -0
  135. package/src/migrations/0.1.27-migrateInit.ts +4 -0
  136. package/src/migrations/0.1.28-tsToTsx.ts +37 -0
  137. package/src/migrations/0.1.31-ensureProjectIcons.ts +10 -0
  138. package/src/migrations/0.1.42-ensureVersion.ts +10 -0
  139. package/src/migrations/0.1.57-ensureJsBundleThemes.ts +10 -0
  140. package/src/migrations/0.1.64-imageFiles.ts +15 -0
  141. package/src/migrations/0.1.95-componentType.ts +14 -0
  142. package/src/migrations/migrations.ts +147 -0
  143. package/src/test-common/fixtures.ts +178 -0
  144. package/src/utils/auth-utils.ts +276 -0
  145. package/src/utils/checksum.ts +106 -0
  146. package/src/utils/code-utils.ts +656 -0
  147. package/src/utils/config-utils.ts +551 -0
  148. package/src/utils/envdetect.ts +39 -0
  149. package/src/utils/error.ts +36 -0
  150. package/src/utils/file-utils.ts +526 -0
  151. package/src/utils/get-context.ts +451 -0
  152. package/src/utils/help.ts +75 -0
  153. package/src/utils/lang-utils.ts +52 -0
  154. package/src/utils/npm-utils.ts +223 -0
  155. package/src/utils/prompts.ts +22 -0
  156. package/src/utils/resolve-utils.ts +245 -0
  157. package/src/utils/semver.ts +67 -0
  158. package/src/utils/test-utils.ts +116 -0
  159. package/src/utils/user-utils.ts +37 -0
  160. package/testData/fixImports_plasmic.json +66 -0
  161. package/tsconfig-transform.json +68 -0
  162. package/tsconfig.json +67 -0
package/dist/lib.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var auth_1 = require("./actions/auth");
4
+ Object.defineProperty(exports, "auth", { enumerable: true, get: function () { return auth_1.auth; } });
5
+ var fix_imports_1 = require("./actions/fix-imports");
6
+ Object.defineProperty(exports, "fixImports", { enumerable: true, get: function () { return fix_imports_1.fixImports; } });
7
+ var init_1 = require("./actions/init");
8
+ Object.defineProperty(exports, "initPlasmic", { enumerable: true, get: function () { return init_1.initPlasmic; } });
9
+ var project_token_1 = require("./actions/project-token");
10
+ Object.defineProperty(exports, "getProjectApiToken", { enumerable: true, get: function () { return project_token_1.getProjectApiToken; } });
11
+ var sync_1 = require("./actions/sync");
12
+ Object.defineProperty(exports, "sync", { enumerable: true, get: function () { return sync_1.sync; } });
13
+ var upload_bundle_1 = require("./actions/upload-bundle");
14
+ Object.defineProperty(exports, "uploadJsBundle", { enumerable: true, get: function () { return upload_bundle_1.uploadJsBundle; } });
15
+ var watch_1 = require("./actions/watch");
16
+ Object.defineProperty(exports, "watchProjects", { enumerable: true, get: function () { return watch_1.watchProjects; } });
17
+ var deps_1 = require("./deps");
18
+ Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return deps_1.logger; } });
19
+ var error_1 = require("./utils/error");
20
+ Object.defineProperty(exports, "HandledError", { enumerable: true, get: function () { return error_1.HandledError; } });
21
+ Object.defineProperty(exports, "handleError", { enumerable: true, get: function () { return error_1.handleError; } });
22
+ var get_context_1 = require("./utils/get-context");
23
+ Object.defineProperty(exports, "setMetadataEnv", { enumerable: true, get: function () { return get_context_1.setMetadataEnv; } });
@@ -0,0 +1,2 @@
1
+ import { PlasmicLock } from "../utils/config-utils";
2
+ export declare function ensureFileLocks(lock: PlasmicLock): PlasmicLock;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureFileLocks = void 0;
4
+ function ensureFileLocks(lock) {
5
+ for (const project of lock.projects) {
6
+ // Ensure all `ProjectLock`s have `fileLock` array
7
+ if (!project.fileLocks) {
8
+ project.fileLocks = [];
9
+ }
10
+ // Ensure all `FileLock`s have valid checksums
11
+ project.fileLocks = project.fileLocks.filter((fileLock) => typeof fileLock.checksum === "string" && fileLock.checksum.length === 32);
12
+ }
13
+ return lock;
14
+ }
15
+ exports.ensureFileLocks = ensureFileLocks;
@@ -0,0 +1,2 @@
1
+ import { PlasmicConfig } from "../utils/config-utils";
2
+ export declare function ensureImportModuleType(config: PlasmicConfig): PlasmicConfig;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureImportModuleType = void 0;
4
+ function ensureImportModuleType(config) {
5
+ for (const project of config.projects) {
6
+ for (const component of project.components) {
7
+ component.importSpec.moduleType = "local";
8
+ }
9
+ }
10
+ return config;
11
+ }
12
+ exports.ensureImportModuleType = ensureImportModuleType;
@@ -0,0 +1,2 @@
1
+ import { PlasmicConfig } from "../utils/config-utils";
2
+ export declare function ensureReactRuntime(config: PlasmicConfig): PlasmicConfig;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureReactRuntime = void 0;
4
+ function ensureReactRuntime(config) {
5
+ if (!config.code.reactRuntime) {
6
+ config.code.reactRuntime = "classic";
7
+ }
8
+ return config;
9
+ }
10
+ exports.ensureReactRuntime = ensureReactRuntime;
@@ -0,0 +1 @@
1
+ export declare function migrateInit(prev: any): any;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.migrateInit = void 0;
4
+ function migrateInit(prev) {
5
+ // Just stamping the first migration
6
+ return prev;
7
+ }
8
+ exports.migrateInit = migrateInit;
@@ -0,0 +1,3 @@
1
+ import { PlasmicConfig } from "../utils/config-utils";
2
+ import { MigrateContext } from "./migrations";
3
+ export declare function tsToTsx(config: PlasmicConfig, context: MigrateContext): PlasmicConfig;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.tsToTsx = void 0;
7
+ const glob_1 = __importDefault(require("glob"));
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ const upath_1 = __importDefault(require("upath"));
10
+ const deps_1 = require("../deps");
11
+ const file_utils_1 = require("../utils/file-utils");
12
+ function tsToTsx(config, context) {
13
+ const srcDir = context.absoluteSrcDir;
14
+ const allFiles = glob_1.default.sync(`${srcDir}/**/*.+(ts)`, {
15
+ ignore: [`${srcDir}/**/node_modules/**/*`],
16
+ });
17
+ const existingFiles = lodash_1.default.groupBy(allFiles, (f) => upath_1.default.basename(f));
18
+ config.projects.forEach((project) => {
19
+ project.components.forEach((c) => {
20
+ if (c.renderModuleFilePath.endsWith("ts")) {
21
+ const relFilePath = file_utils_1.findSrcDirPath(context.absoluteSrcDir, c.renderModuleFilePath, existingFiles);
22
+ const absFilePath = upath_1.default.join(context.absoluteSrcDir, relFilePath);
23
+ if (file_utils_1.existsBuffered(absFilePath)) {
24
+ deps_1.logger.info(`rename file from ${absFilePath} to ${absFilePath}x`);
25
+ file_utils_1.renameFileBuffered(absFilePath, `${absFilePath}x`);
26
+ }
27
+ c.renderModuleFilePath = `${c.renderModuleFilePath}x`;
28
+ }
29
+ });
30
+ });
31
+ return config;
32
+ }
33
+ exports.tsToTsx = tsToTsx;
@@ -0,0 +1,2 @@
1
+ import { PlasmicConfig } from "../utils/config-utils";
2
+ export declare function ensureProjectIcons(config: PlasmicConfig): PlasmicConfig;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureProjectIcons = void 0;
4
+ function ensureProjectIcons(config) {
5
+ for (const proj of config.projects) {
6
+ if (!proj.icons) {
7
+ proj.icons = [];
8
+ }
9
+ }
10
+ return config;
11
+ }
12
+ exports.ensureProjectIcons = ensureProjectIcons;
@@ -0,0 +1,2 @@
1
+ import { PlasmicConfig } from "../utils/config-utils";
2
+ export declare function ensureVersion(config: PlasmicConfig): PlasmicConfig;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureVersion = void 0;
4
+ function ensureVersion(config) {
5
+ for (const proj of config.projects) {
6
+ if (!proj.version) {
7
+ proj.version = "latest";
8
+ }
9
+ }
10
+ return config;
11
+ }
12
+ exports.ensureVersion = ensureVersion;
@@ -0,0 +1,2 @@
1
+ import { PlasmicConfig } from "../utils/config-utils";
2
+ export declare function ensureJsBundleThemes(config: PlasmicConfig): PlasmicConfig;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureJsBundleThemes = void 0;
4
+ function ensureJsBundleThemes(config) {
5
+ for (const proj of config.projects) {
6
+ if (!proj.jsBundleThemes) {
7
+ proj.jsBundleThemes = [];
8
+ }
9
+ }
10
+ return config;
11
+ }
12
+ exports.ensureJsBundleThemes = ensureJsBundleThemes;
@@ -0,0 +1,2 @@
1
+ import { PlasmicConfig } from "../utils/config-utils";
2
+ export declare function ensureImageFiles(config: PlasmicConfig): PlasmicConfig;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureImageFiles = void 0;
4
+ function ensureImageFiles(config) {
5
+ if (!config.images) {
6
+ config.images = {
7
+ scheme: "inlined",
8
+ };
9
+ }
10
+ for (const proj of config.projects) {
11
+ if (!proj.images) {
12
+ proj.images = [];
13
+ }
14
+ }
15
+ return config;
16
+ }
17
+ exports.ensureImageFiles = ensureImageFiles;
@@ -0,0 +1,2 @@
1
+ import { PlasmicConfig } from "../utils/config-utils";
2
+ export declare function ensureComponentType(config: PlasmicConfig): PlasmicConfig;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureComponentType = void 0;
4
+ function ensureComponentType(config) {
5
+ for (const project of config.projects) {
6
+ for (const component of project.components) {
7
+ if (component.componentType) {
8
+ continue;
9
+ }
10
+ const [_, componentPath] = component.importSpec.modulePath.split(/pages/);
11
+ component.componentType = componentPath ? "page" : "component";
12
+ }
13
+ }
14
+ return config;
15
+ }
16
+ exports.ensureComponentType = ensureComponentType;
@@ -0,0 +1,10 @@
1
+ import { PlasmicConfig, PlasmicLock } from "../utils/config-utils";
2
+ export interface MigrateContext {
3
+ absoluteSrcDir: string;
4
+ }
5
+ declare type MigrateConfigFunc = (prev: PlasmicConfig, context: MigrateContext) => PlasmicConfig;
6
+ declare type MigrateLockFunc = (prev: PlasmicLock, context: MigrateContext) => PlasmicLock;
7
+ export declare const MIGRATIONS: Record<string, MigrateConfigFunc>;
8
+ export declare const LOCK_MIGRATIONS: Record<string, MigrateLockFunc>;
9
+ export declare function runNecessaryMigrations(configFile: string, lockFile: string, baseDir: string, yes?: boolean): Promise<void>;
10
+ export {};
@@ -0,0 +1,119 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.runNecessaryMigrations = exports.LOCK_MIGRATIONS = exports.MIGRATIONS = void 0;
16
+ /**
17
+ * Super simple migration framework for cli.
18
+ *
19
+ * If you want to run some migration script (say, to fix up the schema of plasmic.json, etc),
20
+ * you should:
21
+ *
22
+ * 1. Bump your cli version.
23
+ * 2. Add a [version]-[desc].ts file to the migrations folder, exporting a function that takes
24
+ * the previous version of plasmic.json (or plasmic.lock) blob, and returns the new version
25
+ * of plasmic.json (or plasmic.lock) blob.
26
+ * 3. Add the migration function to the MIGRATIONS (or LOCK_MIGRATIONS) dict in this file.
27
+ *
28
+ * The framework will run migrations in sequence, so you are guaranteed that the plasmic.json blob
29
+ * passed into your migration function is valid as of the previous version.
30
+ */
31
+ const chalk_1 = __importDefault(require("chalk"));
32
+ const lodash_1 = __importDefault(require("lodash"));
33
+ const semver_1 = __importDefault(require("semver"));
34
+ const upath_1 = __importDefault(require("upath"));
35
+ const deps_1 = require("../deps");
36
+ const config_utils_1 = require("../utils/config-utils");
37
+ const error_1 = require("../utils/error");
38
+ const file_utils_1 = require("../utils/file-utils");
39
+ const npm_utils_1 = require("../utils/npm-utils");
40
+ const user_utils_1 = require("../utils/user-utils");
41
+ const _0_1_110_fileLocks_1 = require("./0.1.110-fileLocks");
42
+ const _0_1_146_addReactRuntime_1 = require("./0.1.146-addReactRuntime");
43
+ const _0_1_27_migrateInit_1 = require("./0.1.27-migrateInit");
44
+ const _0_1_28_tsToTsx_1 = require("./0.1.28-tsToTsx");
45
+ const _0_1_31_ensureProjectIcons_1 = require("./0.1.31-ensureProjectIcons");
46
+ const _0_1_42_ensureVersion_1 = require("./0.1.42-ensureVersion");
47
+ const _0_1_57_ensureJsBundleThemes_1 = require("./0.1.57-ensureJsBundleThemes");
48
+ const _0_1_64_imageFiles_1 = require("./0.1.64-imageFiles");
49
+ const _0_1_95_componentType_1 = require("./0.1.95-componentType");
50
+ exports.MIGRATIONS = {
51
+ "0.1.27": _0_1_27_migrateInit_1.migrateInit,
52
+ "0.1.28": _0_1_28_tsToTsx_1.tsToTsx,
53
+ "0.1.31": _0_1_31_ensureProjectIcons_1.ensureProjectIcons,
54
+ "0.1.42": _0_1_42_ensureVersion_1.ensureVersion,
55
+ "0.1.57": _0_1_57_ensureJsBundleThemes_1.ensureJsBundleThemes,
56
+ "0.1.64": _0_1_64_imageFiles_1.ensureImageFiles,
57
+ "0.1.95": _0_1_95_componentType_1.ensureComponentType,
58
+ "0.1.146": _0_1_146_addReactRuntime_1.ensureReactRuntime,
59
+ };
60
+ exports.LOCK_MIGRATIONS = {
61
+ "0.1.110": _0_1_110_fileLocks_1.ensureFileLocks,
62
+ };
63
+ function runNecessaryMigrations(configFile, lockFile, baseDir, yes) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ const cliVersion = npm_utils_1.getCliVersion();
66
+ // If we don't have a lock file, we don't need to run migrations on it!
67
+ const maybeReadLock = () => {
68
+ if (file_utils_1.existsBuffered(lockFile)) {
69
+ return JSON.parse(file_utils_1.readFileText(lockFile));
70
+ }
71
+ return undefined;
72
+ };
73
+ const cur = config_utils_1.readConfig(configFile, false);
74
+ const curVersion = cur.cliVersion;
75
+ if (!!curVersion && semver_1.default.lt(cliVersion, curVersion)) {
76
+ const confirm = yield user_utils_1.confirmWithUser(`Project requires @plasmicapp/cli>=${curVersion} (You currently have ${cliVersion}). Would you like to upgrade it?`, yes);
77
+ if (!confirm) {
78
+ throw new error_1.HandledError("Upgrading is required to continue.");
79
+ }
80
+ const success = npm_utils_1.installUpgrade("@plasmicapp/cli", baseDir, {
81
+ global: npm_utils_1.isCliGloballyInstalled(upath_1.default.dirname(configFile)),
82
+ dev: true,
83
+ });
84
+ deps_1.logger.info(chalk_1.default.bold("@plasmicapp/cli has been upgraded; please try again!"));
85
+ throw new error_1.HandledError(success ? "" : "Error upgrading @plasmicapp/cli");
86
+ }
87
+ const context = {
88
+ absoluteSrcDir: upath_1.default.isAbsolute(cur.srcDir)
89
+ ? cur.srcDir
90
+ : upath_1.default.resolve(upath_1.default.dirname(configFile), cur.srcDir),
91
+ };
92
+ const greaterVersions = semver_1.default.sort([...lodash_1.default.keys(exports.MIGRATIONS), ...lodash_1.default.keys(exports.LOCK_MIGRATIONS)].filter((v) => !curVersion || semver_1.default.gt(v, curVersion)));
93
+ for (const version of greaterVersions) {
94
+ deps_1.logger.info(`Migrating to plasmic.json version ${version}`);
95
+ const migrationFunc = exports.MIGRATIONS[version];
96
+ if (migrationFunc !== undefined) {
97
+ const prev = config_utils_1.readConfig(configFile, false);
98
+ const next = migrationFunc(prev, context);
99
+ next.cliVersion = version;
100
+ yield config_utils_1.writeConfig(configFile, next, baseDir);
101
+ }
102
+ const lockMigrationFunc = exports.LOCK_MIGRATIONS[version];
103
+ if (lockMigrationFunc !== undefined) {
104
+ const prev = maybeReadLock();
105
+ if (prev) {
106
+ const next = lockMigrationFunc(prev, context);
107
+ yield config_utils_1.writeLock(lockFile, next, baseDir);
108
+ }
109
+ }
110
+ }
111
+ // Finally, stamp the latest version
112
+ const latestConfig = config_utils_1.readConfig(configFile, false);
113
+ if (latestConfig.cliVersion !== cliVersion) {
114
+ latestConfig.cliVersion = cliVersion;
115
+ yield config_utils_1.writeConfig(configFile, latestConfig, baseDir);
116
+ }
117
+ });
118
+ }
119
+ exports.runNecessaryMigrations = runNecessaryMigrations;