Last active
April 2, 2018 11:02
-
-
Save kurogelee/f64e5b47cb1df052de9b15cef846f441 to your computer and use it in GitHub Desktop.
VSCodeでTypeScript/Node.jsの開発環境を作る(UT・カバレッジ・ログ出力・リリース手順含む) ref: https://qiita.com/kurogelee/items/cf7954f6c23294600ef2
This file contains hidden or 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
{ | |
"commands": [ | |
{ | |
"command": "commands.refresh", | |
"text": "$(sync)", | |
"color": "#FFCC00" | |
}, | |
{ | |
"command": "workbench.action.tasks.runTask", | |
"arguments": ["ts-node"], | |
"text": "$(triangle-right) ts-node", | |
"color": "#CCFFCC", | |
"filterFileRegex": "\\.ts" | |
}, | |
{ | |
"command": "workbench.action.tasks.runTask", | |
"arguments": ["mocha"], | |
"text": "$(octoface) mocha", | |
"color": "#EEBBAA", | |
"filterFileRegex": "\\.ts" | |
}, | |
{ | |
"command": "workbench.action.terminal.toggleTerminal", | |
"text": "$(terminal)" | |
} | |
] | |
} |
This file contains hidden or 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
{ | |
"log4js": { | |
"appenders": { | |
"out": { | |
"type": "stdout" | |
}, | |
"error": { | |
"type": "dateFile", | |
"filename": "logs/error.log", | |
"daysToKeep": 31 | |
} | |
}, | |
"categories": { | |
"default": { | |
"appenders": [ | |
"error" | |
], | |
"level": "INFO" | |
}, | |
"console": { | |
"appenders": [ | |
"out", | |
"error" | |
], | |
"level": "INFO" | |
} | |
} | |
} | |
} |
This file contains hidden or 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
{ | |
"log4js": { | |
"categories": { | |
"default": { | |
"level": "DEBUG" | |
}, | |
"console": { | |
"level": "DEBUG" | |
} | |
} | |
} | |
} |
This file contains hidden or 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
C:\>node -v | |
v8.10.0 | |
C:\>npm -v | |
3.10.6 | |
C:\>code -v | |
1.21.1 | |
79b44aa704ce542d8ca4a3cc44cfca566e7720f1 | |
x64 |
This file contains hidden or 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
mkdir ts-sample | |
cd ts-sample | |
npm init -y | |
mkdir .vscode src test config | |
npm i -SEB config log4js | |
npm i -DE typescript ts-node tslint | |
npm i -DE @types/node @types/config | |
npm i -DE espower-typescript power-assert mocha @types/mocha | |
npm i -DE nyc | |
npm i -DE rimraf cpx | |
node_modules\.bin\tsc --init | |
npm i -g npm-run | |
npm-run tslint --init | |
code --install-extension eg2.tslint | |
code --install-extension fabiospampinato.vscode-commands |
This file contains hidden or 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
node_modules\.bin\tsc |
This file contains hidden or 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
node build/main.js |
This file contains hidden or 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
node_modules\.bin\ts-node src/main.ts |
This file contains hidden or 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
npm i -g npm-run |
This file contains hidden or 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
npm-run ts-node src/main.ts |
This file contains hidden or 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
npm i -DE tslint |
This file contains hidden or 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
mkdir ts-sample | |
cd ts-sample | |
npm init -y |
This file contains hidden or 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
code --install-extension eg2.tslint |
This file contains hidden or 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
npm-run tslint --init |
This file contains hidden or 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
npm i -DE @types/node | |
npm i -DE espower-typescript power-assert mocha @types/mocha |
This file contains hidden or 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
code --install-extension fabiospampinato.vscode-commands |
This file contains hidden or 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
npm i -DE nyc |
This file contains hidden or 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
npm i -SEB config log4js | |
npm i -DE @types/config |
This file contains hidden or 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
npm i -DE rimraf cpx |
This file contains hidden or 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
npm WARN [email protected] No description | |
npm WARN [email protected] No repository field. | |
npm WARN [email protected] No license field. |
This file contains hidden or 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
mkdir .vscode src test config |
This file contains hidden or 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
├─.vscode | |
├─bin # リリース後のjsソース配置先 | |
├─build # ビルド用の一時ディレクトリ | |
│ ├─src # jsソース出力先 | |
│ └─test # jsテスト出力先 | |
├─config | |
├─coverage | |
├─logs | |
├─node_modules | |
├─src # tsソース | |
└─test # tsテスト |
This file contains hidden or 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
npm i -DE typescript ts-node |
This file contains hidden or 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
node_modules\.bin\tsc --init |
This file contains hidden or 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
{ | |
"version": "0.2.0", | |
"configurations": [ | |
{ | |
"type": "node", | |
"request": "launch", | |
"name": "ts-node[debug]", | |
"program": "${workspaceFolder}/node_modules/ts-node/dist/bin.js", | |
"args": [ | |
"${relativeFile}" | |
], | |
"console": "integratedTerminal" | |
}, | |
{ | |
"type": "node", | |
"request": "launch", | |
"name": "mocha[debug]", | |
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", | |
"args": [ | |
"--no-timeouts", | |
"--colors", | |
"--require", | |
"espower-typescript/guess", | |
"${relativeFile}" | |
], | |
"console": "integratedTerminal" | |
} | |
] | |
} |
This file contains hidden or 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
"use strict"; | |
const message = "world"; | |
console.log(`Hello ${message}`); | |
//# sourceMappingURL=main.js.map |
This file contains hidden or 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
import assert = require("assert"); | |
import {main} from "../src/main"; | |
describe("main()", () => { | |
const message = "world!"; | |
it("hello world!", () => { | |
assert(main(message) === "Hello world"); | |
}); | |
}); |
This file contains hidden or 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
#!/usr/bin/env node | |
process.env.NODE_CONFIG_DIR = __dirname + "/../config"; | |
import * as config from "config"; | |
import * as log4js from "log4js"; | |
log4js.configure(config.get("log4js")); | |
const log = log4js.getLogger(); | |
const consoleLog = log4js.getLogger("console"); | |
export function main(argv: string[]) { | |
try { | |
consoleLog.debug(`argv: ${argv}`); | |
const message: string = argv[2]; | |
return `Hello ${message.charAt(0)}`; | |
} catch (e) { | |
log.error(e); | |
} finally { | |
log4js.shutdown((e) => e && console.log(e)); | |
} | |
} | |
if (require.main === module) { | |
main(process.argv); | |
} | |
This file contains hidden or 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
{ | |
"name": "ts-sample", | |
"version": "1.0.0", | |
"private": true, | |
"scripts": { | |
"test": "nyc -i ts-node/register --temp-directory coverage/.nyc -r text -r html -n test/**/*.ts -n src/**/*.ts -e .ts mocha test/**/*.ts", | |
"release": "rimraf build bin && tsc && cpx build/src/** bin && cd build && npm pack -cwd .." | |
}, | |
"files": [ | |
"bin", | |
"config/default.json" | |
], | |
"bin": { | |
"sample": "bin/main.js" | |
}, | |
"devDependencies": { | |
"@types/config": "0.0.34", | |
"@types/mocha": "2.2.48", | |
"@types/node": "9.4.7", | |
"cpx": "1.5.0", | |
"espower-typescript": "8.1.3", | |
"mocha": "5.0.4", | |
"nyc": "11.6.0", | |
"power-assert": "1.4.4", | |
"rimraf": "2.6.2", | |
"ts-node": "5.0.1", | |
"tslint": "5.9.1", | |
"typescript": "2.7.2" | |
}, | |
"dependencies": { | |
"config": "1.30.0", | |
"log4js": "2.5.3" | |
}, | |
"bundledDependencies": [ | |
"config", | |
"log4js" | |
] | |
} |
This file contains hidden or 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
{ | |
"version": "2.0.0", | |
"tasks": [ | |
{ | |
"label": "ts-node", | |
"type": "shell", | |
"command": "npm-run ts-node ${relativeFile}" | |
}, | |
{ | |
"label": "mocha", | |
"type": "shell", | |
"command": "npm-run mocha -r espower-typescript/guess ${relativeFile}" | |
} | |
] | |
} |
This file contains hidden or 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
Show hidden characters
{ | |
"compilerOptions": { | |
"target": "ES2017", | |
"module": "commonjs", | |
"sourceMap": true, | |
"outDir": "build", | |
"strict": true | |
}, | |
"include": [ | |
"src/**/*", | |
"test/**/*" | |
] | |
} |
This file contains hidden or 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
{ | |
"defaultSeverity": "warn", | |
"extends": [ | |
"tslint:recommended" | |
], | |
"jsRules": {}, | |
"rules": { | |
"no-console": false | |
}, | |
"rulesDirectory": [] | |
} |
This file contains hidden or 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
{ | |
"compilerOptions": { | |
"target": "es5", | |
"module": "commonjs", | |
"strict": true, | |
"esModuleInterop": true | |
} | |
} |
This file contains hidden or 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
{ | |
"name": "ts-sample", | |
"version": "1.0.0", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"description": "" | |
} |
This file contains hidden or 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
{ | |
"defaultSeverity": "error", | |
"extends": [ | |
"tslint:recommended" | |
], | |
"jsRules": {}, | |
"rules": {}, | |
"rulesDirectory": [] | |
} |
This file contains hidden or 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
"scripts": { | |
"test": "nyc -i ts-node/register --temp-directory coverage/.nyc -r text -r html -n test/**/*.ts -n src/**/*.ts -e .ts mocha test/**/*.ts", | |
"release": "rimraf build bin && tsc && cpx build/src/** bin && cd build && npm pack -cwd .." | |
}, | |
"files": [ | |
"bin", | |
"config/default.json" | |
], | |
"bin": { | |
"sample": "bin/main.js" | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment