create-plasmic-app 0.0.57 → 0.0.59

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/dist/index.js CHANGED
@@ -103,19 +103,19 @@ Sentry.configureScope((scope) => {
103
103
  * @param question instance of a question formatted for `inquirer`
104
104
  * @returns
105
105
  */
106
- function maybePrompt(question) {
106
+ function maybePrompt(question, checkCliAnswer = true) {
107
107
  return __awaiter(this, void 0, void 0, function* () {
108
108
  const name = (0, lang_utils_1.ensure)(question.name);
109
109
  const message = (0, lang_utils_1.ensure)(question.message);
110
- const maybeAnswer = argv[name];
111
- if (maybeAnswer === null || maybeAnswer === undefined || maybeAnswer === "") {
112
- const ans = yield inquirer_1.default.prompt(Object.assign({}, question));
113
- return ans[name];
114
- }
115
- else {
116
- console.log(`${message}: ${maybeAnswer} (specified in CLI arg)`);
117
- return (0, lang_utils_1.ensure)(argv[name]);
110
+ if (checkCliAnswer) {
111
+ const cliAnswer = argv[name];
112
+ if (cliAnswer !== null && cliAnswer !== undefined && cliAnswer !== "") {
113
+ console.log(`${message}: ${cliAnswer} (specified in CLI arg)`);
114
+ return cliAnswer; // assume it's the correct type
115
+ }
118
116
  }
117
+ const ans = yield inquirer_1.default.prompt(question);
118
+ return ans[name];
119
119
  });
120
120
  }
121
121
  // Keeping these as globals to easily share with our `crash` function
@@ -202,20 +202,26 @@ function run() {
202
202
  // Get the projectId
203
203
  console.log();
204
204
  let projectId;
205
+ let firstPrompt = true;
205
206
  while (!projectId) {
206
207
  const rawProjectId = yield maybePrompt({
207
208
  name: "projectId",
208
- message: `What is the URL of your project?
209
- If you don't have a project yet, create one by going to
210
- https://studio.plasmic.app/starters/blank
211
- `,
212
- });
213
- projectId = rawProjectId
214
- .replace("https://studio.plasmic.app/projects/", "")
215
- .trim();
216
- if (!projectId) {
217
- console.error(`"${rawProjectId}" is not a valid project ID.`);
209
+ message: `If you don't have a project yet, create one by going to https://studio.plasmic.app/starters/blank.
210
+ What is the URL of your project?`,
211
+ }, firstPrompt);
212
+ firstPrompt = false; // avoid infinite loop with an invalid CLI answer
213
+ const matchUrl = rawProjectId.match(/studio\.plasmic\.app\/projects\/([a-z0-9]{5,})\//i);
214
+ if (matchUrl) {
215
+ projectId = matchUrl[1];
216
+ continue;
217
+ }
218
+ // allow passing in a project ID
219
+ const matchId = rawProjectId.match(/([a-z0-9]{5,})/i);
220
+ if (matchId) {
221
+ projectId = matchId[1];
222
+ continue;
218
223
  }
224
+ console.error(`"${rawProjectId}" is not a valid project URL nor ID.`);
219
225
  }
220
226
  // RUN IT
221
227
  console.log();
@@ -56,7 +56,7 @@ const reactStrategy = {
56
56
  yield (0, file_utils_1.overwriteIndex)(projectPath, "react", scheme);
57
57
  }
58
58
  // Deactivate React.StrictMode from index.tsx
59
- const indexFileName = path_1.default.join(projectPath, "src", `index.${useTypescript ? "tsx" : "ts"}`);
59
+ const indexFileName = path_1.default.join(projectPath, "src", `index.${useTypescript ? "tsx" : "js"}`);
60
60
  let indexFile = fs_1.default.readFileSync(indexFileName).toString();
61
61
  indexFile = indexFile.replace("<React.StrictMode>", "");
62
62
  indexFile = indexFile.replace("</React.StrictMode>", "");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-plasmic-app",
3
- "version": "0.0.57",
3
+ "version": "0.0.59",
4
4
  "description": "Create Plasmic-powered React apps",
5
5
  "main": "./dist/lib.js",
6
6
  "types": "./dist/lib.d.ts",
@@ -22,7 +22,7 @@
22
22
  "devDependencies": {
23
23
  "@types/findup-sync": "^2.0.2",
24
24
  "@types/glob": "^7.1.3",
25
- "@types/inquirer": "^7.3.1",
25
+ "@types/inquirer": "^8.2.5",
26
26
  "@types/jest": "^26.0.20",
27
27
  "@types/lodash": "^4.14.168",
28
28
  "@types/node": "^14.14.33",
@@ -54,5 +54,5 @@
54
54
  "validate-npm-package-name": "^3.0.0",
55
55
  "yargs": "^16.2.0"
56
56
  },
57
- "gitHead": "9f6a6d8770a08c3c895c75eb8159edaca05933ab"
57
+ "gitHead": "a9822920199e1809d0e15008515dea8e23aaf676"
58
58
  }
package/src/index.ts CHANGED
@@ -74,17 +74,23 @@ Sentry.configureScope((scope) => {
74
74
  * @param question instance of a question formatted for `inquirer`
75
75
  * @returns
76
76
  */
77
- async function maybePrompt(question: DistinctQuestion) {
78
- const name = ensure(question.name) as string;
77
+ async function maybePrompt<T>(
78
+ question: DistinctQuestion<Record<string, T>>,
79
+ checkCliAnswer = true
80
+ ): Promise<T> {
81
+ const name = ensure(question.name);
79
82
  const message = ensure(question.message);
80
- const maybeAnswer = argv[name];
81
- if (maybeAnswer === null || maybeAnswer === undefined || maybeAnswer === "") {
82
- const ans = await inquirer.prompt({ ...question });
83
- return ans[name];
84
- } else {
85
- console.log(`${message}: ${maybeAnswer} (specified in CLI arg)`);
86
- return ensure(argv[name]);
83
+
84
+ if (checkCliAnswer) {
85
+ const cliAnswer = argv[name];
86
+ if (cliAnswer !== null && cliAnswer !== undefined && cliAnswer !== "") {
87
+ console.log(`${message}: ${cliAnswer} (specified in CLI arg)`);
88
+ return cliAnswer as T; // assume it's the correct type
89
+ }
87
90
  }
91
+
92
+ const ans = await inquirer.prompt<Record<string, T>>(question);
93
+ return ans[name];
88
94
  }
89
95
 
90
96
  // Keeping these as globals to easily share with our `crash` function
@@ -132,7 +138,7 @@ async function run(): Promise<void> {
132
138
 
133
139
  // Prompt for the platform
134
140
  const platform = ensureString(
135
- await maybePrompt({
141
+ await maybePrompt<string>({
136
142
  name: "platform",
137
143
  message: "What React framework do you want to use?",
138
144
  type: "list",
@@ -181,20 +187,34 @@ async function run(): Promise<void> {
181
187
  // Get the projectId
182
188
  console.log();
183
189
  let projectId: string | undefined;
190
+ let firstPrompt = true;
184
191
  while (!projectId) {
185
- const rawProjectId = await maybePrompt({
186
- name: "projectId",
187
- message: `What is the URL of your project?
188
- If you don't have a project yet, create one by going to
189
- https://studio.plasmic.app/starters/blank
190
- `,
191
- });
192
- projectId = rawProjectId
193
- .replace("https://studio.plasmic.app/projects/", "")
194
- .trim();
195
- if (!projectId) {
196
- console.error(`"${rawProjectId}" is not a valid project ID.`);
192
+ const rawProjectId = await maybePrompt<string>(
193
+ {
194
+ name: "projectId",
195
+ message: `If you don't have a project yet, create one by going to https://studio.plasmic.app/starters/blank.
196
+ What is the URL of your project?`,
197
+ },
198
+ firstPrompt
199
+ );
200
+ firstPrompt = false; // avoid infinite loop with an invalid CLI answer
201
+
202
+ const matchUrl = rawProjectId.match(
203
+ /studio\.plasmic\.app\/projects\/([a-z0-9]{5,})\//i
204
+ );
205
+ if (matchUrl) {
206
+ projectId = matchUrl[1];
207
+ continue;
208
+ }
209
+
210
+ // allow passing in a project ID
211
+ const matchId = rawProjectId.match(/([a-z0-9]{5,})/i);
212
+ if (matchId) {
213
+ projectId = matchId[1];
214
+ continue;
197
215
  }
216
+
217
+ console.error(`"${rawProjectId}" is not a valid project URL nor ID.`);
198
218
  }
199
219
 
200
220
  // RUN IT
@@ -55,7 +55,7 @@ const reactStrategy: CPAStrategy = {
55
55
  const indexFileName = path.join(
56
56
  projectPath,
57
57
  "src",
58
- `index.${useTypescript ? "tsx" : "ts"}`
58
+ `index.${useTypescript ? "tsx" : "js"}`
59
59
  );
60
60
  let indexFile = fs.readFileSync(indexFileName).toString();
61
61
  indexFile = indexFile.replace("<React.StrictMode>", "");