-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
052351c
commit 131d8b6
Showing
4 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
template/node_modules | ||
template/package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"git.ignoreLimitWarning": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
const c = require("ansi-colors"); | ||
const inquirer = require("inquirer"); | ||
const { execSync } = require("child_process"); | ||
const fs = require("fs"); | ||
const { resolve } = require("path"); | ||
|
||
const USER_DIRECTORY = process.env.PWD; | ||
const TEMPLATE_DIRECTORY = resolve(__dirname, "template"); | ||
const QUESTIONS = [ | ||
{ | ||
type: "input", | ||
prefix: c.greenBright(">"), | ||
message: "What is name of your scaffold?", | ||
name: "name", | ||
validate: (name) => { | ||
if (name === "") { | ||
return "Name cannot be left blank" | ||
} | ||
// Regular expression for valid npm package name | ||
if (!RegExp("^(?:@[a-z0-9-~][a-z0-9-._~]*/)?[a-z0-9-~][a-z0-9-._~]*$").test(name)){ | ||
return "Invalid name" | ||
} | ||
return true; | ||
} | ||
}, | ||
{ | ||
type: "input", | ||
prefix: c.greenBright(">"), | ||
message: "Enter description of your scaffold:", | ||
name: "description", | ||
}, | ||
{ | ||
type: "input", | ||
prefix: c.greenBright(">"), | ||
message: "What is your name?", | ||
name: "author", | ||
}, | ||
]; | ||
|
||
const resolveTemplate = (path) => resolve(TEMPLATE_DIRECTORY, path); | ||
const resolveUser = (path) => resolve(USER_DIRECTORY, path); | ||
const l = (message) => { console.log(message); }; | ||
const info = (message) => { l(c.blueBright(i) + c.italic(` ${message}`)); } | ||
const done = () => {l.greenBright("\u2713 Done"); }; | ||
|
||
function start() { | ||
l( | ||
` | ||
${c.blueBright("webpack-scaffold-starter")} | ||
------------------------ | ||
Start your webpack scaffold on the go | ||
` | ||
) | ||
} | ||
|
||
async function question() { | ||
info("Details of your scaffold"); | ||
let answers = {}; | ||
const details = await inquirer.prompt(QUESTIONS); | ||
answers = {answers, ...details}; | ||
return answers; | ||
} | ||
|
||
function scaffold(answers) { | ||
info("Scaffolding files ..."); | ||
const packageJSON = require("./template/package.json"); | ||
packageJSON.name = answers.name; | ||
packageJSON.description = answers.description; | ||
packageJSON.author = answers.author; | ||
|
||
let index = fs.readFileSync(resolveTemplate("./index.js")); | ||
index = index.replace(/<name>/g, answers.name); | ||
index = index.replace(/<description>/, ansewers.description); | ||
index = index.replace(/<description>/, ansewers.author); | ||
|
||
fs.writeFileSync(resolveUser("./package.json"), packageJSON); | ||
fs.writeFileSync(resolveUser("./index.js"), index); | ||
done(); | ||
} | ||
|
||
function install() { | ||
info("Installing Dependencies"); | ||
l(c.gray(" May take few minutes")); | ||
execSync(`cd ${USER_DIRECTORY} && npm install --quiet`); | ||
done(); | ||
} | ||
|
||
(async() => { | ||
start(); | ||
const answers = await question(); | ||
scaffold(); | ||
install(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "webpack-scaffold-starter", | ||
"version": "1.0.0", | ||
"description": "A CLI tool for scaffolding starter webpack-scaffold", | ||
"main": "index.js", | ||
"dependencies": { | ||
"ansi-colors": "^3.2.4", | ||
"inquirer": "^6.2.2" | ||
}, | ||
"devDependencies": {}, | ||
"scripts": { | ||
|
||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/rishabh3112/webpack-scaffold-starter.git" | ||
}, | ||
"author": "Rishabh Chawla", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/rishabh3112/webpack-scaffold-starter/issues" | ||
}, | ||
"homepage": "https://github.com/rishabh3112/webpack-scaffold-starter#readme" | ||
} |