Skip to content
This repository was archived by the owner on Mar 30, 2021. It is now read-only.

Commit 6668aa7

Browse files
committed
Makes the workflow better
This changes the workflow so that the generator asks the directory name first and then asks URL and hence simplifies the workflow.
1 parent fba4ac7 commit 6668aa7

File tree

3 files changed

+79
-297
lines changed

3 files changed

+79
-297
lines changed

__tests__/app.js

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ describe("generator-biojs-webcomponents:app - Make a new Web Component", () => {
7979
});
8080

8181
describe("generator-biojs-webcomponents:app - Upgrade an existing component by importing build file locally", () => {
82+
it("makes a new directory named - component-dist", async () => {
83+
await validators
84+
.directoryName("component-dist")
85+
.then(() => assert.file(["component-dist"]));
86+
});
8287
it("imports the build file", async () => {
8388
await validators
8489
.importBuildFileLocally(
@@ -88,43 +93,12 @@ describe("generator-biojs-webcomponents:app - Upgrade an existing component by i
8893
assert.file(["component-dist/validator.js"]);
8994
});
9095
});
91-
it("skips the current question if user enters skip", async () => {
92-
assert.equal(await validators.importBuildFileLocally("skip"), true);
93-
});
94-
it("renames the directory in which build file will be imported", async () => {
95-
await validators
96-
.renameDirectory("test-directory")
97-
.then(() => assert.file(["test-directory", "component-dist"]));
98-
});
99-
it("pastes the build file in renamed directory", async () => {
100-
await validators
101-
.importBuildFileInRenamedDirectory(path.join(__dirname, "../LICENSE"), {
102-
renameDirectoryLocal: "test-directory"
103-
})
104-
.then(() => assert.file(["test-directory/LICENSE"]));
105-
});
106-
it("overwrites the directory content", async () => {
107-
await validators
108-
.overwriteDirectoryContent(path.join(__dirname, "../README.md"), {
109-
renameOrOverwriteLocal:
110-
"Overwrite the files in the existing component-dist directory."
111-
})
112-
.then(() => {
113-
assert.file(["component-dist/README.md"]);
114-
});
115-
});
11696
it("throws an error if user enters an empty string as path of build file", async () => {
11797
assert.equal(
11898
await validators.importBuildFileFromNPM(""),
11999
chalk.red("This is a mandatory field, please answer.")
120100
);
121101
});
122-
it("throws an error if user enters an empty string as the name for directory in which build file will be imported", async () => {
123-
assert.equal(
124-
await validators.renameDirectory(""),
125-
chalk.red("This is a mandatory field, please answer.")
126-
);
127-
});
128102
});
129103

