@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,460 @@
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.getYargsOption = exports.getInitArgsChoices = exports.getInitArgsQuestion = exports.getInitArgsLongDescription = exports.getInitArgsShortDescription = exports.initPlasmic = void 0;
16
+ const chalk_1 = __importDefault(require("chalk"));
17
+ const inquirer_1 = __importDefault(require("inquirer"));
18
+ const lodash_1 = __importDefault(require("lodash"));
19
+ const upath_1 = __importDefault(require("upath"));
20
+ const deps_1 = require("../deps");
21
+ const auth_utils_1 = require("../utils/auth-utils");
22
+ const config_utils_1 = require("../utils/config-utils");
23
+ const envdetect_1 = require("../utils/envdetect");
24
+ const file_utils_1 = require("../utils/file-utils");
25
+ const lang_utils_1 = require("../utils/lang-utils");
26
+ const npm_utils_1 = require("../utils/npm-utils");
27
+ const user_utils_1 = require("../utils/user-utils");
28
+ function initPlasmic(opts) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ if (!opts.baseDir)
31
+ opts.baseDir = process.cwd();
32
+ yield auth_utils_1.getOrStartAuth(opts);
33
+ const configFile = opts.config || config_utils_1.findConfigFile(opts.baseDir, { traverseParents: false });
34
+ if (configFile && file_utils_1.existsBuffered(configFile)) {
35
+ deps_1.logger.error("You already have a plasmic.json file! Please either delete or edit it directly.");
36
+ return;
37
+ }
38
+ // path to plasmic.json
39
+ const newConfigFile = opts.config || upath_1.default.join(opts.baseDir, config_utils_1.CONFIG_FILE_NAME);
40
+ const answers = yield deriveInitAnswers(opts);
41
+ yield config_utils_1.writeConfig(newConfigFile, createInitConfig(answers), opts.baseDir);
42
+ if (!process.env.QUIET) {
43
+ deps_1.logger.info("Successfully created plasmic.json.\n");
44
+ }
45
+ const answer = yield user_utils_1.confirmWithUser("@plasmicapp/react-web is a small runtime required by Plasmic-generated code.\n Do you want to add it now?", opts.yes);
46
+ if (answer) {
47
+ npm_utils_1.installUpgrade("@plasmicapp/react-web", opts.baseDir);
48
+ }
49
+ });
50
+ }
51
+ exports.initPlasmic = initPlasmic;
52
+ function createInitConfig(opts) {
53
+ return config_utils_1.fillDefaults(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ srcDir: opts.srcDir, defaultPlasmicDir: opts.plasmicDir }, (opts.platform === "nextjs" && {
54
+ nextjsConfig: {
55
+ pagesDir: opts.pagesDir,
56
+ },
57
+ })), (opts.platform === "gatsby" && {
58
+ gatsbyConfig: {
59
+ pagesDir: opts.pagesDir,
60
+ },
61
+ })), { code: Object.assign(Object.assign(Object.assign({}, (opts.codeLang && { lang: opts.codeLang })), (opts.codeScheme && { scheme: opts.codeScheme })), (opts.reactRuntime && { reactRuntime: opts.reactRuntime })), style: Object.assign({}, (opts.styleScheme && { scheme: opts.styleScheme })), images: Object.assign(Object.assign(Object.assign({}, (opts.imagesScheme && { scheme: opts.imagesScheme })), (opts.imagesScheme && { publicDir: opts.imagesPublicDir })), (opts.imagesScheme && { publicUrlPrefix: opts.imagesPublicUrlPrefix })) }), (opts.platform && { platform: opts.platform })), { cliVersion: npm_utils_1.getCliVersion() }));
62
+ }
63
+ /**
64
+ * Pretty-print the question along with the default answer, as if that was the choice
65
+ * being made. Don't actually interactively prompt for a response.
66
+ */
67
+ function simulatePrompt(question, defaultAnswer, bold = false) {
68
+ var _a, _b, _c;
69
+ const message = question.message.endsWith(">")
70
+ ? question.message
71
+ : question.message + ">";
72
+ process.stdout.write((bold ? chalk_1.default.bold(message) : message) + " ");
73
+ deps_1.logger.info(chalk_1.default.cyan((_c = (_b = (_a = question.choices) === null || _a === void 0 ? void 0 : _a.call(question).find((choice) => choice.value === defaultAnswer)) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : defaultAnswer));
74
+ }
75
+ function deriveInitAnswers(opts) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ const plasmicRootDir = opts.config ? upath_1.default.dirname(opts.config) : opts.baseDir;
78
+ const platform = !!opts.platform
79
+ ? opts.platform
80
+ : envdetect_1.detectNextJs()
81
+ ? "nextjs"
82
+ : envdetect_1.detectGatsby()
83
+ ? "gatsby"
84
+ : "react";
85
+ const isCra = envdetect_1.detectCreateReactApp();
86
+ const isNext = platform === "nextjs";
87
+ const isGatsby = platform === "gatsby";
88
+ const isGeneric = !isCra && !isNext && !isGatsby;
89
+ const isTypescript = envdetect_1.detectTypescript();
90
+ if (isNext) {
91
+ deps_1.logger.info("Detected Next.js...");
92
+ }
93
+ else if (isGatsby) {
94
+ deps_1.logger.info("Detected Gatsby...");
95
+ }
96
+ else if (isCra) {
97
+ deps_1.logger.info("Detected create-react-app...");
98
+ }
99
+ // Platform-specific defaults that take precedent
100
+ const deriver = isNext
101
+ ? getNextDefaults(plasmicRootDir)
102
+ : isGatsby
103
+ ? getGatsbyDefaults(plasmicRootDir)
104
+ : isCra
105
+ ? getCraDefaults(plasmicRootDir)
106
+ : getGenericDefaults(plasmicRootDir);
107
+ const srcDir = lang_utils_1.ensureString(deriver.srcDir);
108
+ const getDefaultAnswer = (name, defaultAnswer) => {
109
+ // Try to get the user CLI arg override first
110
+ if (opts[name]) {
111
+ return opts[name];
112
+ }
113
+ else if (deriver[name]) {
114
+ // Then get the platform-specific default
115
+ if (lodash_1.default.isFunction(deriver[name])) {
116
+ const fn = deriver[name];
117
+ return fn(srcDir);
118
+ }
119
+ return deriver[name];
120
+ }
121
+ else {
122
+ // Other specified default
123
+ return defaultAnswer;
124
+ }
125
+ };
126
+ // Start with a complete set of defaults. Some of these are not worth displaying.
127
+ const answers = {
128
+ host: getDefaultAnswer("host", ""),
129
+ platform,
130
+ codeLang: getDefaultAnswer("codeLang", isTypescript ? "ts" : "js"),
131
+ codeScheme: getDefaultAnswer("codeScheme", config_utils_1.DEFAULT_CONFIG.code.scheme),
132
+ styleScheme: getDefaultAnswer("styleScheme", config_utils_1.DEFAULT_CONFIG.style.scheme),
133
+ imagesScheme: getDefaultAnswer("imagesScheme", config_utils_1.DEFAULT_CONFIG.images.scheme),
134
+ imagesPublicDir: getDefaultAnswer("imagesPublicDir", lang_utils_1.ensure(config_utils_1.DEFAULT_PUBLIC_FILES_CONFIG.publicDir)),
135
+ imagesPublicUrlPrefix: getDefaultAnswer("imagesPublicUrlPrefix", lang_utils_1.ensure(config_utils_1.DEFAULT_PUBLIC_FILES_CONFIG.publicUrlPrefix)),
136
+ srcDir: getDefaultAnswer("srcDir", config_utils_1.DEFAULT_CONFIG.srcDir),
137
+ plasmicDir: getDefaultAnswer("plasmicDir", config_utils_1.DEFAULT_CONFIG.defaultPlasmicDir),
138
+ pagesDir: getDefaultAnswer("pagesDir", undefined),
139
+ reactRuntime: getDefaultAnswer("reactRuntime", "classic"),
140
+ };
141
+ const prominentAnswers = lodash_1.default.omit(answers, "codeScheme");
142
+ if (process.env.QUIET) {
143
+ return answers;
144
+ }
145
+ deps_1.logger.info(chalk_1.default.bold("Plasmic Express Setup -- Here are the default settings we recommend:\n"));
146
+ yield performAsks(true);
147
+ // Allow a user to short-circuit
148
+ const useExpressQuestion = {
149
+ name: "continue",
150
+ message: `Would you like to accept these defaults?`,
151
+ type: "list",
152
+ choices: () => [
153
+ {
154
+ value: "yes",
155
+ name: "Accept these defaults",
156
+ },
157
+ {
158
+ value: "no",
159
+ name: "Customize the choices",
160
+ },
161
+ ],
162
+ };
163
+ deps_1.logger.info("");
164
+ if (opts.yes) {
165
+ simulatePrompt(useExpressQuestion, "yes", true);
166
+ return answers;
167
+ }
168
+ else {
169
+ const useExpress = yield inquirer_1.default.prompt([useExpressQuestion]);
170
+ if (useExpress.continue === "yes") {
171
+ return answers;
172
+ }
173
+ }
174
+ /**
175
+ * @param express When true, we pretty-print the question along with the default answer, as if that was the choice
176
+ * being made. This is for displaying the default choices in the express setup.
177
+ */
178
+ function performAsks(express) {
179
+ return __awaiter(this, void 0, void 0, function* () {
180
+ // Proceed with platform-specific prompts
181
+ function maybePrompt(question) {
182
+ return __awaiter(this, void 0, void 0, function* () {
183
+ const name = lang_utils_1.ensure(question.name);
184
+ const message = lang_utils_1.ensure(question.message);
185
+ if (opts[name]) {
186
+ deps_1.logger.info(message + answers[name] + "(specified in CLI arg)");
187
+ }
188
+ else if (express) {
189
+ const defaultAnswer = answers[name];
190
+ simulatePrompt(question, defaultAnswer);
191
+ }
192
+ else if (!opts.yes && !deriver.alwaysDerived.includes(name)) {
193
+ const ans = yield inquirer_1.default.prompt(Object.assign(Object.assign({}, question), { default: answers[name] }));
194
+ // Not sure why TS complains here without this cast.
195
+ answers[name] = ans[name];
196
+ }
197
+ // Other questions are silently skipped
198
+ });
199
+ }
200
+ yield maybePrompt({
201
+ name: "srcDir",
202
+ message: `${getInitArgsQuestion("srcDir")}\n>`,
203
+ });
204
+ yield maybePrompt({
205
+ name: "plasmicDir",
206
+ message: `${getInitArgsQuestion("plasmicDir")} (This is relative to "${answers.srcDir}")\n>`,
207
+ });
208
+ if (config_utils_1.isPageAwarePlatform(platform)) {
209
+ yield maybePrompt({
210
+ name: "pagesDir",
211
+ message: `${getInitArgsQuestion("pagesDir")} (This is relative to "${answers.srcDir}")\n>`,
212
+ });
213
+ }
214
+ yield maybePrompt({
215
+ name: "codeLang",
216
+ message: `${getInitArgsQuestion("codeLang")}\n`,
217
+ type: "list",
218
+ choices: () => [
219
+ {
220
+ name: `Typescript${isTypescript ? " (tsconfig.json detected)" : ""}`,
221
+ value: "ts",
222
+ },
223
+ {
224
+ name: `Javascript${!isTypescript ? " (no tsconfig.json detected)" : ""}`,
225
+ value: "js",
226
+ },
227
+ ],
228
+ });
229
+ yield maybePrompt({
230
+ name: "styleScheme",
231
+ message: `${getInitArgsQuestion("styleScheme")}\n`,
232
+ type: "list",
233
+ choices: () => [
234
+ {
235
+ name: `CSS modules, imported as "import sty from './plasmic.module.css'"`,
236
+ value: "css-modules",
237
+ },
238
+ {
239
+ name: `Plain CSS stylesheets, imported as "import './plasmic.css'"`,
240
+ value: "css",
241
+ },
242
+ ],
243
+ });
244
+ yield maybePrompt({
245
+ name: "imagesScheme",
246
+ message: `${getInitArgsQuestion("imagesScheme")}\n`,
247
+ type: "list",
248
+ choices: () => [
249
+ {
250
+ name: `Imported as files, like "import img from './image.png'". ${isGeneric ? "Not all bundlers support this." : ""}`,
251
+ value: "files",
252
+ },
253
+ {
254
+ name: `Images stored in a public folder, referenced like <img src="/static/image.png"/>`,
255
+ value: "public-files",
256
+ },
257
+ {
258
+ name: `Inlined as base64-encoded data URIs`,
259
+ value: "inlined",
260
+ },
261
+ ],
262
+ });
263
+ if (answers.imagesScheme === "public-files") {
264
+ yield maybePrompt({
265
+ name: "imagesPublicDir",
266
+ message: `${getInitArgsQuestion("imagesPublicDir")} (This is relative to "${answers.srcDir}")\n>`,
267
+ });
268
+ yield maybePrompt({
269
+ name: "imagesPublicUrlPrefix",
270
+ message: `${getInitArgsQuestion("imagesPublicUrlPrefix")} ${isNext ? `(for Next.js, this is usually "/")` : ""}\n>`,
271
+ });
272
+ }
273
+ });
274
+ }
275
+ yield performAsks(false);
276
+ return answers;
277
+ });
278
+ }
279
+ function getNextDefaults(plasmicRootDir) {
280
+ var _a;
281
+ const projectRootDir = (_a = npm_utils_1.findPackageJsonDir(plasmicRootDir)) !== null && _a !== void 0 ? _a : plasmicRootDir;
282
+ return {
283
+ srcDir: upath_1.default.relative(plasmicRootDir, upath_1.default.join(projectRootDir, "components")),
284
+ pagesDir: (srcDir) => upath_1.default.relative(upath_1.default.join(plasmicRootDir, srcDir), upath_1.default.join(projectRootDir, "pages")),
285
+ styleScheme: "css-modules",
286
+ imagesScheme: "public-files",
287
+ imagesPublicDir: (srcDir) => upath_1.default.relative(upath_1.default.join(plasmicRootDir, srcDir), upath_1.default.join(projectRootDir, "public")),
288
+ imagesPublicUrlPrefix: "/",
289
+ alwaysDerived: [
290
+ "styleScheme",
291
+ "imagesScheme",
292
+ "imagesPublicDir",
293
+ "pagesDir",
294
+ ],
295
+ };
296
+ }
297
+ function getGatsbyDefaults(plasmicRootDir) {
298
+ var _a;
299
+ const projectRootDir = (_a = npm_utils_1.findPackageJsonDir(plasmicRootDir)) !== null && _a !== void 0 ? _a : plasmicRootDir;
300
+ return {
301
+ srcDir: upath_1.default.relative(plasmicRootDir, upath_1.default.join(projectRootDir, "src", "components")),
302
+ pagesDir: (srcDir) => {
303
+ const absSrcDir = upath_1.default.join(plasmicRootDir, srcDir);
304
+ const absPagesDir = upath_1.default.join(projectRootDir, "src", "pages");
305
+ const relDir = upath_1.default.relative(absSrcDir, absPagesDir);
306
+ return relDir;
307
+ },
308
+ styleScheme: "css-modules",
309
+ imagesScheme: "files",
310
+ imagesPublicDir: (srcDir) => upath_1.default.relative(upath_1.default.join(plasmicRootDir, srcDir), upath_1.default.join(projectRootDir, "static")),
311
+ imagesPublicUrlPrefix: "/",
312
+ alwaysDerived: ["imagesScheme", "pagesDir"],
313
+ };
314
+ }
315
+ function getCraDefaults(plasmicRootDir) {
316
+ var _a;
317
+ const projectRootDir = (_a = npm_utils_1.findPackageJsonDir(plasmicRootDir)) !== null && _a !== void 0 ? _a : plasmicRootDir;
318
+ return {
319
+ srcDir: upath_1.default.relative(plasmicRootDir, upath_1.default.join(projectRootDir, "src", "components")),
320
+ styleScheme: "css-modules",
321
+ imagesScheme: "files",
322
+ imagesPublicDir: (srcDir) => upath_1.default.relative(upath_1.default.join(plasmicRootDir, srcDir), upath_1.default.join(projectRootDir, "public")),
323
+ alwaysDerived: [],
324
+ };
325
+ }
326
+ function getGenericDefaults(plasmicRootDir) {
327
+ var _a;
328
+ const projectRootDir = (_a = npm_utils_1.findPackageJsonDir(plasmicRootDir)) !== null && _a !== void 0 ? _a : plasmicRootDir;
329
+ const srcDir = file_utils_1.existsBuffered(upath_1.default.join(projectRootDir, "src"))
330
+ ? upath_1.default.join(projectRootDir, "src", "components")
331
+ : upath_1.default.join(projectRootDir, "components");
332
+ return {
333
+ srcDir: upath_1.default.relative(plasmicRootDir, srcDir),
334
+ alwaysDerived: [],
335
+ };
336
+ }
337
+ /**
338
+ * Consolidating where we are specifying the descriptions of InitArgs
339
+ */
340
+ const INIT_ARGS_DESCRIPTION = {
341
+ host: {
342
+ shortDescription: "Plasmic host to use",
343
+ },
344
+ platform: {
345
+ shortDescription: "Target platform",
346
+ longDescription: "Target platform to generate code for",
347
+ choices: ["react", "nextjs", "gatsby"],
348
+ },
349
+ codeLang: {
350
+ shortDescription: "Target language",
351
+ longDescription: "Target language to generate code for",
352
+ question: `What target language should Plasmic generate code in?`,
353
+ choices: ["js", "ts"],
354
+ },
355
+ codeScheme: {
356
+ shortDescription: "Code generation scheme",
357
+ longDescription: "Code generation scheme to use",
358
+ choices: ["blackbox", "direct"],
359
+ },
360
+ styleScheme: {
361
+ shortDescription: "Styling framework",
362
+ longDescription: "Styling framework to use",
363
+ question: "How should we generate css for Plasmic components?",
364
+ choices: ["css", "css-modules"],
365
+ },
366
+ imagesScheme: {
367
+ shortDescription: "Image scheme",
368
+ longDescription: "How to reference used image files",
369
+ question: "How should we reference image files used in Plasmic components?",
370
+ choices: ["inlined", "files", "public-files"],
371
+ },
372
+ imagesPublicDir: {
373
+ shortDescription: "Directory of public static files",
374
+ longDescription: "Default directory to put public static files",
375
+ question: "What directory should static image files be put into?",
376
+ },
377
+ imagesPublicUrlPrefix: {
378
+ shortDescription: "URL prefix for static files",
379
+ longDescription: "URL prefix from which the app will serve static files",
380
+ question: "What's the URL prefix from which the app will serve static files?",
381
+ },
382
+ srcDir: {
383
+ shortDescription: "Source directory",
384
+ longDescription: "Default directory to put React component files (that you edit) into",
385
+ question: "What directory should React component files (that you edit) be put into?",
386
+ },
387
+ plasmicDir: {
388
+ shortDescription: "Plasmic-managed directory",
389
+ longDescription: "Default directory to put Plasmic-managed files into; relative to src-dir",
390
+ question: "What directory should Plasmic-managed files (that you should not edit) be put into?",
391
+ },
392
+ pagesDir: {
393
+ shortDescription: "Pages directory",
394
+ longDescription: "Default directory to put page files (that you edit) into",
395
+ question: "What directory should pages be put into?",
396
+ },
397
+ };
398
+ /**
399
+ * Get the short description, which exists for all args
400
+ * @param key
401
+ * @returns
402
+ */
403
+ function getInitArgsShortDescription(key) {
404
+ var _a;
405
+ return (_a = INIT_ARGS_DESCRIPTION[key]) === null || _a === void 0 ? void 0 : _a.shortDescription;
406
+ }
407
+ exports.getInitArgsShortDescription = getInitArgsShortDescription;
408
+ /**
409
+ * Try to get a long description, falling back to the short description
410
+ * @param key
411
+ * @returns
412
+ */
413
+ function getInitArgsLongDescription(key) {
414
+ var _a, _b, _c;
415
+ return ((_b = (_a = INIT_ARGS_DESCRIPTION[key]) === null || _a === void 0 ? void 0 : _a.longDescription) !== null && _b !== void 0 ? _b : (_c = INIT_ARGS_DESCRIPTION[key]) === null || _c === void 0 ? void 0 : _c.shortDescription);
416
+ }
417
+ exports.getInitArgsLongDescription = getInitArgsLongDescription;
418
+ /**
419
+ * Try to get a question form, falling back to the description
420
+ * @param key
421
+ * @returns
422
+ */
423
+ function getInitArgsQuestion(key) {
424
+ var _a, _b, _c, _d, _e;
425
+ return ((_d = (_b = (_a = INIT_ARGS_DESCRIPTION[key]) === null || _a === void 0 ? void 0 : _a.question) !== null && _b !== void 0 ? _b : (_c = INIT_ARGS_DESCRIPTION[key]) === null || _c === void 0 ? void 0 : _c.longDescription) !== null && _d !== void 0 ? _d : (_e = INIT_ARGS_DESCRIPTION[key]) === null || _e === void 0 ? void 0 : _e.shortDescription);
426
+ }
427
+ exports.getInitArgsQuestion = getInitArgsQuestion;
428
+ /**
429
+ * Get the possible choices for an arg
430
+ * @param key
431
+ * @returns
432
+ */
433
+ function getInitArgsChoices(key) {
434
+ var _a;
435
+ return (_a = INIT_ARGS_DESCRIPTION[key]) === null || _a === void 0 ? void 0 : _a.choices;
436
+ }
437
+ exports.getInitArgsChoices = getInitArgsChoices;
438
+ /**
439
+ * Get a `opt` object for use with the `yargs` library.
440
+ * If no choices are specified, assume it's freeform string input
441
+ * All options use "" as the default, unless overridden
442
+ * @param key
443
+ * @param defaultOverride
444
+ * @returns
445
+ */
446
+ function getYargsOption(key, defaultOverride) {
447
+ const arg = lang_utils_1.ensure(INIT_ARGS_DESCRIPTION[key]);
448
+ return !arg.choices
449
+ ? {
450
+ describe: lang_utils_1.ensure(getInitArgsLongDescription(key)),
451
+ string: true,
452
+ default: defaultOverride !== null && defaultOverride !== void 0 ? defaultOverride : "",
453
+ }
454
+ : {
455
+ describe: lang_utils_1.ensure(getInitArgsLongDescription(key)),
456
+ choices: ["", ...lang_utils_1.ensure(getInitArgsChoices(key))],
457
+ default: defaultOverride !== null && defaultOverride !== void 0 ? defaultOverride : "",
458
+ };
459
+ }
460
+ exports.getYargsOption = getYargsOption;
@@ -0,0 +1,6 @@
1
+ export interface ProjectTokenArgs {
2
+ projectId: string;
3
+ host: string;
4
+ }
5
+ export declare const getProjectApiToken: (projectId: string, host?: string | undefined) => Promise<string | undefined>;
6
+ export declare const projectToken: (args: ProjectTokenArgs) => Promise<void>;
@@ -0,0 +1,42 @@
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.projectToken = exports.getProjectApiToken = void 0;
16
+ const chalk_1 = __importDefault(require("chalk"));
17
+ const api_1 = require("../api");
18
+ const deps_1 = require("../deps");
19
+ const auth_utils_1 = require("../utils/auth-utils");
20
+ const config_utils_1 = require("../utils/config-utils");
21
+ exports.getProjectApiToken = (projectId, host) => __awaiter(void 0, void 0, void 0, function* () {
22
+ var _a;
23
+ const auth = yield auth_utils_1.getOrStartAuth({
24
+ host: host || config_utils_1.DEFAULT_HOST,
25
+ baseDir: "",
26
+ });
27
+ if (auth) {
28
+ const api = new api_1.PlasmicApi(auth);
29
+ const versionResolution = yield api.resolveSync([
30
+ { projectId, componentIdOrNames: undefined },
31
+ ]);
32
+ return (_a = versionResolution.projects[0]) === null || _a === void 0 ? void 0 : _a.projectApiToken;
33
+ }
34
+ return undefined;
35
+ });
36
+ exports.projectToken = (args) => __awaiter(void 0, void 0, void 0, function* () {
37
+ const { projectId, host } = args;
38
+ const projectApiToken = yield exports.getProjectApiToken(projectId, host);
39
+ deps_1.logger.info(`Generated projectApiToken for ${chalk_1.default.bold(projectId)}:`);
40
+ deps_1.logger.info(chalk_1.default.bold(projectApiToken));
41
+ deps_1.logger.warn(`Be careful with this token, anyone can have access to your project with it`);
42
+ });
@@ -0,0 +1,10 @@
1
+ import { ChecksumBundle, ComponentBundle } from "../api";
2
+ import { ComponentUpdateSummary } from "../utils/code-utils";
3
+ import { PlasmicContext, ProjectConfig, ProjectLock } from "../utils/config-utils";
4
+ export interface ComponentPendingMerge {
5
+ skeletonModulePath: string;
6
+ editedSkeletonFile: string;
7
+ newSkeletonFile: string;
8
+ merge: (resolvedNewSkeletonFile: string, resolvedEditedSkeletonFile: string) => Promise<void>;
9
+ }
10
+ export declare function syncProjectComponents(context: PlasmicContext, project: ProjectConfig, version: string, componentBundles: ComponentBundle[], forceOverwrite: boolean, appendJsxOnMissingBase: boolean, summary: Map<string, ComponentUpdateSummary>, pendingMerge: ComponentPendingMerge[], projectLock: ProjectLock, checksums: ChecksumBundle, baseDir: string): Promise<void>;