Series of articles:
- Step one, create the first command
- Step 2: Set up the development environment
- Step 3: Get information about github projects
- The fourth step is to obtain project information through lifting code
- [Hand in hand to take you to lift a scaffolding] step five, finish the job
Getting git project information is an important step. However, can only get the information can not download down, you this scaffolding has a 🔨 use.
In this section, we’ll start downloading git projects. And publish the completed code to nPMjs.com, master the core technology, and serve the global code farmers 😂
First install dependenciesdownload-git-repo
npm install download-git-repo -S
Copy the code
Expand Git action classes
- Git class downloadProject method:
downloadProject({ repo, version, repoPath }) {
return new Promise((resolve, reject) = > {
download(`The ${this.orgName}/${repo}#${version}`, repoPath, (err) => {
if (err) reject(err);
resolve(true);
});
});
}
Copy the code
Download-git-repo is introduced here, so I recommend you to check out the official documentation
- Optimize the command/download.js file,
// Ask the user for a directory to create the project
const repoName = [
{
type: 'input'.name: 'repoPath'.message: 'Please enter project name:',
validate(v) {
const done = this.async();
if(! v.trim()) { done('Item name cannot be empty ~');
}
done(null.true); }},];const { repoPath } = await this.inquirer.prompt(repoName);
// Download the code to the specified directory
try {
downLoadLoad = this.downLoad.start();
await this.git.downloadProject({ repo, version, repoPath });
downLoadLoad.succeed('Downloaded code successfully');
} catch (error) {
console.log(error);
downLoadLoad.fail('Downloading code failed... ');
}
Copy the code
Added logic to ask the user for the project development directory and invoke code download. At this point, we can download the template code normally. Try ^_^
Github has implemented the code library download function, but it is not difficult to notice that the code can only be downloaded to the scaffolding project directory. Of course not. Next we posted our scaffolding on nPMjs.com.
Publish the code to NPM
-
First of all, create NPMJS account, this I will not say here, the huge Sign up on the top right corner of the home page, this wave, you will not calculate (ping) I (lun) input (qu) 😄
-
Second, log in to the NPM official website to verify that there is no problem with your account
-
Again, it is important to replace the NPM image with the official image
npm config set registry http://registry.npmjs.org Copy the code
Of course, switching to an official image will be slow, but I have one piece of advice: be patient. Geek buddies can also execute the following statement after the completion of the package, replace the mirror with taobao mirror speed fly.
npm config set registry https://registry.npm.taobao.org Copy the code
-
Finally, the result of NPM publish is as follows:
There are no unexpected errors reported, but by reading the error message, this is to let us log in and also give the login command, NPM design is quite interesting ^_^
-
According to the error message, run NPM adduser
Here to share with you, if you do not change the mirror address, you will report this error when logging in.
The normal login operation looks like this
-
Finally, this time it’s true. Finally, after successful login, we publish again.
-
Visit npmjs.com in your browser and log in to find the package we just uploaded at 😄 as shown below
-
The last step is to verify the results….
- Command line execution
npm i learn-cli -g
Global install Learn-CLI - The following steps are shown below:
- Command line execution
So far, the preliminary scaffolding development has been completed, if you have any questions, please let me know in the comments section.
Afterword.
In my previous work, there was a lot of business, all kinds of logic needed to be written and all kinds of wheels needed to be copied, resulting in infinite demand, but my brain capacity was limited. Therefore, some people wrote excellent code today, but forgot how to write it tomorrow. This iteration built a good development template, and they had to rebuild it in the next iteration. All kinds of fuckin configurations (webpack I didn’t say you 😄). Going back and forth is boring, so I came up with the idea of building a scaffold, one configuration at a time, one company cycle is effective. Very good ^_^
Learn-cli V0.0.2 already meets most of the requirements, but there are still some optimizations to be made. For example, there is no readMe, you can download the project template directly to the local computer, and copy the template directly from the local computer after initializing the project. After all, there is no end to learning. But time is limited, I also welcome the PR of my friends, let’s work together to build a scaffold that we like, but also our own
The first time I wrote a series of articles, I couldn’t stop writing 😄. Next, I plan to write a series of interface testing tools. It’s the usual HTTP interface testing tool. It’s a project I agreed to study with a very good friend a long time ago.
Technical selection:
Front end: vue. Js
The backend: Java
Why use Java when you have Node, PHP and Python on the back end? Haha, because I can do the first few kinds of ^_^, welcome friends to learn here we go with me