Skip to content

Instantly share code, notes, and snippets.

@ssube

ssube/Makefile Secret

Created May 28, 2017 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssube/157d4fc6f411966ac06c2498f087be9a to your computer and use it in GitHub Desktop.
Save ssube/157d4fc6f411966ac06c2498f087be9a to your computer and use it in GitHub Desktop.
webpack typescript mocha
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import * as sinonChai from 'sinon-chai';
chai.use(chaiAsPromised);
chai.use(sinonChai);
const context = (require as any).context('.', true, /Test.*$/);
context.keys().forEach(context);
module.exports = context;
GIT_REV = $(shell git rev-parse HEAD)
GIT_REF = $(shell git rev-parse --abbrev-ref HEAD)
CI_COMMIT_REF_SLUG ?= $(GIT_REF)
CI_ENVIRONMENT_SLUG ?= local
CI_RUNNER_DESCRIPTION ?= $(shell hostname)
NODE_BIN := ./node_modules/.bin
NODE_DBG ?= --inspect-brk --nolazy
TARGET_PATH ?= ./target
TARGET_MAIN ?= $(TARGET_PATH)/main-bundle.js
BABEL_OPTS ?= --source-maps inline
BABEL_PATHS := $(TARGET_PATH)/tsc --out-dir $(TARGET_PATH)/babel
DEPLOY_ENV ?= $(CI_ENVIRONMENT_SLUG)
DEPLOY_REF ?= $(CI_COMMIT_REF_SLUG)
DEPLOY_REV ?= $(GIT_REV)
DEPLOY_RUN ?= $(CI_RUNNER_DESCRIPTION)
DEPLOY_URL ?= https://api.rollbar.com/api/1/deploy/
DEPLOY_USER ?= $(shell whoami)
GAME_OPTS ?= --config='json:["file://base/src/res/reference.yml"]' --log='json:[{"level": "debug", "streams": [{"path": "./output.log"}]}]'
GAME_TERM ?= --bootstrap='json:{"controller": "terminal-controller", "type": "node-bootstrap"}'
GAME_ELECT ?= --bootstrap='json:{"controller": "electron-controller", "type": "node-bootstrap"}'
MOCHA_MULTI ?= --reporter mocha-multi --reporter-options json="$(TARGET_PATH)/mocha.json",spec
MOCHA_OPTS ?= --colors --sort --grep "$(MOCHA_GREP)" --ui bdd --check-leaks # --require "$(TARGET_PATH)/main-bundle.js"
TYPES_OPTS ?= --pretty
TYPES_PATHS := --project ./tsconfig.json --outDir "$(TARGET_PATH)/tsc"
WEBPACK_OPTS ?= --config "config/webpack.js"
all: build test
build: ## build the distributable version of the application
$(NODE_BIN)/webpack $(WEBPACK_OPTS)
test:
$(NODE_BIN)/mocha $(MOCHA_OPTS) target/test-bundle.js
clean: ## clean up temporary files
rm -rf $(TARGET_PATH)
deploy: deploy-sync deploy-notify
deploy-notify:
curl $(DEPLOY_URL) \
-F access_token=$(DEPLOY_TOKEN) \
-F environment=$(DEPLOY_ENV) \
-F revision=$(DEPLOY_REV) \
-F local_username=$(DEPLOY_USER) \
-F comment="runner $(DEPLOY_RUN) deployed $(DEPLOY_REF) to $(DEPLOY_ENV)"
deploy-sync:
rclone --help
update:
yarn outdated
# run and debug tasks
run-terminal:
node $(TARGET_MAIN) $(GAME_OPTS) ${GAME_TERM}
debug-terminal:
node $(NODE_DBG) $(TARGET_MAIN) $(GAME_OPTS) ${GAME_TERM}
# debug logs and reporting
view-log:
cat output.log | $(NODE_BIN)/bunyan --pager -o short
{
"compileOnSave": false,
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": false,
"baseUrl": "../",
"experimentalDecorators": true,
"importHelpers": true,
"jsx": "react",
"lib": [
"dom",
"es2017"
],
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"paths": {
"main/*": [
"src/main/*"
],
"test/*": [
"src/test/*"
]
},
"strictNullChecks": true,
"target": "es2017",
"types": [
"@reactivex/rxjs",
"blessed",
"bluebird",
"bunyan",
"chai",
"chai-as-promised",
"js-yaml",
"lodash",
"mathjs",
"mocha",
"nopt",
"sinon-chai",
"source-map-support",
"uuid"
],
"typeRoots": [
"node_modules/@types",
"node_modules"
]
},
"exclude": [
"node_modules"
],
"include": [
"../src/**/*"
]
}
const {resolve} = require('path');
const {CheckerPlugin, TsConfigPathsPlugin} = require('awesome-typescript-loader');
const tsconfig = require('./tsconfig.json');
const path = {
main: resolve(__dirname, '..', 'src', 'main'),
target: resolve(__dirname, '..', 'target'),
test: resolve(__dirname, '..', 'src', 'test')
};
module.exports = {
devtool: 'source-map',
entry: {
main: './src/main/index.ts',
test: './src/test/harness.ts'
},
module: {
rules: [{
test: /\.tsx?$/,
enforce: 'pre',
loader: 'tslint-loader',
options: {
configFile: 'config/tslint.json'
}
}, {
test: /\.tsx?$/,
loader: 'awesome-typescript-loader',
options: {
configFileName: 'config/tsconfig.json'
}
}]
},
output: {
filename: '[name]-bundle.js',
path: path.target
},
plugins: [
new CheckerPlugin()
],
resolve: {
alias: [{
name: 'dtrace-provider',
alias: resolve(path.main, 'shim.ts')
}, {
name: 'term.js',
alias: resolve(path.main, 'shim.ts')
}, {
name: 'pty.js',
alias: resolve(path.main, 'shim.ts')
}, {
name: 'handlebars',
alias: 'handlebars/dist/handlebars.js'
}, {
name: 'main',
alias: path.main,
onlyModule: false
}, {
name: 'test',
alias: path.test,
onlyModule: false
}],
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
plugins: [
new TsConfigPathsPlugin({tsconfig, compiler: 'typescript'})
]
},
target: 'node'
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment