diff --git a/package.json b/package.json index 4d8076ef..4af44897 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,9 @@ "build:hapi": "lerna exec \"npm run build\" --scope @template/hapi --stream", "build:react-component": "lerna exec \"npm run build && npm run doc\" --scope @template/react-component --stream", "build:react-component-tsx": "lerna exec \"npm run build\" --scope @template/react-component --stream", - "watch": "lerna exec \"tsc -p ./ --types --outDir lib --watch\" --scope tsbb --stream", - "build": "lerna exec \"tsc -p ./ --types --outDir lib\" --scope tsbb --stream", - "type-check": "lerna exec \"tsc --noEmit\" --scope tsbb --stream", + "watch": "lerna exec \"tsc -p ./ --types --outDir lib --watch\" --scope create-tsbb --scope tsbb --stream", + "build": "lerna exec \"tsc -p ./ --types --outDir lib\" --scope create-tsbb --scope tsbb --stream", + "type-check": "lerna exec \"tsc --noEmit\" --scope create-tsbb --scope tsbb --stream", "hoist": "lerna bootstrap --hoist", "clean": "lerna clean --yes", "prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"", diff --git a/packages/create-tsbb/README.md b/packages/create-tsbb/README.md new file mode 100644 index 00000000..e4c195ea --- /dev/null +++ b/packages/create-tsbb/README.md @@ -0,0 +1,64 @@ +## create-tsbb + +[![tsbb](https://user-images.githubusercontent.com/1680273/57547188-94c60100-7390-11e9-93b2-5ebf085bb925.png)](https://github.com/jaywcjlove/tsbb) + +

+ + + + + + + + + + + + + + + + + + +

