-
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.
Merge pull request #5 from Santhoshmani1/migrate-to-ts
Migrate to typescript
- Loading branch information
Showing
19 changed files
with
456 additions
and
19 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,51 @@ | ||
import chalk from "chalk"; | ||
import chalkAnimation from "chalk-animation"; | ||
import sleep from "../utils/sleep.js"; | ||
import select from "@inquirer/select"; | ||
import { createSpinner } from "nanospinner"; | ||
import { exec } from "node:child_process"; | ||
import { projectDir } from "./init.js"; | ||
const installWelcome = "2. npm install <package-name>"; | ||
const installNotes = chalk.blueBright("npm install helps you to install external packages & provides the ability to use them in your projects\n"); | ||
function installSuccess(packageName) { | ||
console.log(chalk.green(`${packageName} installed successfully`)); | ||
} | ||
async function installPackage(answer) { | ||
return new Promise((resolve, reject) => { | ||
exec(`cd ${projectDir} && npm install ${answer}`, (error, stdout, stderr) => { | ||
if (error) { | ||
console.warn(error); | ||
reject(stderr); | ||
} | ||
resolve(stdout); | ||
}); | ||
}); | ||
} | ||
async function npmInstall() { | ||
const npmInstallAnimation = chalkAnimation.rainbow(installWelcome); | ||
npmInstallAnimation.start(); | ||
await sleep(2000); | ||
npmInstallAnimation.stop(); | ||
console.log(installNotes); | ||
await sleep(1000); | ||
const answer = await select({ | ||
message: "Pick a package to install:", | ||
choices: [ | ||
{ | ||
value: "chalk", | ||
}, | ||
{ | ||
value: "uuid", | ||
}, | ||
], | ||
}); | ||
const spinner = createSpinner(); | ||
console.log(chalk.yellow("npm install ", answer)); | ||
spinner.start(); | ||
await sleep(1000); | ||
spinner.stop(); | ||
await installPackage(answer) | ||
.then(() => installSuccess(answer)) | ||
.catch((error) => console.error(error)); | ||
} | ||
export default npmInstall; |
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,48 @@ | ||
import chalk from "chalk"; | ||
import chalkAnimation from "chalk-animation"; | ||
import sleep from "../utils/sleep.js"; | ||
import select from "@inquirer/select"; | ||
import { createSpinner } from "nanospinner"; | ||
import { exec } from "node:child_process"; | ||
import { projectDir } from "./init.js"; | ||
const installDevDepWelcome = "3. npm install --save-dev <package-name>"; | ||
const installDevDepNotes = chalk.blueBright("npm install --save-dev helps you to install external packages as development dependency\n"); | ||
function installDevDepSuccess(packageName) { | ||
console.log(chalk.green(`${packageName} installed as development dependency successfully`)); | ||
} | ||
async function installDevDep(answer) { | ||
return new Promise((resolve, reject) => { | ||
exec(`cd ${projectDir} && npm install --save-dev ${answer}`, (error, stdout, stderr) => { | ||
if (error) { | ||
console.warn(error); | ||
reject(stderr); | ||
} | ||
resolve(stdout); | ||
}); | ||
}); | ||
} | ||
async function npmInstallDevDep() { | ||
const npmInstallDevDepAnimation = chalkAnimation.rainbow(installDevDepWelcome); | ||
npmInstallDevDepAnimation.start(); | ||
await sleep(2000); | ||
npmInstallDevDepAnimation.stop(); | ||
console.log(installDevDepNotes); | ||
await sleep(1000); | ||
const answer = await select({ | ||
message: "Let's install nodemon as devdependency:", | ||
choices: [ | ||
{ | ||
value: "nodemon", | ||
}, | ||
], | ||
}); | ||
const spinner = createSpinner(); | ||
console.log(chalk.yellow("npm install ", answer)); | ||
spinner.start(); | ||
await sleep(1000); | ||
spinner.stop(); | ||
await installDevDep(answer) | ||
.then(() => installDevDepSuccess(answer)) | ||
.catch((error) => console.error(error)); | ||
} | ||
export default npmInstallDevDep; |
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,65 @@ | ||
import fs from "fs"; | ||
import chalk from "chalk"; | ||
import inquirer from "inquirer"; | ||
import chalkAnimation from "chalk-animation"; | ||
import sleep from "../utils/sleep.js"; | ||
export let projectDir = process.cwd() || ""; | ||
export async function npmInit() { | ||
console.log(chalk.bold("Let's get started\n")); | ||
const npmInit = chalkAnimation.rainbow("1. npm init", 500); | ||
await sleep(3000); | ||
npmInit.start(); | ||
npmInit.stop(); | ||
console.log(chalk.blueBright("npm init creates a package.json file, it is the heart of any Node.js project. It contains the metadata of the project and the dependencies\n")); | ||
await sleep(1000); | ||
let { name } = await inquirer.prompt({ | ||
type: "input", | ||
name: "name", | ||
message: "Name of the project", | ||
default: "my-first-project", | ||
}); | ||
name = name.replace(" ", "-"); | ||
const { version } = await inquirer.prompt({ | ||
type: "input", | ||
name: "version", | ||
message: "version", | ||
default: "1.0.0", | ||
}); | ||
const { description } = await inquirer.prompt({ | ||
type: "input", | ||
name: "description", | ||
message: "Description of your project?", | ||
default: "", | ||
}); | ||
const { main } = await inquirer.prompt({ | ||
name: "main", | ||
type: "input", | ||
message: "entrypoint of the project", | ||
default: "index.js", | ||
}); | ||
const { author } = await inquirer.prompt({ | ||
type: "input", | ||
name: "author", | ||
message: "Author", | ||
default: "", | ||
}); | ||
const packageJson = { | ||
name, | ||
description, | ||
author, | ||
version, | ||
main, | ||
scripts: { | ||
start: "node index.js", | ||
test: 'echo "Error: no test specified" && exit 1', | ||
}, | ||
keywords: [], | ||
license: "ISC", | ||
}; | ||
fs.mkdir(name, (err) => { | ||
err && console.log(err); | ||
}); | ||
fs.writeFileSync(name + "/package.json", JSON.stringify(packageJson, null, 2)); | ||
projectDir = projectDir + "/" + name; | ||
console.log(chalk.green("project initiated & package.json created successfully!\n")); | ||
} |
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,48 @@ | ||
import chalk from "chalk"; | ||
import chalkAnimation from "chalk-animation"; | ||
import sleep from "../utils/sleep.js"; | ||
import { createSpinner } from "nanospinner"; | ||
import { exec } from "node:child_process"; | ||
import { projectDir } from "./init.js"; | ||
import inquirer from "inquirer"; | ||
const unInstallWelcome = "4. npm uninstall <package-name>"; | ||
const unInstallNotes = chalk.blueBright("npm uninstall removes packages from your project\n"); | ||
function unInstallSuccess(packageName) { | ||
console.log(chalk.green(`${packageName} uninstalled successfully`)); | ||
} | ||
async function unInstallPackage(answer) { | ||
return new Promise((resolve, reject) => { | ||
exec(`cd ${projectDir} && npm uninstall ${answer}`, (error, stdout, stderr) => { | ||
if (error) { | ||
console.warn(error); | ||
reject(stderr); | ||
} | ||
resolve(stdout); | ||
}); | ||
}); | ||
} | ||
async function npmUnInstall() { | ||
const npmUnInstallAnimation = chalkAnimation.rainbow(unInstallWelcome); | ||
npmUnInstallAnimation.start(); | ||
await sleep(2000); | ||
npmUnInstallAnimation.stop(); | ||
console.log(unInstallNotes); | ||
await sleep(1000); | ||
const unwantedPackage = await inquirer.prompt([ | ||
{ | ||
type: "input", | ||
name: "packageName", | ||
message: "Enter the package name to uninstall:", | ||
}, | ||
]); | ||
const { packageName } = unwantedPackage; | ||
const spinner = createSpinner(); | ||
console.log(chalk.yellow("npm uninstall ", packageName)); | ||
spinner.start(); | ||
await sleep(1000); | ||
spinner.stop(); | ||
await unInstallPackage(packageName) | ||
.then(() => unInstallSuccess(packageName)) | ||
.catch((error) => console.error(error)); | ||
} | ||
export default npmUnInstall; |
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,13 @@ | ||
#!/usr/bin/env node | ||
import welcome from "./utils/welcome.js"; | ||
import { npmInit } from "./commands/init.js"; | ||
import npmInstall from "./commands/depInstall.js"; | ||
import npmInstallDevDep from "./commands/devDepInstall.js"; | ||
import npmUnInstall from "./commands/uninstall.js"; | ||
import finish from "./utils/finish.js"; | ||
await welcome(); | ||
await npmInit(); | ||
await npmInstall(); | ||
await npmInstallDevDep(); | ||
await npmUnInstall(); | ||
await finish(); |
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,12 @@ | ||
import chalk from "chalk"; | ||
import chalkAnimation from "chalk-animation"; | ||
import sleep from "./sleep.js"; | ||
async function finish() { | ||
const finalGreetings = chalkAnimation.rainbow("congratulations for getting started with npm. Now It's time to build something amazing!"); | ||
finalGreetings.start(); | ||
await sleep(2000); | ||
finalGreetings.stop(); | ||
console.log(chalk.blueBright("All the best")); | ||
process.exit(0); | ||
} | ||
export default finish; |
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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
const sleep = (ms = 3000) => new Promise((resolve) => setTimeout(resolve, ms)); | ||
|
||
export default sleep; | ||
export default sleep; |
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,11 @@ | ||
import chalkAnimation from "chalk-animation"; | ||
import figlet from "figlet"; | ||
import gradient from "gradient-string"; | ||
import sleep from "./sleep.js"; | ||
async function welcome() { | ||
console.log(gradient.rainbow(figlet.textSync("npm-cli-tour", { horizontalLayout: "full" }))); | ||
let welcomeText = chalkAnimation.rainbow("Welcome to npm-cli-tour\n\n"); | ||
await sleep(3000); | ||
welcomeText.stop(); | ||
} | ||
export default welcome; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.