@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
@@ -0,0 +1,339 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ var __importDefault = (this && this.__importDefault) || function (mod) {
31
+ return (mod && mod.__esModule) ? mod : { "default": mod };
32
+ };
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ exports.setMetadataEnv = exports.generateMetadata = exports.getContext = exports.readLock = void 0;
35
+ const Sentry = __importStar(require("@sentry/node"));
36
+ const lodash_1 = __importDefault(require("lodash"));
37
+ const querystring = __importStar(require("querystring"));
38
+ const upath_1 = __importDefault(require("upath"));
39
+ const init_1 = require("../actions/init");
40
+ const api_1 = require("../api");
41
+ const deps_1 = require("../deps");
42
+ const migrations_1 = require("../migrations/migrations");
43
+ const error_1 = require("../utils/error");
44
+ const auth_utils_1 = require("./auth-utils");
45
+ const config_utils_1 = require("./config-utils");
46
+ const file_utils_1 = require("./file-utils");
47
+ const lang_utils_1 = require("./lang-utils");
48
+ const npm_utils_1 = require("./npm-utils");
49
+ const prompts = __importStar(require("./prompts"));
50
+ function createPlasmicLock() {
51
+ return {
52
+ projects: [],
53
+ cliVersion: npm_utils_1.getCliVersion(),
54
+ };
55
+ }
56
+ function readLock(lockFile) {
57
+ if (!file_utils_1.existsBuffered(lockFile)) {
58
+ return createPlasmicLock();
59
+ }
60
+ try {
61
+ const result = JSON.parse(file_utils_1.readFileText(lockFile));
62
+ return Object.assign({}, result);
63
+ }
64
+ catch (e) {
65
+ deps_1.logger.error(`Error encountered reading ${config_utils_1.LOCK_FILE_NAME} at ${lockFile}: ${e}`);
66
+ throw e;
67
+ }
68
+ }
69
+ exports.readLock = readLock;
70
+ function removeMissingFilesFromLock(context, config, lock) {
71
+ const knownProjects = Object.fromEntries(config.projects.map((project) => [project.projectId, project]));
72
+ const knownGlobalVariants = Object.fromEntries(context.config.globalVariants.variantGroups.map((vg) => [vg.projectId, vg]));
73
+ lock.projects = lock.projects
74
+ .filter((project) => knownProjects[project.projectId])
75
+ .map((project) => {
76
+ const knownComponents = Object.fromEntries(knownProjects[project.projectId].components.map((component) => [
77
+ component.id,
78
+ component,
79
+ ]));
80
+ const knownImages = Object.fromEntries(knownProjects[project.projectId].images.map((image) => [
81
+ image.id,
82
+ image,
83
+ ]));
84
+ const knownIcons = Object.fromEntries(knownProjects[project.projectId].images.map((icons) => [
85
+ icons.id,
86
+ icons,
87
+ ]));
88
+ project.fileLocks = project.fileLocks.filter((lock) => {
89
+ switch (lock.type) {
90
+ default:
91
+ return false;
92
+ case "projectCss":
93
+ return knownProjects[project.projectId].cssFilePath;
94
+ case "globalVariant":
95
+ return knownGlobalVariants[project.projectId];
96
+ case "cssRules":
97
+ case "renderModule":
98
+ return knownComponents[lock.assetId];
99
+ case "image":
100
+ return knownImages[lock.assetId];
101
+ case "icon":
102
+ return knownIcons[lock.assetId];
103
+ }
104
+ });
105
+ return project;
106
+ });
107
+ }
108
+ function attemptToRestoreFilePath(context, expectedPath, baseNameToFiles) {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ // If the path is not set, always recreate.
111
+ if (expectedPath === "") {
112
+ return undefined;
113
+ }
114
+ if (file_utils_1.fileExists(context, expectedPath)) {
115
+ return expectedPath;
116
+ }
117
+ const fileName = upath_1.default.basename(expectedPath);
118
+ if (!baseNameToFiles[fileName]) {
119
+ const answer = yield prompts.askChoice({
120
+ message: `File ${upath_1.default.join(context.absoluteSrcDir, expectedPath)} not found. Do you want to recreate it?`,
121
+ choices: ["Yes", "No"],
122
+ defaultAnswer: "Yes",
123
+ hidePrompt: context.cliArgs.yes,
124
+ });
125
+ if (answer === "No") {
126
+ throw new error_1.HandledError("Please add this file or update your plasmic.json by removing or changing this path and try again.");
127
+ }
128
+ return undefined;
129
+ }
130
+ if (baseNameToFiles[fileName].length === 1) {
131
+ const newPath = upath_1.default.relative(context.absoluteSrcDir, baseNameToFiles[fileName][0]);
132
+ deps_1.logger.info(`\tDetected file moved from ${expectedPath} to ${newPath}.`);
133
+ return newPath;
134
+ }
135
+ // Multiple files
136
+ const none = "None.";
137
+ const answer = yield prompts.askChoice({
138
+ message: `Cannot find expected file at ${expectedPath}. Please select one of the following matches:`,
139
+ choices: [...baseNameToFiles[fileName], none],
140
+ defaultAnswer: none,
141
+ hidePrompt: context.cliArgs.yes,
142
+ });
143
+ if (answer === none) {
144
+ throw new error_1.HandledError("Please add this file or update your plasmic.json by removing or changing this path and try again.");
145
+ }
146
+ return answer;
147
+ });
148
+ }
149
+ function resolveMissingFilesInConfig(context, config) {
150
+ return __awaiter(this, void 0, void 0, function* () {
151
+ const baseNameToFiles = file_utils_1.buildBaseNameToFiles(context);
152
+ // Make sure all the files exist. Prompt the user / exit process if not.
153
+ function filterFiles(list, pathProp) {
154
+ return __awaiter(this, void 0, void 0, function* () {
155
+ const newList = [];
156
+ for (const item of list) {
157
+ const newPath = yield attemptToRestoreFilePath(context, item[pathProp], baseNameToFiles);
158
+ if (newPath) {
159
+ item[pathProp] = newPath;
160
+ newList.push(item);
161
+ }
162
+ }
163
+ return newList;
164
+ });
165
+ }
166
+ context.config.globalVariants.variantGroups = yield filterFiles(context.config.globalVariants.variantGroups, "contextFilePath");
167
+ context.config.style.defaultStyleCssFilePath =
168
+ (yield attemptToRestoreFilePath(context, context.config.style.defaultStyleCssFilePath, baseNameToFiles)) || "";
169
+ for (const project of config.projects) {
170
+ project.cssFilePath =
171
+ (yield attemptToRestoreFilePath(context, project.cssFilePath, baseNameToFiles)) || "";
172
+ project.images = yield filterFiles(project.images, "filePath");
173
+ project.icons = yield filterFiles(project.icons, "moduleFilePath");
174
+ project.jsBundleThemes = yield filterFiles(project.jsBundleThemes || [], "themeFilePath");
175
+ // For components, if they decide to recreate in any of the path (css, wrapper, or blackbox component)
176
+ // we'll delete existing files.
177
+ const newComponents = [];
178
+ for (const component of project.components) {
179
+ if (component.type === "mapped") {
180
+ // For components mapped to an external module, we skip restoring files on disk
181
+ newComponents.push(component);
182
+ continue;
183
+ }
184
+ const newModulePath = yield attemptToRestoreFilePath(context, component.importSpec.modulePath, baseNameToFiles);
185
+ if (!newModulePath) {
186
+ continue;
187
+ }
188
+ const newRenderModulePath = yield attemptToRestoreFilePath(context, component.renderModuleFilePath, baseNameToFiles);
189
+ if (!newRenderModulePath) {
190
+ continue;
191
+ }
192
+ const newCssPath = yield attemptToRestoreFilePath(context, component.cssFilePath, baseNameToFiles);
193
+ if (!newCssPath) {
194
+ continue;
195
+ }
196
+ component.importSpec.modulePath = newModulePath;
197
+ component.renderModuleFilePath = newRenderModulePath;
198
+ component.cssFilePath = newCssPath;
199
+ newComponents.push(component);
200
+ }
201
+ project.components = newComponents;
202
+ }
203
+ });
204
+ }
205
+ function getContext(args, { enableSkipAuth = false } = {}) {
206
+ return __awaiter(this, void 0, void 0, function* () {
207
+ if (!args.baseDir)
208
+ args.baseDir = process.cwd();
209
+ const auth = enableSkipAuth
210
+ ? yield getCurrentOrDefaultAuth(args)
211
+ : yield getOrInitAuth(args);
212
+ /** Sentry */
213
+ if (auth.host.startsWith(config_utils_1.DEFAULT_HOST)) {
214
+ // Production usage of cli
215
+ Sentry.init({
216
+ dsn: "https://3ed4eb43d28646e381bf3c50cff24bd6@o328029.ingest.sentry.io/5285892",
217
+ });
218
+ Sentry.configureScope((scope) => {
219
+ if (auth.user) {
220
+ scope.setUser({ email: auth.user });
221
+ }
222
+ scope.setExtra("cliVersion", npm_utils_1.getCliVersion());
223
+ scope.setExtra("args", JSON.stringify(args));
224
+ scope.setExtra("host", auth.host);
225
+ });
226
+ }
227
+ /** PlasmicConfig **/
228
+ let configFile = args.config || config_utils_1.findConfigFile(args.baseDir, { traverseParents: true });
229
+ if (!configFile) {
230
+ yield maybeRunPlasmicInit(args, "plasmic.json", enableSkipAuth);
231
+ configFile = config_utils_1.findConfigFile(args.baseDir, { traverseParents: true });
232
+ if (!configFile) {
233
+ const err = new error_1.HandledError("No plasmic.json file found. Please run `plasmic init` first.");
234
+ throw err;
235
+ }
236
+ }
237
+ const rootDir = upath_1.default.dirname(configFile);
238
+ // plasmic.lock should be in the same directory as plasmic.json
239
+ const lockFile = upath_1.default.join(rootDir, config_utils_1.LOCK_FILE_NAME);
240
+ yield migrations_1.runNecessaryMigrations(configFile, lockFile, args.baseDir, args.yes);
241
+ const config = config_utils_1.readConfig(configFile, true);
242
+ /** PlasmicLock */
243
+ const lock = readLock(lockFile);
244
+ const context = {
245
+ config,
246
+ configFile,
247
+ lock,
248
+ lockFile,
249
+ rootDir,
250
+ absoluteSrcDir: upath_1.default.isAbsolute(config.srcDir)
251
+ ? config.srcDir
252
+ : upath_1.default.resolve(rootDir, config.srcDir),
253
+ auth,
254
+ api: new api_1.PlasmicApi(auth),
255
+ cliArgs: args,
256
+ };
257
+ yield resolveMissingFilesInConfig(context, config);
258
+ removeMissingFilesFromLock(context, config, lock);
259
+ return context;
260
+ });
261
+ }
262
+ exports.getContext = getContext;
263
+ /**
264
+ * Use empty user/token to signify no auth (only returning to provide a default host).
265
+ */
266
+ function getCurrentOrDefaultAuth(args) {
267
+ return __awaiter(this, void 0, void 0, function* () {
268
+ const auth = yield auth_utils_1.getCurrentAuth(args.auth);
269
+ if (auth) {
270
+ return auth;
271
+ }
272
+ return {
273
+ host: config_utils_1.DEFAULT_HOST,
274
+ user: "",
275
+ token: "",
276
+ };
277
+ });
278
+ }
279
+ function getOrInitAuth(args) {
280
+ return __awaiter(this, void 0, void 0, function* () {
281
+ const auth = yield auth_utils_1.getCurrentAuth(args.auth);
282
+ if (auth) {
283
+ return auth;
284
+ }
285
+ if (yield maybeRunPlasmicInit(args, ".plasmic.auth")) {
286
+ return lang_utils_1.ensure(yield auth_utils_1.getCurrentAuth());
287
+ }
288
+ // Could not find the authentication credentials and the user
289
+ // declined to run plasmic init.
290
+ throw new error_1.HandledError("Could not authenticate.");
291
+ });
292
+ }
293
+ function maybeRunPlasmicInit(args, missingFile, enableSkipAuth) {
294
+ return __awaiter(this, void 0, void 0, function* () {
295
+ if (!process.env.QUIET) {
296
+ deps_1.logger.info(`No ${missingFile} file found. Initializing plasmic...`);
297
+ }
298
+ yield init_1.initPlasmic(Object.assign({ host: config_utils_1.DEFAULT_HOST, platform: "", codeLang: "", codeScheme: "", styleScheme: "", imagesScheme: "", srcDir: "", plasmicDir: "", imagesPublicDir: "", imagesPublicUrlPrefix: "", enableSkipAuth }, args));
299
+ return true;
300
+ });
301
+ }
302
+ /**
303
+ * Create a metadata bundle
304
+ * This will be used to tag Segment events (e.g. for codegen)
305
+ * Merges in:
306
+ * 1. defaults
307
+ * 2. PLASMIC_METADATA environment variable settings
308
+ * 3. arguments from the command-line
309
+ * to create a single Metadata object for Segment
310
+ * @param defaults
311
+ * @param fromArgs
312
+ */
313
+ function generateMetadata(defaults, fromArgs) {
314
+ const fromEnv = process.env.PLASMIC_METADATA;
315
+ const metadataFromEnv = !fromEnv ? {} : Object.assign({}, querystring.decode(fromEnv));
316
+ const metadataFromArgs = !fromArgs ? {} : Object.assign({}, querystring.decode(fromArgs));
317
+ // Priority: 1. args 2. env 3. defaults
318
+ const metadata = lodash_1.default.assign(Object.assign({}, defaults), metadataFromEnv, metadataFromArgs);
319
+ return metadata;
320
+ }
321
+ exports.generateMetadata = generateMetadata;
322
+ /**
323
+ * This is meant to be called from consumers of the CLI to set
324
+ * metadata into the PLASMIC_METADATA environment variable
325
+ * @param metadata
326
+ */
327
+ function setMetadataEnv(metadata) {
328
+ const fromEnv = process.env.PLASMIC_METADATA
329
+ ? querystring.decode(process.env.PLASMIC_METADATA)
330
+ : {};
331
+ const env = Object.assign({}, fromEnv);
332
+ lodash_1.default.toPairs(metadata).forEach(([k, v]) => {
333
+ if (!env[k]) {
334
+ env[k] = v;
335
+ }
336
+ });
337
+ process.env.PLASMIC_METADATA = querystring.encode(env);
338
+ }
339
+ exports.setMetadataEnv = setMetadataEnv;
@@ -0,0 +1,2 @@
1
+ import { PlasmicContext } from "./config-utils";
2
+ export declare function printFirstSyncInfo(context: PlasmicContext): void;
@@ -0,0 +1,56 @@
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.printFirstSyncInfo = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ const wrap_ansi_1 = __importDefault(require("wrap-ansi"));
10
+ const deps_1 = require("../deps");
11
+ const lang_utils_1 = require("./lang-utils");
12
+ function wrap(str) {
13
+ return wrap_ansi_1.default(str, 60);
14
+ }
15
+ function printFirstSyncInfo(context) {
16
+ const config = context.config;
17
+ if (config.code.scheme === "blackbox" && config.projects.length > 0) {
18
+ const project = lang_utils_1.ensure(lodash_1.default.last(config.projects));
19
+ deps_1.logger.info(`\nYour Plasmic project "${project.projectName}" has now been synced to disk.`);
20
+ const exampleComponent = project.components[0];
21
+ if (exampleComponent) {
22
+ deps_1.logger.info(`
23
+
24
+ ${chalk_1.default.bold("Using Plasmic Components")}
25
+ ${chalk_1.default.bold("------------------------")}
26
+
27
+ ${wrap(`For each component, Plasmic generates two React components in two files. For example, for component ${chalk_1.default.bold(exampleComponent.name)}, there are:`)}
28
+
29
+ * A ${chalk_1.default.bold("blackbox")} component at ${chalk_1.default.bold.underline(exampleComponent.renderModuleFilePath)}
30
+ ${wrap(`This is a blackbox, purely-presentational library component that you can use to render your designs. This file is owned by Plasmic, and you should not edit it -- it will be overwritten when the component design is updated. This component should only be used by the "wrapper" component (below).`)}
31
+
32
+ * A ${chalk_1.default.bold("wrapper")} component at ${chalk_1.default.bold.underline(exampleComponent.importSpec.modulePath)}
33
+ ${wrap(`This component is owned and edited by you to instantiate the Plasmic${exampleComponent.name} component with desired variants, states, event handlers, and data. You have complete control over this file, and this is the actual component that should be used by the rest of the codebase.`)}
34
+
35
+ Learn more at https://www.plasmic.app/learn/codegen-guide/
36
+ `);
37
+ }
38
+ const exampleIcon = project.icons[0];
39
+ if (exampleIcon) {
40
+ deps_1.logger.info(`
41
+ ${chalk_1.default.bold("Using Icons")}
42
+ ${chalk_1.default.bold("-----------")}
43
+
44
+ ${wrap(`For each SVG icon, Plasmic also generates a React component. The component takes in all the usual props that you can pass to an svg element, and defaults to width/height of 1em.`)}
45
+
46
+ For example, for the ${chalk_1.default.bold(exampleIcon.name)} icon at ${chalk_1.default.bold.underline(exampleIcon.moduleFilePath)},
47
+ instantiate it like:
48
+
49
+ ${chalk_1.default.green(`<${exampleIcon.name} color="red" />`)}
50
+
51
+ Learn more at https://www.plasmic.app/learn/other-assets/#icons
52
+ `);
53
+ }
54
+ }
55
+ }
56
+ exports.printFirstSyncInfo = printFirstSyncInfo;
@@ -0,0 +1,10 @@
1
+ declare type StringGen = string | (() => string);
2
+ export declare function flatMap<T, U>(arr: T[], f: (x: T) => U[]): U[];
3
+ export declare function ensure<T>(x: T | null | undefined, msg?: StringGen): T;
4
+ export declare function ensureString(x: any): string;
5
+ export declare class AssertionError extends Error {
6
+ constructor(msg?: string);
7
+ }
8
+ export declare function assert<T>(cond: T, msg?: StringGen): asserts cond;
9
+ export declare const tuple: <T extends any[]>(...args: T) => T;
10
+ export {};
@@ -0,0 +1,52 @@
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.tuple = exports.assert = exports.AssertionError = exports.ensureString = exports.ensure = exports.flatMap = void 0;
7
+ const lodash_1 = __importDefault(require("lodash"));
8
+ function flatMap(arr, f) {
9
+ const r = [];
10
+ for (const x of arr) {
11
+ r.push(...f(x));
12
+ }
13
+ return r;
14
+ }
15
+ exports.flatMap = flatMap;
16
+ function ensure(x, msg = "") {
17
+ if (x === null || x === undefined) {
18
+ debugger;
19
+ msg = (lodash_1.default.isString(msg) ? msg : msg()) || "";
20
+ throw new Error(`Value must not be undefined or null${msg ? `- ${msg}` : ""}`);
21
+ }
22
+ else {
23
+ return x;
24
+ }
25
+ }
26
+ exports.ensure = ensure;
27
+ function ensureString(x) {
28
+ if (lodash_1.default.isString(x)) {
29
+ return x;
30
+ }
31
+ else {
32
+ throw new Error(`Expected ${x} to be a string`);
33
+ }
34
+ }
35
+ exports.ensureString = ensureString;
36
+ class AssertionError extends Error {
37
+ constructor(msg = "Assertion failed") {
38
+ super(msg);
39
+ }
40
+ }
41
+ exports.AssertionError = AssertionError;
42
+ function assert(cond, msg = "Assertion failed") {
43
+ if (!cond) {
44
+ // We always generate an non empty message so that it doesn't get swallowed
45
+ // by the async library.
46
+ msg = (lodash_1.default.isString(msg) ? msg : msg()) || "Assertion failed";
47
+ debugger;
48
+ throw new AssertionError(msg);
49
+ }
50
+ }
51
+ exports.assert = assert;
52
+ exports.tuple = (...args) => args;
@@ -0,0 +1,28 @@
1
+ import { PlasmicContext } from "./config-utils";
2
+ export declare function getParsedCliPackageJson(): any;
3
+ export declare function getCliVersion(): string;
4
+ /**
5
+ * Call this to check if we match the engine policy
6
+ */
7
+ export declare function checkEngineStrict(): boolean;
8
+ export declare function getParsedPackageJson(): any;
9
+ export declare function warnLatest(context: PlasmicContext, pkg: string, baseDir: string, msgs: {
10
+ requiredMsg: () => string;
11
+ updateMsg: (curVersion: string, latestVersion: string) => string;
12
+ }, yes?: boolean): Promise<void>;
13
+ export declare function findInstalledVersion(context: PlasmicContext, pkg: string): string | undefined;
14
+ /**
15
+ * Detects if the cli is globally installed. `rootDir` is the folder
16
+ * where plasmic.json is
17
+ */
18
+ export declare function isCliGloballyInstalled(rootDir: string): boolean;
19
+ export declare function findPackageJsonDir(rootDir: string): string | undefined;
20
+ export declare function installUpgrade(pkg: string, baseDir: string, opts?: {
21
+ global?: boolean;
22
+ dev?: boolean;
23
+ }): boolean;
24
+ export declare function installCommand(pkg: string, baseDir: string, opts?: {
25
+ global?: boolean;
26
+ dev?: boolean;
27
+ }): string;
28
+ export declare function detectPackageManager(baseDir: string): "yarn" | "npm";