-
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
Ostad
authored and
Ostad
committed
Apr 12, 2020
0 parents
commit 414bd2f
Showing
19 changed files
with
9,288 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 @@ | ||
MY_SECRET=Hellooooo |
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,2 @@ | ||
setup.js | ||
setup |
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,26 @@ | ||
{ | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"project": "./tsconfig.json" | ||
}, | ||
"plugins": ["@typescript-eslint"], | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"prettier", | ||
"prettier/@typescript-eslint" | ||
], | ||
"env": { | ||
"node": true, | ||
"es6": true | ||
}, | ||
"rules": { | ||
"@typescript-eslint/restrict-plus-operands": "error", | ||
"@typescript-eslint/interface-name-prefix": 0, | ||
"no-async-promise-executor": 1, | ||
"@typescript-eslint/explicit-function-return-type": 0, | ||
"@typescript-eslint/indent": 0, | ||
"no-console": "warn" | ||
} | ||
} |
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,26 @@ | ||
lib-cov | ||
*.seed | ||
*.log | ||
*.csv | ||
*.dat | ||
*.out | ||
*.pid | ||
*.gz | ||
|
||
|
||
pids | ||
logs | ||
results | ||
|
||
npm-debug.log | ||
node_modules | ||
coverage | ||
tmp | ||
issues/ | ||
test/fixtures/test* | ||
|
||
.idea | ||
|
||
out | ||
docs | ||
dist |
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,4 @@ | ||
.npmrc | ||
.env | ||
*.log | ||
docs |
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,4 @@ | ||
{ | ||
"trailingComma": "all", | ||
"tabWidth": 2 | ||
} |
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,15 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Launch Program", | ||
"runtimeArgs": ["-r", "ts-node/register"], | ||
"args": ["${workspaceFolder}/src/app.ts"] | ||
} | ||
] | ||
} |
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 @@ | ||
{ | ||
"typescript.tsdk": "node_modules\\typescript\\lib" | ||
} |
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,64 @@ | ||
# node typescript starter | ||
|
||
### An opinionated combination of my favorite tools for starting a node project | ||
|
||
# Quick Start | ||
|
||
`npx create-ts-starter PROJECT_NAME Vscode` | ||
|
||
OR | ||
|
||
`npm init ts-starter PROJECT_NAME VSCode` | ||
|
||
### notice: you can ignore last param VSCode and open the project in your favorite editor manually! | ||
|
||
OR | ||
|
||
`git clone --depth 1 https://github.com/saostad/node-typescript-starter.git PROJECT_NAME` | ||
|
||
`npm install` | ||
|
||
`npm start` | ||
|
||
## Other Commands | ||
|
||
- to run tests: `npm t` | ||
- to run tests in watch mode: `npm run test:watch` | ||
- to format with prettier: `npm run format` | ||
- to lint with eslint: `npm run lint` | ||
- to generate documentations website: `npm run gen-docs` | ||
- to run in production: `npm run prod` | ||
- to run in docker environment in `docker-compose up` | ||
|
||
## Functionalities | ||
|
||
- dies at unhandled errors (this is very good strategy for production - docker will take care of restart the program after exit) | ||
- pre-configured for work with VSCode debugger | ||
- pre-configured to publish or create module | ||
- pre-configured to run tests with jest | ||
- pre-configured to load environment variables from .env file | ||
- pre-configured to run in docker environment | ||
- pre-configured to log in logs in root folder with default log rotation | ||
- pre-configured to generate api documentations in `docs` folder of root project directory | ||
- type-def for process.env variables | ||
- restart the process after modifying ts files | ||
|
||
## Powered By: | ||
|
||
- [x] [typescript](https://github.com/Microsoft/TypeScript) | ||
- [x] [fast-node-logger](https://github.com/saostad/fast-node-logger) | ||
- [x] [jest](https://github.com/facebook/jest) | ||
- [x] [eslint](https://github.com/eslint/eslint) | ||
- [x] [prettier](https://github.com/prettier/prettier) | ||
- [x] [TypeDoc](https://github.com/TypeStrong/TypeDoc) | ||
- [x] [npm-run-all](https://github.com/mysticatea/npm-run-all) | ||
- [x] [nodemon](https://github.com/remy/nodemon) | ||
- [x] [Docker](https://www.docker.com/) | ||
|
||
## TODO: | ||
|
||
- [ ] add error handling [best practices](https://www.youtube.com/watch?v=62ZRPJkHOX0&list=WL&index=10&t=0s) | ||
- [ ] add pm2 for process monitoring in development | ||
- [ ] add docker restart policy in make sure it restart in production | ||
- [ ] remove all startup overhead to have fastest start up | ||
- [ ] top-level await support |
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,79 @@ | ||
#!/usr/bin/env node | ||
const util = require("util"); | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
|
||
/** Steps: | ||
* 1- create folder | ||
* 2- copy files to created folder | ||
* 3- run npm install | ||
* 4- run git init | ||
* 5- run vscode | ||
*/ | ||
|
||
const defaultFolderName = "node-ts-starter"; | ||
const initWorkingDirectory = process.cwd(); | ||
|
||
let folderName = defaultFolderName; | ||
if (process.argv.slice(2).length > 0) { | ||
folderName = process.argv.slice(2)[0]; | ||
} | ||
|
||
const folderPath = path.join(initWorkingDirectory, folderName); | ||
|
||
let runVsCode = false; | ||
if (process.argv.slice(2).length > 1) { | ||
runVsCode = true; | ||
} | ||
|
||
const repo = "https://github.com/saostad/node-typescript-starter.git"; | ||
console.log(`downloading files from repo ${repo}`); | ||
|
||
const exec = util.promisify(require("child_process").exec); | ||
async function runShellCmd(command) { | ||
try { | ||
const { stdout, stderr } = await exec(command); | ||
console.log(stdout); | ||
console.log(stderr); | ||
} catch { | ||
(err) => { | ||
console.error(err); | ||
}; | ||
} | ||
} | ||
|
||
async function setup() { | ||
try { | ||
await runShellCmd(`git clone --depth 1 ${repo} ${folderName}`); | ||
process.chdir(folderPath); | ||
|
||
console.log(`installing dependencies, please wait...`); | ||
await runShellCmd(`npm i`); | ||
console.log(`dependencies installed successfully!`); | ||
|
||
await runShellCmd(`npx rimraf ./.git`); | ||
console.log(`old .git folder deleted successfully!`); | ||
|
||
fs.appendFileSync(".gitignore", "\r\ndist", "utf8"); | ||
|
||
await runShellCmd(`git init && git add . && git commit -am "init commit"`); | ||
console.log(`new git repo initialized successfully!`); | ||
|
||
console.log(); | ||
console.log(`type command below to start hacking:`); | ||
console.log(); | ||
console.log(`cd ${folderName}`); | ||
console.log(); | ||
console.log(`npm start`); | ||
console.log(); | ||
|
||
if (runVsCode) { | ||
console.log(`starting vscode...`); | ||
runShellCmd(`code ${folderPath}`); | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
} | ||
|
||
setup(); |
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,30 @@ | ||
version: "2.4" | ||
|
||
services: | ||
node_server: | ||
container_name: node_server | ||
image: node:12.16.1 | ||
user: "node" | ||
restart: unless-stopped | ||
working_dir: /home/node/app | ||
environment: | ||
NODE_ENV: development | ||
VIRTUAL_HOST: DOMAIN_NAME_HERE | ||
CERT_NAME: CERT_NAME_HERE | ||
volumes: | ||
- ./:/home/node/app | ||
# uncomment this part if you wanna run it behind a reverse proxy like nginx | ||
# expose: | ||
# - "4002" | ||
# use this part if it runs directly without reverse proxy | ||
# ports: | ||
# - "4002:4002" | ||
# | ||
command: "npm run prod" | ||
# command: "npm install" | ||
# | ||
# uncomment below lines just in production | ||
# networks: | ||
# default: | ||
# external: | ||
# name: nginx-proxy |
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,10 @@ | ||
module.exports = { | ||
roots: ["<rootDir>/src"], | ||
testMatch: [ | ||
"**/__tests__/**/*.+(ts|tsx|js)", | ||
"**/?(*.)+(spec|test).+(ts|tsx|js)", | ||
], | ||
transform: { | ||
"^.+\\.(ts|tsx)$": "ts-jest", | ||
}, | ||
}; |
Oops, something went wrong.