├── .npmrc ├── templates ├── jsp │ ├── src │ │ ├── myVal.js │ │ └── doSomethingAwesome.js │ ├── .babelrc │ ├── index.js │ └── tests │ │ └── index.test.js ├── tsp │ ├── src │ │ ├── myVal.ts │ │ └── doSomethingAwesome.ts │ ├── .babelrc │ ├── index.ts │ └── tsconfig.json ├── jsw │ ├── .babelrc │ ├── index.js │ ├── src │ │ └── doSomethingAwesome.js │ ├── tests │ │ └── index.test.js │ └── webpack.config.js └── tsw │ ├── .babelrc │ ├── index.ts │ ├── src │ └── doSomethingAwesome.ts │ ├── tsconfig.json │ └── webpack.config.js ├── bin └── create-awesome-package ├── .vscode ├── launch.json └── settings.json ├── src ├── package-templates │ ├── package-jsp-tmpl.json │ ├── package-tsp-tmpl.json │ ├── package-jsw-tmpl.json │ └── package-tsw-tmpl.json ├── constants.js ├── writeLintFile.js ├── writePackageFile.js ├── main.js └── cli.js ├── package.json ├── LICENSE ├── README.md └── .gitignore /.npmrc: -------------------------------------------------------------------------------- 1 | registry=https://registry.npmjs.org/ -------------------------------------------------------------------------------- /templates/jsp/src/myVal.js: -------------------------------------------------------------------------------- 1 | export const myVal = 5; 2 | -------------------------------------------------------------------------------- /templates/tsp/src/myVal.ts: -------------------------------------------------------------------------------- 1 | export const myVal: number = 5; 2 | -------------------------------------------------------------------------------- /templates/jsp/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env"] 3 | } 4 | -------------------------------------------------------------------------------- /templates/jsw/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env"] 3 | } 4 | -------------------------------------------------------------------------------- /templates/tsp/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env"] 3 | } 4 | -------------------------------------------------------------------------------- /templates/tsw/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env"] 3 | } 4 | -------------------------------------------------------------------------------- /bin/create-awesome-package: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | require = require('esm')(module) 4 | require('../src/cli').cli(process.argv); 5 | -------------------------------------------------------------------------------- /templates/jsp/index.js: -------------------------------------------------------------------------------- 1 | import doSomethingAwesome from "./src/doSomethingAwesome"; 2 | 3 | 4 | export default doSomethingAwesome; 5 | -------------------------------------------------------------------------------- /templates/jsw/index.js: -------------------------------------------------------------------------------- 1 | import doSomethingAwesome from "./src/doSomethingAwesome"; 2 | 3 | 4 | export default doSomethingAwesome; 5 | -------------------------------------------------------------------------------- /templates/tsp/index.ts: -------------------------------------------------------------------------------- 1 | import doSomethingAwesome from "./src/doSomethingAwesome"; 2 | 3 | 4 | export default doSomethingAwesome; 5 | -------------------------------------------------------------------------------- /templates/tsw/index.ts: -------------------------------------------------------------------------------- 1 | import doSomethingAwesome from "./src/doSomethingAwesome"; 2 | 3 | 4 | export default doSomethingAwesome; 5 | -------------------------------------------------------------------------------- /templates/jsw/src/doSomethingAwesome.js: -------------------------------------------------------------------------------- 1 | const doSomethingAwesomeAddition = (a, b) => { 2 | const sum = a + b; 3 | return sum; 4 | }; 5 | 6 | export default doSomethingAwesomeAddition; 7 | -------------------------------------------------------------------------------- /templates/tsw/src/doSomethingAwesome.ts: -------------------------------------------------------------------------------- 1 | const doSomethingAwesome = (a: number, b: number) => { 2 | const sum = a + b; 3 | return sum; 4 | }; 5 | 6 | export default doSomethingAwesome; 7 | -------------------------------------------------------------------------------- /templates/jsp/src/doSomethingAwesome.js: -------------------------------------------------------------------------------- 1 | import { myVal } from "./myVal"; 2 | 3 | const doSomethingAwesomeAddition = (a, b) => { 4 | const sum = a + b; 5 | console.log("myVal", myVal); 6 | return sum; 7 | }; 8 | 9 | export default doSomethingAwesomeAddition; 10 | -------------------------------------------------------------------------------- /templates/tsp/src/doSomethingAwesome.ts: -------------------------------------------------------------------------------- 1 | import { myVal } from "./myVal"; 2 | 3 | const doSomethingAwesome = (a: number, b: number) => { 4 | const sum = a + b; 5 | console.log("myVal", myVal); 6 | return sum; 7 | }; 8 | 9 | export default doSomethingAwesome; 10 | -------------------------------------------------------------------------------- /templates/tsp/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "./dist/", 4 | "noImplicitAny": true, 5 | "lib": ["es6", "dom", "es2017"], 6 | "module": "es6", 7 | "target": "es5", 8 | "jsx": "react", 9 | "allowJs": true 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /templates/tsw/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "./dist/", 4 | "noImplicitAny": true, 5 | "lib": ["es6", "dom", "es2017"], 6 | "module": "es6", 7 | "target": "es5", 8 | "jsx": "react", 9 | "allowJs": true 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /templates/jsp/tests/index.test.js: -------------------------------------------------------------------------------- 1 | import doSomethingAwesome from "../src/doSomethingAwesome"; 2 | 3 | test("test doSomethingAwesome should return 3", () => { 4 | const num1 = 1; 5 | const num2 = 2; 6 | const sum = doSomethingAwesome(num1, num2); 7 | expect(sum).toBe(3); 8 | }); 9 | -------------------------------------------------------------------------------- /templates/jsw/tests/index.test.js: -------------------------------------------------------------------------------- 1 | import doSomethingAwesome from "../src/doSomethingAwesome"; 2 | 3 | test("test doSomethingAwesome should return 3", () => { 4 | const num1 = 1; 5 | const num2 = 2; 6 | const sum = doSomethingAwesome(num1, num2); 7 | expect(sum).toBe(3); 8 | }); 9 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [] 7 | } -------------------------------------------------------------------------------- /templates/jsw/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | 3 | module.exports = { 4 | entry: "./index.js", 5 | output: { 6 | path: path.resolve(__dirname, "dist"), 7 | filename: "index.js" 8 | }, 9 | module: { 10 | rules: [ 11 | { 12 | test: /\.js$/, 13 | exclude: /node_modules/, 14 | use: { 15 | loader: "babel-loader" 16 | } 17 | } 18 | ] 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /templates/tsw/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | 3 | module.exports = { 4 | entry: "./index.ts", 5 | output: { 6 | path: path.resolve(__dirname, "dist"), 7 | filename: "index.js" 8 | }, 9 | resolve: { 10 | extensions: [ '.tsx', '.ts', '.js' ], 11 | }, 12 | module: { 13 | rules: [ 14 | { 15 | test: /\.ts$/, 16 | exclude: /node_modules/, 17 | use: { 18 | loader: "ts-loader" 19 | } 20 | } 21 | ] 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /src/package-templates/package-jsp-tmpl.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "my-package", 3 | "version": "0.1.0", 4 | "description": "your-awesome-package", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest", 8 | "build": "rm -rf ./dist && npm run build:js", 9 | "build:js": "parcel build index.js" 10 | }, 11 | "repository": {}, 12 | "bugs": {}, 13 | "homepage": "", 14 | "devDependencies": { 15 | "@babel/cli": "^7.7.5", 16 | "@babel/core": "^7.7.5", 17 | "@babel/preset-env": "^7.7.6", 18 | "babel-loader": "^8.0.6", 19 | "jest": "^24.9.0", 20 | "parcel-bundler": "^1.12.4" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/constants.js: -------------------------------------------------------------------------------- 1 | export const TemplateMapper = { 2 | JavaScript: "js", 3 | TypeScript: "ts" 4 | }; 5 | 6 | export const TemplateEnum = { 7 | JavaScript: "JavaScript", 8 | TypeScript: "TypeScript" 9 | }; 10 | 11 | export const BundlerMapper = { 12 | Webpack: "w", 13 | Parcel: "p" 14 | }; 15 | 16 | export const BundlerEnum = { 17 | Webpack: "Webpack", 18 | Parcel: "Parcel" 19 | }; 20 | 21 | export const LinterEnum = { 22 | Eslint: "EsLint", 23 | Prettier: "Prettier", 24 | Both: "Both", 25 | None: "None", 26 | }; 27 | 28 | export const LinterConfirmation = { 29 | Yes: "Yes", 30 | No: "No" 31 | }; 32 | 33 | export const templates = Object.values(TemplateEnum); 34 | -------------------------------------------------------------------------------- /src/package-templates/package-tsp-tmpl.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "my-package", 3 | "version": "0.1.0", 4 | "description": "your-awesome-package", 5 | "main": "index.ts", 6 | "scripts": { 7 | "test": "jest", 8 | "build": "rm -rf ./dist && npm run build:ts", 9 | "build:ts": "parcel build index.ts" 10 | }, 11 | "repository": {}, 12 | "bugs": {}, 13 | "homepage": "", 14 | "devDependencies": { 15 | "@babel/cli": "^7.7.5", 16 | "@babel/core": "^7.7.5", 17 | "@babel/preset-env": "^7.7.6", 18 | "babel-loader": "^8.0.6", 19 | "jest": "^24.9.0", 20 | "ts-loader": "^6.2.1", 21 | "typescript": "^3.7.4", 22 | "parcel-bundler": "^1.12.4" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/package-templates/package-jsw-tmpl.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "your-awesome-package", 3 | "version": "0.1.0", 4 | "description": "your-awesome-package", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest", 8 | "build": "rm -rf ./dist && npm run build:js", 9 | "build:js": "webpack -p --progress --config ./webpack.config.js" 10 | }, 11 | "repository": {}, 12 | "bugs": {}, 13 | "homepage": "", 14 | "devDependencies": { 15 | "@babel/cli": "^7.7.5", 16 | "@babel/core": "^7.7.5", 17 | "@babel/preset-env": "^7.7.6", 18 | "babel-loader": "^8.0.6", 19 | "jest": "^24.9.0", 20 | "webpack": "^4.41.2", 21 | "webpack-cli": "^3.3.10" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/package-templates/package-tsw-tmpl.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "your-awesome-package", 3 | "version": "0.1.0", 4 | "description": "your-awesome-package", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest", 8 | "build": "rm -rf ./dist && npm run build:js", 9 | "build:js": "webpack -p --progress --config ./webpack.config.js" 10 | }, 11 | "repository": {}, 12 | "bugs": {}, 13 | "homepage": "", 14 | "devDependencies": { 15 | "@babel/cli": "^7.7.5", 16 | "@babel/core": "^7.7.5", 17 | "@babel/preset-env": "^7.7.6", 18 | "babel-loader": "^8.0.6", 19 | "jest": "^24.9.0", 20 | "ts-loader": "^6.2.1", 21 | "typescript": "^3.7.4", 22 | "webpack": "^4.41.2", 23 | "webpack-cli": "^3.3.10" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/writeLintFile.js: -------------------------------------------------------------------------------- 1 | import chalk from "chalk"; 2 | import fs from "fs"; 3 | import os from "os"; 4 | import path from "path"; 5 | 6 | const eslintPrettier = { 7 | parserOptions: { 8 | ecmaVersion: 2017, 9 | sourceType: "module" 10 | }, 11 | env: { 12 | es6: true 13 | }, 14 | extends: ["airbnb", "prettier"], 15 | plugins: ["prettier"], 16 | rules: { 17 | "prettier/prettier": ["error"], 18 | "no-unused-vars": [ 19 | "error", 20 | { vars: "all", args: "after-used", ignoreRestSiblings: false } 21 | ] 22 | } 23 | }; 24 | 25 | export async function writeLintFile(options) { 26 | fs.writeFileSync( 27 | path.join(options.targetDirectory, ".eslintrc.json"), 28 | JSON.stringify(eslintPrettier, null, 2) + os.EOL 29 | ); 30 | } 31 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "workbench.colorCustomizations": { 3 | "activityBar.background": "#2f7c47", 4 | "activityBar.activeBorder": "#422c74", 5 | "activityBar.foreground": "#e7e7e7", 6 | "activityBar.inactiveForeground": "#e7e7e799", 7 | "activityBarBadge.background": "#422c74", 8 | "activityBarBadge.foreground": "#e7e7e7", 9 | "titleBar.activeBackground": "#215732", 10 | "titleBar.inactiveBackground": "#21573299", 11 | "titleBar.activeForeground": "#e7e7e7", 12 | "titleBar.inactiveForeground": "#e7e7e799", 13 | "statusBar.background": "#215732", 14 | "statusBarItem.hoverBackground": "#2f7c47", 15 | "statusBar.foreground": "#e7e7e7" 16 | }, 17 | "peacock.color": "#215732" 18 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "create-awesome-package", 3 | "version": "2.1.2", 4 | "description": "CLI to bootstrap your awesome package", 5 | "main": "src/main.js", 6 | "bin": { 7 | "create-awesome-package": "bin/create-awesome-package" 8 | }, 9 | "scripts": { 10 | "test": "echo \"Error: no test specified\" && exit 1" 11 | }, 12 | "keywords": [ 13 | "create-awesome-package", 14 | "npm", 15 | "package", 16 | "create new package" 17 | ], 18 | "repository": { 19 | "type": "git", 20 | "url": "git+https://github.com/destromas1/create-awesome-package.git" 21 | }, 22 | "author": "destromas1 ", 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://github.com/destromas1/create-awesome-package/issues" 26 | }, 27 | "homepage": "https://github.com/destromas1/create-awesome-package#readme", 28 | "dependencies": { 29 | "arg": "^4.1.2", 30 | "chalk": "^3.0.0", 31 | "esm": "^3.2.25", 32 | "inquirer": "^7.0.2", 33 | "ncp": "^2.0.0" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Shahjada Talukdar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # create-awesome-package 2 | 3 | 4 | When you need to create a new package, need to add a lot of boilerplate code, webpack or other build system to transpile to ES5 etc. 5 | 6 | This CLI helps to create the package with JS/TS, build system(Webpack/Parcel) and necessary stuff 🔥 7 | It's like create-react-app but for building packages 📦 8 | 9 | 10 | `create-awesome-package` helps to create the package with build system and necessary stuff. 11 | 12 | ### You can create package with JavaScript/TypeScript 13 | 14 | You just write your own code 🔥 15 | 16 | # How to install 17 | 18 | `npm i -g create-awesome-package` 19 | 20 |

How to use

21 | 22 | Go to your root of the package you want to build. 23 | 24 | Then, Just run 25 | 26 | `create-awesome-package [name]` 27 | 28 | example - 29 | `create-awesome-package my-package` 30 | 31 | OR also you can use `npx` 32 | 33 | `npx create-awesome-package my-package` ( if you don't want to globally install it) 34 | 35 | and you are done! 36 | 37 | It will provide you the boilerplate you need to get started! 38 | 39 |

To Run Tests

40 | 41 | `npm run test` 42 | 43 | ---- 44 | 45 | Inspired from `create-react-app` 46 | 47 | -------------------------------------------------------------------------------- /src/writePackageFile.js: -------------------------------------------------------------------------------- 1 | import chalk from "chalk"; 2 | import fs from "fs"; 3 | import os from "os"; 4 | import path from "path"; 5 | import { LinterConfirmation } from "./constants.js"; 6 | 7 | const linterLibs = { 8 | eslint: "^6.8.0", 9 | "eslint-config-airbnb": "^18.0.1", 10 | "eslint-config-prettier": "6.10.0", 11 | "eslint-plugin-import": "^2.20.0", 12 | "eslint-plugin-jsx-a11y": "^6.2.3", 13 | "eslint-plugin-prettier": "3.1.2", 14 | "eslint-plugin-react": "^7.18.1", 15 | prettier: "1.19.1" 16 | }; 17 | 18 | const lintScripts = { 19 | "prettier": "./node_modules/.bin/prettier ./src/*.js --write", 20 | "eslint": "./node_modules/.bin/eslint ./src/*.js" 21 | }; 22 | 23 | export async function writePackageFile(options, templateBundler) { 24 | const packageTmpl = require(`./package-templates/package-${templateBundler}-tmpl.json`); 25 | 26 | const packageJson = { 27 | ...packageTmpl, 28 | name: options.packageName, 29 | devDependencies: { 30 | ...packageTmpl.devDependencies, 31 | ...(options.linter !== LinterConfirmation.No && linterLibs) 32 | }, 33 | scripts: { 34 | ...packageTmpl.scripts, 35 | ...(options.linter !== LinterConfirmation.No && lintScripts) 36 | } 37 | }; 38 | fs.writeFileSync( 39 | path.join(options.targetDirectory, "package.json"), 40 | JSON.stringify(packageJson, null, 2) + os.EOL 41 | ); 42 | } 43 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import chalk from "chalk"; 2 | import fs from "fs"; 3 | import ncp from "ncp"; 4 | import path from "path"; 5 | import { promisify } from "util"; 6 | import { LinterConfirmation } from "./constants.js"; 7 | import { writeLintFile } from "./writeLintFile.js"; 8 | import { writePackageFile } from "./writePackageFile.js"; 9 | 10 | const access = promisify(fs.access); 11 | const copy = promisify(ncp); 12 | 13 | async function copyTemplateFiles(options, templateBundler) { 14 | console.log("options.linter", options.linter); 15 | 16 | if (options.linter !== LinterConfirmation.No) { 17 | await writeLintFile(options); 18 | } 19 | await writePackageFile(options, templateBundler); 20 | 21 | return copy(options.templateDirectory, options.targetDirectory, { 22 | clobber: false 23 | }); 24 | } 25 | 26 | export async function createAwesomePackage(options) { 27 | const refinedOptions = { 28 | ...options, 29 | targetDirectory: options.targetDirectory || process.cwd() 30 | }; 31 | const currentFilePath = import.meta.url; 32 | const pathname = new URL(currentFilePath).pathname; 33 | 34 | console.log("Bootstrapping package for", options.template); 35 | 36 | const templateBundler = `${options.template}${options.bundler}`; 37 | 38 | const templateDir = path.resolve( 39 | pathname, 40 | `../../templates/${templateBundler}` 41 | ); 42 | 43 | console.log("Using template Directory :", templateDir); 44 | 45 | refinedOptions.templateDirectory = templateDir; 46 | 47 | try { 48 | await access(templateDir, fs.constants.R_OK); 49 | } catch (error) { 50 | console.error("%s Invalid template path", chalk.red.bold("ERROR")); 51 | process.exit(1); 52 | } 53 | 54 | await copyTemplateFiles(refinedOptions, templateBundler); 55 | 56 | console.log("Now you can write code for your awesome package! 🚀"); 57 | console.log("RUN ---"); 58 | console.log("npm i"); 59 | console.log("To Build the package RUN - npm run build"); 60 | } 61 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | -------------------------------------------------------------------------------- /src/cli.js: -------------------------------------------------------------------------------- 1 | import arg from "arg"; 2 | import chalk from "chalk"; 3 | import inquirer from "inquirer"; 4 | import { createAwesomePackage } from "./main"; 5 | import { 6 | TemplateEnum, 7 | TemplateMapper, 8 | BundlerEnum, 9 | BundlerMapper, 10 | LinterConfirmation 11 | } from "./constants"; 12 | 13 | const parseArgsIntoOptions = rawArgs => { 14 | const args = arg( 15 | { 16 | "--yes": Boolean, 17 | "-y": "--yes" 18 | }, 19 | { 20 | argv: rawArgs.slice(2) 21 | } 22 | ); 23 | 24 | // Q - ready to create your awesome package? 25 | 26 | const packageName = args._[0]; 27 | 28 | return { 29 | skipPrompts: args["--yes"] || false, 30 | packageName 31 | }; 32 | }; 33 | 34 | async function promptForTemplate() { 35 | const answers = await inquirer.prompt([ 36 | { 37 | type: "list", 38 | name: "template", 39 | message: "Select your Template language", 40 | choices: [TemplateEnum.JavaScript, TemplateEnum.TypeScript] 41 | } 42 | ]); 43 | 44 | const mappedTemplate = TemplateMapper[answers.template]; 45 | 46 | return mappedTemplate; 47 | } 48 | 49 | async function promptForBundler() { 50 | const answers = await inquirer.prompt([ 51 | { 52 | type: "list", 53 | name: "bundler", 54 | message: "Select your bundler", 55 | choices: [BundlerEnum.Webpack, BundlerEnum.Parcel] 56 | } 57 | ]); 58 | 59 | const mappedBundler = BundlerMapper[answers.bundler]; 60 | 61 | return mappedBundler; 62 | } 63 | 64 | async function promptForEslintPrettier() { 65 | const answers = await inquirer.prompt([ 66 | { 67 | type: "list", 68 | name: "linter", 69 | message: "Add Eslint and Prettier to your package", 70 | choices: [LinterConfirmation.Yes, LinterConfirmation.No] 71 | } 72 | ]); 73 | 74 | return answers.linter; 75 | } 76 | 77 | export async function cli(args) { 78 | // TODO refactor 79 | let options = parseArgsIntoOptions(args); 80 | 81 | const template = await promptForTemplate(); 82 | const bundler = await promptForBundler(); 83 | const linter = await promptForEslintPrettier(); 84 | 85 | options = { 86 | ...options, 87 | template, 88 | bundler, 89 | linter 90 | }; 91 | 92 | await createAwesomePackage(options); 93 | } 94 | --------------------------------------------------------------------------------