130104
describe("generator-biojs-webcomponents:app - Upgrade an existing component by importing build file using npm", () => {
@@ -133,16 +107,13 @@ describe("generator-biojs-webcomponents:app - Upgrade an existing component by i
133107
await validators.version("fkdk", { packageName: "node" }),
134108
chalk.red(
135109
"Sorry, the version - " +
136-
chalk.red.bold("fkdk") +
110+
chalk.yellow("fkdk") +
137111
" doesn't exist. Please enter again. Enter " +
138112
chalk.cyan("latest") +
139113
" if you want to import the latest version."
140114
)
141115
);
142116
});
143-
it("skips the current question if user enters skip", async () => {
144-
assert.equal(await validators.importBuildFileFromNPM("skip"), true);
145-
});
146117
it("throws an error if an npm package doesn't exist", async () => {
147118
assert.equal(
148119
await validators.packageName("cbaxyz"),

generators/app/index.js

Lines changed: 24 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ module.exports = class extends Generator {
4141
type: "rawlist",
4242
name: "importFrom",
4343
message:
44-
"We need the build file (generally index.js, main.js or componentName.js) for this, import it using one of the options -",
44+
"I need the build file (generally index.js, main.js or componentName.js) for this, import it using one of the options -",
4545
choices: [
4646
"Install component from npm package (Recommended - fastest way)",
47-
"Tell us the path of the build file on your local machine and we will import it in the project.",
48-
"Tell us the npm package name, version, build file URL and we will download the build file."
47+
"Tell us the path of the build file on your local machine and I will import it in the project.",
48+
"Tell us the npm package name, version, build file URL and I will download the build file."
4949
],
5050
default: 0
5151
}
@@ -84,7 +84,7 @@ module.exports = class extends Generator {
8484
type: "input",
8585
name: "checkVersionAndInstallComponent",
8686
message:
87-
"Great! We will import the latest version of the npm package, if you don't want this, enter the version.",
87+
"Great! I will import the latest version of the npm package, if you don't want this, enter the version.",
8888
default: "latest",
8989
when: function(responses) {
9090
if (responses.confirmPackageNameToInstallComponent) {
@@ -131,7 +131,7 @@ module.exports = class extends Generator {
131131
type: "input",
132132
name: "version",
133133
message:
134-
"Great! We will import the latest version of your file from the npm package, if you don't want this, enter the version.",
134+
"Great! I will import the latest version of your file from the npm package, if you don't want this, enter the version.",
135135
default: "latest",
136136
when: function(responses) {
137137
if (responses.confirmPackageName) {
@@ -142,6 +142,14 @@ module.exports = class extends Generator {
142142
},
143143
validate: validators.version
144144
},
145+
{
146+
type: "input",
147+
name: "directoryName",
148+
message:
149+
"The build file will be imported in a separate directory in the project's root. Enter the name of this directory or press Enter if you like to go with default.",
150+
validate: validators.directoryName,
151+
default: "component-dist"
152+
},
145153
{
146154
type: "input",
147155
name: "importBuildFileFromNPM",
@@ -154,7 +162,7 @@ module.exports = class extends Generator {
154162
"?version=" +
155163
answers.version
156164
) +
157-
" contains the directory of the package, please find the build file (generally in the dist or build folder) and paste the link here, we will download it for you."
165+
" contains the directory of the package, please find the build file (generally in the dist or build folder) and paste the link here, I will download it for you."
158166
);
159167
},
160168
when: function(responses) {
@@ -165,154 +173,25 @@ module.exports = class extends Generator {
165173
return false; // Don't show this prompt if user says that package description is incorrect
166174
},
167175
validate: validators.importBuildFileFromNPM
168-
},
169-
{
170-
type: "list",
171-
name: "renameOrOverwriteNpm",
172-
message: "What do you want to do?",
173-
choices: [
174-
"Rename the component-dist directory we are making.",
175-
"Overwrite the files in the existing component-dist directory."
176-
],
177-
when: function(responses) {
178-
if (responses.importBuildFileFromNPM === "skip") {
179-
return true; // Show this prompt if user says that package description is correct
180-
}
181-
182-
return false; // Don't show this prompt if user says that package description is incorrect
183-
}
184-
},
185-
{
186-
type: "input",
187-
name: "renameDirectoryNpm",
188-
message: `Enter the name of the directory in which you want to import the build file, make sure it is not ${chalk.cyan(
189-
"dist"
190-
)} or ${chalk.cyan("component-dist")}.`,
191-
when: function(responses) {
192-
if (
193-
responses.renameOrOverwriteNpm ===
194-
"Rename the component-dist directory we are making."
195-
) {
196-
return true;
197-
}
198-
199-
return false;
200-
},
201-
validate: validators.renameDirectory
202-
},
203-
{
204-
type: "input",
205-
name: "importBuildFileInRenamedDirectoryNpm",
206-
message:
207-
"Great! Now enter the URL of the build file to import it in the renamed directory.",
208-
when: function(responses) {
209-
if (
210-
responses.renameOrOverwriteNpm ===
211-
"Rename the component-dist directory we are making."
212-
) {
213-
return true;
214-
}
215-
216-
return false;
217-
},
218-
validate: validators.importBuildFileInRenamedDirectory
219-
},
220-
{
221-
type: "input",
222-
name: "overwriteDirectoryContentNpm",
223-
message: `Enter the URL of the build file. Please note that this will overwrite all the existing content in ${chalk.cyan(
224-
"component-dist"
225-
)}.`,
226-
when: function(responses) {
227-
if (
228-
responses.renameOrOverwriteNpm ===
229-
"Overwrite the files in the existing component-dist directory."
230-
) {
231-
return true;
232-
}
233-
234-
return false;
235-
},
236-
validate: validators.overwriteDirectoryContent
237176
}
238177
];
239178

240179
// Prompt(s) if user chooses to import files locally from computer
241180
const localPrompts = [
242181
{
243182
type: "input",
244-
name: "importBuildFileLocally",
245-
message: "Please enter the path of the build file.",
246-
validate: validators.importBuildFileLocally
247-
},
248-
{
249-
type: "list",
250-
name: "renameOrOverwriteLocal",
251-
message: "What do you want to do?",
252-
choices: [
253-
"Rename the component-dist directory we are making.",
254-
"Overwrite the files in the existing component-dist directory."
255-
],
256-
when: function(responses) {
257-
if (responses.importBuildFileLocally === "skip") {
258-
return true; // Show this prompt if user says that package description is correct
259-
}
260-
261-
return false; // Don't show this prompt if user says that package description is incorrect
262-
}
263-
},
264-
{
265-
type: "input",
266-
name: "renameDirectoryLocal",
267-
message: `Enter the name of the directory in which you want to import the build file, make sure it is not ${chalk.cyan(
268-
"dist"
269-
)} or ${chalk.cyan("component-dist")}.`,
270-
when: function(responses) {
271-
if (
272-
responses.renameOrOverwriteLocal ===
273-
"Rename the component-dist directory we are making."
274-
) {
275-
return true;
276-
}
277-
278-
return false;
279-
},
280-
validate: validators.renameDirectory
281-
},
282-
{
283-
type: "input",
284-
name: "importBuildFileInRenamedDirectory",
285-
message:
286-
"Great! Now enter the path of the build file to import it in the renamed directory.",
287-
when: function(responses) {
288-
if (
289-
responses.renameOrOverwriteLocal ===
290-
"Rename the component-dist directory we are making."
291-
) {
292-
return true;
293-
}
294-
295-
return false;
296-
},
297-
validate: validators.importBuildFileInRenamedDirectory
183+
name: "directoryName",
184+
message: `The build file will be imported in a separate directory in the project's root. Enter the name of this directory or press Enter if you like to go with default ${chalk.cyan(
185+
"component-dist"
186+
)}.`,
187+
validate: validators.directoryName,
188+
default: "component-dist"
298189
},
299190
{
300191
type: "input",
301-
name: "overwriteDirectoryContent",
302-
message: `Enter the path of the build file. Please note that this will overwrite all the existing content in ${chalk.cyan(
303-
"component-dist"
304-
)}.`,
305-
when: function(responses) {
306-
if (
307-
responses.renameOrOverwriteLocal ===
308-
"Overwrite the files in the existing component-dist directory."
309-
) {
310-
return true;
311-
}
312-
313-
return false;
314-
},
315-
validate: validators.overwriteDirectoryContent
192+
name: "importBuildFileLocally",
193+
message: "Please enter the path of the build file.",
194+
validate: validators.importBuildFileLocally
316195
}
317196
];
318197

@@ -566,7 +445,7 @@ module.exports = class extends Generator {
566445
yarn: false
567446
});
568447
this.log(
569-
`While we install the dependencies, you can read the next steps - \n1. Write the code for your component, instructions are in ${chalk.yellow(
448+
`While I install the dependencies, you can read the next steps - \n1. Write the code for your component, instructions are in ${chalk.yellow(
570449
"src/index.js"
571450
)}.\n2. Add css styles to your component in ${chalk.yellow(
572451
"src/style"

0 commit comments

Comments
 (0)