+ +Creates a [`tsbb`](https://www.travis-ci.org/jaywcjlove/tsbb) application using the command line. + +### Usage + +```shell +$ yarn create tsbb [appName] +# or npm +$ npm create tsbb my-app +# or npx +$ npx create-tsbb my-app +``` + +### Command Help + +Below is a help of commands you might find useful. The example download is from https://jaywcjlove.github.io/tsbb + +```bash +Usage: create-tsbb [options] [--help|h] + +Options: + --version, -v Show version number + --help, -h Displays help information. + --example, -e Example from: https://jaywcjlove.github.io/tsbb , default: "basic" + --force, -f Overwrite target directory if it exists. default: false + --path, -p Specify the download target git address. default: "https://jaywcjlove.github.io/tsbb" + +Example: + npx create-tsbb my-app + yarn create tsbb appName + npm create tsbb my-app + npm create tsbb my-app -f + npm create tsbb my-app -p https://jaywcjlove.github.io/tsbb + +Copyright 2021 +``` + +## License + +[MIT © Kenny Wong](https://github.com/jaywcjlove/tsbb/blob/master/LICENSE) diff --git a/packages/create-tsbb/package.json b/packages/create-tsbb/package.json new file mode 100644 index 00000000..b642a4c2 --- /dev/null +++ b/packages/create-tsbb/package.json @@ -0,0 +1,48 @@ +{ + "name": "create-tsbb", + "version": "1.0.1", + "description": "Creates a TSBB application using the command line.", + "homepage": "https://jaywcjlove.github.io/tsbb", + "author": "Kenny Wong (https://github.com/jaywcjlove)", + "main": "lib/index.js", + "typings": "lib/create.d.ts", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/jaywcjlove/tree/master/create-tsbb" + }, + "bin": { + "create-tsbb": "lib/cli.js" + }, + "scripts": { + "watch": "npm run watch:ts", + "watch:ts": "tsbb watch & npm run build:types -- --watch", + "build": "npm run build:ts && npm run build:types", + "build:ts": "tsbb build", + "build:types": "tsbb types" + }, + "files": [ + "lib", + "src" + ], + "jest": {}, + "keywords": [ + "kkt", + "tsbb", + "create-tsbb", + "react", + "redux", + "rematch", + "uiw", + "redux-saga", + "elm", + "framework", + "frontend" + ], + "devDependencies": { + "tsbb": "2.0.0" + }, + "dependencies": { + "create-kkt": "2.1.3" + } +} diff --git a/packages/create-tsbb/src/cli.ts b/packages/create-tsbb/src/cli.ts new file mode 100644 index 00000000..8ddf63a3 --- /dev/null +++ b/packages/create-tsbb/src/cli.ts @@ -0,0 +1,62 @@ +#!/usr/bin/env node + +import minimist from 'minimist'; +import { create } from 'create-kkt'; + +async function run(): Promise { + try { + const argvs = minimist(process.argv.slice(2)); + if (argvs.h || argvs.help) { + console.log('\n Usage: create-tsbb [options] [--help|h]'); + console.log('\n Options:'); + console.log(' --version, -v', 'Show version number'); + console.log(' --help, -h', 'Displays help information.'); + console.log( + ' --example, -e', + 'Example from: \x1b[34mhttp://jaywcjlove.github.io/tsbb/ \x1b[0m , default: "basic"', + ); + console.log(' --force, -f', 'Overwrite target directory if it exists. default: false'); + console.log( + ' --path, -p', + 'Specify the download target git address. default: "\x1b[34mhttp://jaywcjlove.github.io/tsbb/ \x1b[0m"', + ); + exampleHelp(); + console.log('\n Copyright 2021'); + console.log('\n'); + return; + } + const { version } = require('../package.json'); + if (argvs.v || argvs.version) { + console.log(`\n create-tsbb v${version}\n`); + return; + } + argvs.appName = argvs._[0]; + argvs.path = argvs.p = argvs.path || argvs.p || 'http://jaywcjlove.github.io/tsbb/'; + argvs.force = argvs.f = argvs.force || argvs.f || false; + argvs.example = argvs.e = (argvs.example || argvs.e || 'basic').toLocaleLowerCase(); + create(argvs, exampleHelp); + } catch (error) { + console.log(`\x1b[31m${error.message}\x1b[0m`); + console.log(error); + process.exit(1); + } +} + +export function exampleHelp() { + console.log('\n Example:'); + console.log(' \x1b[35myarn\x1b[0m create tsbb \x1b[33mappName\x1b[0m'); + console.log(' \x1b[35mnpx\x1b[0m create-tsbb \x1b[33mmy-app\x1b[0m'); + console.log(' \x1b[35mnpm\x1b[0m create tsbb \x1b[33mmy-app\x1b[0m'); + console.log(' \x1b[35mnpm\x1b[0m create tsbb \x1b[33mmy-app\x1b[0m -f'); + console.log( + ' \x1b[35mnpm\x1b[0m create tsbb \x1b[33mmy-app\x1b[0m -p \x1b[34mhttp://jaywcjlove.github.io/tsbb/\x1b[0m', + ); +} + +try { + run(); +} catch (error) { + console.log(`\x1b[31m${error.message}\x1b[0m`); + console.log(error); + process.exit(1); +} diff --git a/packages/create-tsbb/src/types/global.d.ts b/packages/create-tsbb/src/types/global.d.ts new file mode 100644 index 00000000..7e3a61cb --- /dev/null +++ b/packages/create-tsbb/src/types/global.d.ts @@ -0,0 +1 @@ +/// diff --git a/packages/create-tsbb/tsconfig.json b/packages/create-tsbb/tsconfig.json new file mode 100644 index 00000000..b587978e --- /dev/null +++ b/packages/create-tsbb/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "esModuleInterop": true, + "declaration": true, + "target": "es2017", + "noImplicitAny": true, + "resolveJsonModule": true, + "moduleResolution": "node", + "sourceMap": true, + "outDir": "lib", + "baseUrl": ".", + "typeRoots": ["node_modules/@types/*", "src/type/*"] + }, + "include": ["src/**/*"] +} diff --git a/packages/tsbb/README.md b/packages/tsbb/README.md index dabc9264..d8308b7a 100644 --- a/packages/tsbb/README.md +++ b/packages/tsbb/README.md @@ -47,8 +47,13 @@ TSBB is a zero-config CLI that helps you develop, test, and publish modern TypeS You will need `Node.js` installed on your system. -```bash -$ npx tsbb create my-project +```shell +$ yarn create tsbb [appName] +# or npm +$ npm create tsbb my-app +# or npx +$ npx create-tsbb my-app + $ cd my-project $ npm run watch # Listen compile .ts files. @@ -61,7 +66,7 @@ or ```bash $ npm install tsbb -g # Create project -$ tsbb create my-project --example=Express +$ create-tsbb my-project --example=express # --- Example name ----------------┴ˇˇˇˇˇˇ ``` @@ -70,9 +75,9 @@ $ tsbb create my-project --example=Express Initialize the project from one of the examples: ```shell -$ npx tsbb create my-app -e +$ npx create-tsbb my-app -e # --- E.g: ----------------┴ˇˇˇˇˇˇˇˇˇˇˇˇˇˇ -# npx tsbb create my-app -e Basic +# npx create-tsbb my-app -e Basic ``` - [**`Basic`**](example/basic) - The [Node.js](https://nodejs.org/en/) base application example.