From e15cf272638c8f3e12247045aa44bc436be01bbc Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Tue, 29 Oct 2019 13:13:32 +0300 Subject: [PATCH] ci: separate build & test stages --- .gitignore | 3 +++ .travis.yml | 39 ++++++++++++++++++++++++++---- example/jsonrpc.js | 59 ---------------------------------------------- package.json | 21 +++++++++-------- test/index.js | 8 +++---- 5 files changed, 52 insertions(+), 78 deletions(-) delete mode 100644 example/jsonrpc.js diff --git a/.gitignore b/.gitignore index 08161e2..2b73834 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,9 @@ npm-debug.log .DS_Store .esm-cache +# Bundle +target + # Typescript *.tsbuildinfo .tsbuildinfo diff --git a/.travis.yml b/.travis.yml index 3b571ee..3d8ead8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,39 @@ language: node_js -node_js: - - "8" - - "10" - - "12" - - "13" sudo: false + +install: skip +before_install: skip +before_script: skip +script: skip + cache: directories: + - ./target + - target - node_modules + +stages: + - build + - test + +jobs: + include: + - stage: build + node_js: + - "12" + install: + - yarn install + - yarn build + script: skip + - stage: test + node_js: + - "6" + - "8" + - "10" + - "12" + - "13" + install: skip + before_install: skip + before_script: skip + script: + - yarn test diff --git a/example/jsonrpc.js b/example/jsonrpc.js deleted file mode 100644 index b8a8257..0000000 --- a/example/jsonrpc.js +++ /dev/null @@ -1,59 +0,0 @@ -"use strict"; - -const jsonrpc = require('../jsonrpc'); - -const requestObj = jsonrpc.request('123', 'update', {list: [1, 2, 3]}); -const notificationObj = jsonrpc.notification('update', {list: [1, 2, 3]}) -const successObj = jsonrpc.success('123', 'OK') -const errorObj = jsonrpc.error('123', new jsonrpc.JsonRpcError('some error', 99)) -const parseObj = jsonrpc.parse('{"jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": 1}') -const parseObjBatch = jsonrpc.parse( - JSON.stringify([ - {'jsonrpc': '2.0', 'method': 'sum', 'params': [1, 2, 4], 'id': '1'}, - {'jsonrpc': '2.0', 'method': 'foo.get', 'params': {'name': 'myself'}}, - {'jsonrpc': '2.0', 'result': 19, 'id': '2'}, - {'jsonrpc': '2.0', 'error': {'code': -32600, 'message': 'Invalid Request'}, 'id': null}, - ]) -) - -console.log(requestObj) -console.log(notificationObj) -console.log(successObj) -console.log(errorObj) -console.log(parseObj) -console.log(parseObjBatch) - -// RequestObject { -// jsonrpc: '2.0', -// id: '123', -// method: 'update', -// params: { list: [ 1, 2, 3 ] } } -// NotificationObject { -// jsonrpc: '2.0', -// method: 'update', -// params: { list: [ 1, 2, 3 ] } } -// SuccessObject { jsonrpc: '2.0', id: '123', result: 'OK' } -// ErrorObject { -// jsonrpc: '2.0', -// id: '123', -// error: JsonRpcError { message: 'some error', code: 99 } } -// JsonRpcParsed { -// payload: -// RequestObject { jsonrpc: '2.0', id: 1, method: 'subtract', params: [ 42, 23 ] }, -// type: 'request' } -// [ JsonRpcParsed { -// payload: -// RequestObject { jsonrpc: '2.0', id: '1', method: 'sum', params: [Array] }, -// type: 'request' }, -// JsonRpcParsed { -// payload: -// NotificationObject { jsonrpc: '2.0', method: 'foo.get', params: [Object] }, -// type: 'notification' }, -// JsonRpcParsed { -// payload: SuccessObject { jsonrpc: '2.0', id: '2', result: 19 }, -// type: 'success' }, -// JsonRpcParsed { -// payload: -// ErrorObject { jsonrpc: '2.0', id: null, error: [JsonRpcError] }, -// type: 'error' } ] - diff --git a/package.json b/package.json index 8e5b522..6185a10 100644 --- a/package.json +++ b/package.json @@ -6,14 +6,14 @@ ], "license": "MIT", "version": "2.1.0", - "source": "src/main/ts/index.ts", - "main": "jsonrpc.js", - "module": "jsonrpc.mjs", - "unpkg": "jsonrpc.umd.js", - "browser": "jsonrpc.umd.js", - "types": "jsonrpc.d.ts", + "source": "target/jsonrpc.ts", + "main": "target/jsonrpc.js", + "module": "target/jsonrpc.mjs", + "unpkg": "target/jsonrpc.umd.js", + "browser": "target/jsonrpc.umd.js", + "types": "target/jsonrpc.d.ts", "typescript": { - "definition": "jsonrpc.d.ts" + "definition": "target/jsonrpc.d.ts" }, "repository": { "type": "git", @@ -42,10 +42,11 @@ }, "scripts": { "build:tsc": "tsc -p tsconfig.build.json", - "build:microbundle": "microbundle jsonrpc.ts --name jsonrpc --strict", - "build": "yarn build:microbundle", + "build:target": "rm -rf ./target && mkdir ./target && find . -name \"jsonrpc.*\" -exec cp '{}' ./target/ \\;", + "build:microbundle": "microbundle build jsonrpc.ts --name jsonrpc --strict", + "build": "yarn build:microbundle && yarn build:target", "lint": "tslint -p tsconfig.json -t stylish jsonrpc.ts", - "test": "npm run lint && tman" + "test": "yarn lint && tman" }, "files": [ "README.md", diff --git a/test/index.js b/test/index.js index a9798c9..ed5e673 100644 --- a/test/index.js +++ b/test/index.js @@ -3,12 +3,12 @@ const assert = require('assert') const tman = require('tman') -test(require('../jsonrpc.js')) -test(require('../jsonrpc.umd')) -test(require('esm')(module)('../jsonrpc.mjs')) +test(require('../target/jsonrpc.js')) +test(require('../target/jsonrpc.umd')) +test(require('esm')(module)('../target/jsonrpc.mjs')) require('ts-node/register') -test(require('../jsonrpc.ts').default) +test(require('../target/jsonrpc.ts').default) function test (jsonrpc) { tman.suite('jsonrpc', function () {