Skip to content

Commit

Permalink
feat: meet type module, deps revision
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed May 4, 2021
1 parent 65dcc4e commit aa7cb97
Show file tree
Hide file tree
Showing 11 changed files with 2,355 additions and 5,144 deletions.
89 changes: 66 additions & 23 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,70 @@
language: node_js
node_js:
- '12'
cache: yarn
node_js: 14
install: skip
os: linux
dist: focal

before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
jobs:
fast_finish: true
include:
- stage: verify
if: branch != master AND type != pull_request
install: yarn
script:
- yarn build
- if [ "$CI_TEST" != "false" ]; then
yarn test;
fi
- stage: build
if: branch = master
install: yarn
script:
- yarn build
- chmod -R 777 target
# https://docs.travis-ci.com/user/using-workspaces/
workspaces:
create:
name: linux-shared
paths:
- target
- flow-typed
- typings
- docs
- node_modules

after_script:
- ./cc-test-reporter format-coverage -t lcov ./coverage/lcov.info
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
- &test
if: branch = master AND type = pull_request AND env(CI_TEST) != false
stage: test
install: skip
script: yarn test
workspaces:
use: linux-shared
- <<: *test
node_js: 12
- <<: *test
if: branch = master AND type != pull_request AND env(CI_TEST) != false
before_script:
- if [ "$CC_TEST_REPORTER_ID" != "" ]; then
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter;
chmod +x ./cc-test-reporter;
./cc-test-reporter before-build;
fi
script:
- if [ "$CC_TEST_REPORTER_ID" != "" ]; then
yarn test:report;
else
yarn test;
fi
after_script:
- if [ "$CC_TEST_REPORTER_ID" != "" ]; then
./cc-test-reporter format-coverage -t lcov ./coverage/lcov.info;
./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT;
fi

install:
- yarn cache clean
- yarn

script:
- yarn run build
- chmod -R 777 target
- yarn test:report

