-
Notifications
You must be signed in to change notification settings - Fork 0
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
3a51d47
commit 49cc5f7
Showing
21 changed files
with
179 additions
and
441 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
|
@@ -59,3 +59,4 @@ typings/ | |
|
||
# next.js build output | ||
.next | ||
temp/ |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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,71 @@ | ||
#!/usr/bin/env node | ||
|
||
// Require Node.js Dependencies | ||
const { readdir, readFile, writeFile } = require("fs").promises; | ||
const { join } = require("path"); | ||
|
||
// Require Third-party Dependencies | ||
const execa = require("execa"); | ||
const inquirer = require("inquirer"); | ||
|
||
// CONSTANTS | ||
const ROOT_DIR = join(__dirname, ".."); | ||
const TEMPLATE_DIR = join(ROOT_DIR, "template"); | ||
|
||
/** | ||
* @async | ||
* @function main | ||
* @desc Main Generator CLI | ||
* @returns {Promise<void>} | ||
*/ | ||
async function main() { | ||
const cwd = process.cwd(); | ||
if (cwd === ROOT_DIR || cwd === __dirname) { | ||
throw new Error("Cannot execute at the root of the project"); | ||
} | ||
|
||
// Create initial package.json | ||
await execa("npm init -y"); | ||
|
||
// Write default projects files | ||
(await readdir( | ||
join(TEMPLATE_DIR, "defaultFiles") | ||
)).map((file) => writeFile(file)); | ||
|
||
// Ask projectName and projectDesc | ||
const questions = [ | ||
{ | ||
message: "What is the name of your project", | ||
type: "input", | ||
name: "projectname" | ||
}, | ||
{ | ||
message: "Add a description (optional)", | ||
type: "input", | ||
name: "projectdesc" | ||
} | ||
]; | ||
const response = await inquirer.prompt(questions); | ||
|
||
// Handle Package.json | ||
{ | ||
const cwdPackage = join(cwd, "package.json"); | ||
|
||
const buf = await readFile(cwdPackage); | ||
const obj = JSON.parse(buf.toString()); | ||
obj.name = `@slimio/${response.projectname}`; | ||
obj.description = response.projectdesc; | ||
|
||
await writeFile(cwdPackage, JSON.stringify(obj, null, 2)); | ||
} | ||
|
||
// Handle README.md | ||
const buf = await readFile(join(TEMPLATE_DIR, "README.md")); | ||
|
||
const finalReadme = buf.toString() | ||
.replace(/\${package}/gm, `@slimio/${response.projectname}`) | ||
.replace(/\${desc}/gm, `${response.projectdesc}`); | ||
|
||
await writeFile(join(cwd, "README.md"), finalReadme); | ||
} | ||
main().catch(console.error); |
File renamed without changes.
Oops, something went wrong.