deploy:
provider: script
skip_cleanup: true
script:
- npx semantic-release
- stage: release
if: branch = master AND type != pull_request AND env(CI_RELEASE) = true
workspaces:
use: linux-shared
install: skip
script: npx -p @qiwi/semrel-toolkit semrel -e @qiwi/semrel-config
26 changes: 15 additions & 11 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
{
"preset": "ts-jest",
"testEnvironment": "node",
"transform": {
"^.+\\.tsx?$": "ts-jest",
"^.+\\.m?jsx?$": "@swissquote/crafty-preset-jest/src/esm-transformer"
},
"transformIgnorePatterns": [
"<rootDir>/node_modules/(?!(read-pkg|lodash-es)/.*)"
],
"collectCoverage": true,
"coveragePathIgnorePatterns": [
"types.ts"
],
"collectCoverageFrom": [
"<rootDir>/src/main/ts/**/*.ts"
"<rootDir>/src/main/**/*.(j|t)s"
],
"testMatch": [
"<rootDir>/src/test/ts/**/*.ts",
"<rootDir>/src/test/js/**/*.js"
"<rootDir>/src/test/js/**/*.js",
"<rootDir>/src/test/ts/**/*.ts"
],
"testPathIgnorePatterns": [
"/node_modules/",
"<rootDir>/src/test/stub"
"/node_modules/"

],
"moduleFileExtensions": [
"ts",
Expand All @@ -23,12 +29,10 @@
"json",
"node"
],
"transform": {
"^.+\\.(ts|tsx)$": "ts-jest"
},
"preset": "ts-jest",
"globals": {
"ts-jest": {
"tsConfig": "tsconfig.test.json"
"tsconfig": "<rootDir>/tsconfig.test.json"
}
}
}
52 changes: 14 additions & 38 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"bin": {
"qiwilicense": "target/es5/cli.js"
},
"type": "module",
"main": "target/bundle/license.js",
"module": "target/bundle/license.mjs",
"unpkg": "target/bundle/license.umd.js",
Expand All @@ -21,22 +22,25 @@
"flow-typed"
],
"scripts": {
"jest": "jest -w 1 --config=jest.config.json",
"lint": "tslint -p tsconfig.test.json src/**/*.ts",
"lint:fix": "yarn lint --fix",
"test": "yarn lint && yarn jest",
"test": "yarn lint && yarn test:unit",
"test:unit": "jest",
"clean": "rimraf target typings",
"build": "yarn clean && yarn build:tpl && yarn build:es5 && yarn build:es6 && yarn build:ts && yarn build:libdef && yarn docs && yarn uglify && yarn build:bundle",
"build:fix-import-ext": "find target/es5 target/es6 -type f -name '*.js' -print0 | xargs -0 sed -i '' -E \"s/from '(\\.\\/[^']+)';$/from '\\1.js';/g\"",
"build:fix-module-dirname": "find target/es5 target/es6 -type f -name '*.js' -print0 | xargs -0 sed -i '' -E \"s/__dirname/\\/file:\\\\\\\\\\\\/\\\\\\\\\\\\/(.+)\\\\\\\\\\\\/\\[^\\/\\]\\/.exec(import.meta.url)[1]/g\"",
"build:fix": "yarn build:fix-import-ext && yarn build:fix-module-dirname",
"build": "yarn clean && yarn build:tpl && yarn build:es5 && yarn build:es6 && yarn build:fix && yarn build:ts && yarn build:libdef && yarn docs && yarn uglify && yarn build:bundle",
"build:tpl": "mkdir -p target/tpl && cp src/main/tpl/* target/tpl",
"build:es5": "mkdir -p target/es5 && tsc -p tsconfig.es5.json",
"build:es6": "mkdir -p target/es6 && tsc -p tsconfig.es6.json",
"build:ts": "cp -r src/main/ts/ target/ts/",
"build:bundle": "microbundle build src/main/ts/index.ts -o target/bundle",
"build:libdef": "dts-generator --project ./ --out typings/index.d.ts --prefix @qiwi/license/target/es5 --name @qiwi/license --main @qiwi/license/target/es5/index --moduleResolution node && libdeffix --dts=./typings/index.d.ts --prefix=@qiwi/license/target/es5 && flowgen typings/index.d.ts --output-file flow-typed/index.flow.js",
"build:libdef": "libdefkit --tsconfig=tsconfig.es5.json --tsconfig=tsconfig.es6.json",
"test:report": "yarn test && yarn push:report",
"push:report": "yarn coveralls:push",
"coveralls:push": "cat ./coverage/lcov.info | coveralls",
"docs": "typedoc --readme README.md --tsconfig tsconfig.json src/main --ignoreCompilerErrors || exit 0",
"docs": "typedoc",
"uglify": "for f in $(find target -name '*.js'); do short=${f%.js}; terser -c -m -o $short.js -- $f; done",
"postupdate": "yarn && yarn build && yarn test"
},
Expand All @@ -54,61 +58,33 @@
},
"homepage": "https://github.com/qiwi/license#readme",
"dependencies": {
"@antongolub/git-root": "^1.5.4",
"@qiwi/substrate": "^1.20.7",
"@types/lodash": "^4.14.168",
"@types/lodash-es": "^4.17.4",
"@types/meow": "^6.0.0",
"@types/read-pkg": "^5.1.0",
"find-git-root": "^1.0.4",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"meow": "^9.0.0",
"read-pkg": "^6.0.0",
"tslib": "^2.2.0"
},
"devDependencies": {
"@swissquote/crafty-preset-jest": "^1.14.0",
"@qiwi/libdefkit": "^2.1.8",
"@qiwi/semantic-release-gh-pages-plugin": "^5.0.7",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
"@semantic-release/github": "^7.2.1",
"@semantic-release/npm": "^7.1.1",
"@types/jest": "^26.0.23",
"@types/jest-json-schema": "^2.1.3",
"coveralls": "^3.1.0",
"eslint-plugin-typescript": "^0.14.0",
"esm": "^3.2.25",
"execa": "^5.0.0",
"jest": "^26.6.3",
"lodash": "^4.17.15",
"microbundle": "^0.13.0",
"rimraf": "^3.0.2",
"semantic-release": "^17.4.2",
"terser": "^5.7.0",
"ts-jest": "^26.5.5",
"tslint": "^6.1.3",
"tslint-config-qiwi": "^1.7.0",
"typedoc": "^0.20.36",
"typedoc-plugin-external-module-name": "^4.0.6",
"typescript": "^4.2.4",
"typescript-eslint-parser": "^22.0.0"
},
"release": {
"branch": "master",
"verifyConditions": [
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/git",
"@qiwi/semantic-release-gh-pages-plugin"
],
"prepare": [
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/git"
],
"publish": [
"@semantic-release/npm",
"@semantic-release/github",
"@qiwi/semantic-release-gh-pages-plugin"
]
"typescript": "^4.2.4"
},
"author": "QIWI <[email protected]>",
"contributors": [
Expand Down
10 changes: 5 additions & 5 deletions src/main/ts/license.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import {gitRootSync} from '@antongolub/git-root'
import {readFileSync, writeFileSync, mkdirSync} from 'fs'
import {resolve} from 'path'
import {template} from 'lodash'
import findGitRoot from 'find-git-root'
import {sync as readPkgSync} from 'read-pkg'
import {template} from 'lodash-es'
import {readPackageSync} from 'read-pkg'

import {
IRenderOpts,
TLanguage,
} from './interface'

const ROOT = resolve(findGitRoot(), '..')
const ROOT = gitRootSync() as string

export const DEFAULT_OPTS: IRenderOpts = {
lang: TLanguage.EN,
file: 'LICENSE',
year: new Date().getFullYear(),
dir: ROOT,
name: readPkgSync().name,
name: readPackageSync().name,
type: 'qosl',
}

Expand Down
5 changes: 2 additions & 3 deletions src/test/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {readFileSync} from 'fs'
import {exec} from 'child_process'
import {render, generate, TLanguage} from '../../main/ts'

const dir = resolve(__dirname, '../tmp')

describe('index', () => {
describe('render', () => {
it('returns license text for the specified language (if exists)', () => {
Expand All @@ -21,7 +23,6 @@ describe('index', () => {
describe('generate', () => {
it('creates / updates target file with license', () => {
const year = '2010-2019' + Math.random()
const dir = resolve(__dirname, '../tmp')
const file = 'lic'
const type = 'mit'
const filePath = resolve(dir, file)
Expand All @@ -45,7 +46,6 @@ describe('index', () => {
describe('bin', () => {
it('parses CLI flags and creates license file', (done) => {
const year = '2010-2019' + Math.random()
const dir = resolve(__dirname, '../tmp')
const lang = TLanguage.RU
const file = 'licFromCli'
const filePath = resolve(dir, file)
Expand All @@ -64,7 +64,6 @@ describe('bin', () => {

exec(cmd, () => {
const result = readFileSync(filePath, 'utf-8')

expect(result.includes(year)).toBeTruthy()
expect(result.includes('«КАК ЕСТЬ»')).toBeTruthy()
expect(result.includes('FOO')).toBeTruthy()
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.es5.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "es6",
"outDir": "target/es6"
"target": "es5",
"outDir": "target/es5"
}
}
4 changes: 2 additions & 2 deletions tsconfig.es6.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "es5",
"outDir": "target/es5"
"target": "es6",
"outDir": "target/es6"
}
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"module": "es2020",
"esModuleInterop": true,
"rootDir": "./src/main/ts/",
"baseUrl": "./src/main/ts/",
Expand Down
5 changes: 4 additions & 1 deletion tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
],
"exclude": [
"node_modules"
]
],
"compilerOptions": {
"module": "es2020"
}
}
17 changes: 7 additions & 10 deletions typedoc.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
{
"name": "protopipe",
"mode": "modules",
"out": "./docs",
"target": "ES6",
"exclude": ["test", "node_modules"],
"externalPattern": "**/node_modules/**",
"excludePrivate": true,
"excludeNotExported": true,
"moduleResolution": "node",
"module": "commonjs",
"entryPoints": ["src/main"],
"exclude": ["src/test", "**/node_modules/**"],
"externalPattern": ["**/node_modules/**"],
"excludePrivate": false,
"hideGenerator": true,
"readme": "none",
"ignoreCompilerErrors": true
"readme": "README.md",
"theme": "minimal",
"tsconfig": "./tsconfig.es5.json"
}
Loading

0 comments on commit aa7cb97

Please sign in to comment.