Skip to content

Commit

Permalink
chore(build): build and test properly when running CI scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
flavio-lisboa-brlink committed Oct 25, 2021
1 parent 0bdfcd4 commit 70a3678
Show file tree
Hide file tree
Showing 17 changed files with 155 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .husky/commit-msg
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
. "$(dirname "$0")/_/husky.sh"
. "$(dirname "$0")/common.sh"

npx commitlint --edit $1
pnpm commitlint --edit $1
2 changes: 1 addition & 1 deletion .husky/pre-commit
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
. "$(dirname "$0")/_/husky.sh"
. "$(dirname "$0")/common.sh"

npx lint-staged
pnpm lint-staged
20 changes: 20 additions & 0 deletions jest-base.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
moduleFileExtensions: ['js', 'json', 'ts'],
rootDir: 'test',
testRegex: '\\.(test|spec)\\.ts$',
transform: {
'^.+\\.(t|j)s$': 'ts-jest',
},
collectCoverageFrom: ['**/*.(t|j)s'],
moduleNameMapper: {
'^src/(.*)': '<rootDir>/../src/$1',
'^test/(.*)': '<rootDir>/$1',
'^src': '<rootDir>/../src',
'^package\\.json$': '<rootDir>/../package.json',
},
coverageDirectory: '../coverage',
testEnvironment: 'node',
coverageReporters: [
'json-summary',
],
};
6 changes: 6 additions & 0 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
'packages/*/{src,apps,libs,test}/**/*.{js,ts}': [
'pnpm run -r lint:staged-noargs',
'pnpm run -r format:staged-noargs',
],
};
7 changes: 7 additions & 0 deletions packages/datever-cli/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
};
6 changes: 6 additions & 0 deletions packages/datever-cli/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all",
"arrowParens": "avoid",
"printWidth": 120
}
1 change: 1 addition & 0 deletions packages/datever-cli/commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../commitlint.config');
1 change: 1 addition & 0 deletions packages/datever-cli/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../jest-base.config');
49 changes: 47 additions & 2 deletions packages/datever-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,62 @@
"url": "https://github.com/flisboac/datever/issues"
},
"bin": {
"datever": "dist/ts/src/cli/main.js"
"datever": "dist/main/src/cli/main.js"
},
"files": [
"dist",
"README.md"
],
"scripts": {
"ci:build:version": "pnpm run build && pnpm run lint && pnpm run format && pnpm run test",
"ci:build:publish": "pnpm run build && pnpm run test:cov && pnpm run ci:test:cov-badges && pnpm run ci:git:add-badges && pnpm run docs:readme && git add README.md && pnpm run ci:git:commit-docs",
"ci:test:cov-badges": "pnpm run test:cov-badges || echo \"*** WARNING: Failed to generate test badges.\"",
"ci:git:add-badges": "git add img/badges || echo \"*** WARNING: Ignoring badge file \\\"${badge}\\\".\"",
"ci:git:commit-docs": "pnpm run git:check-clean || git commit --message \"chore(release): update documentation and badges\"",
"build": "pnpm run build:main",
"build:main": "tsc -p tsconfig.main.json && tsconfig-replace-paths -p tsconfig.main.json -s . -o dist/ts",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\"",
"lint:fix": "pnpm run lint -- --fix",
"lint:staged-noargs": "eslint --max-warnings 0",
"format": "pnpm run format:cli -- --check",
"format:cli": "prettier \"src/**/*.ts\" \"test/**/*.ts\"",
"format:fix": "pnpm run format:cli -- --write",
"format:staged-noargs": "prettier --check",
"test": "jest --passWithNoTests",
"test:cov": "jest --coverage --passWithNoTests --coverageReporters=\"json-summary\"",
"test:cov-badges": "jest-coverage-badges --input coverage/coverage-summary.json --output ./img/badges",
"test:dev": "dotenv -- jest",
"test:watch": "pnpm run test:dev -- --watch",
"test:debug": "dotenv -- node --inspect-brk=9230 -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"git:check-clean": "repository-check-dirty",
"git:why": "lint-staged",
"docs:readme": "doctoc --update-only --bitbucket README.md"
},
"dependencies": {
"datever": "workspace:*",
"tslib": "^2.3.1"
},
"devDependencies": {
"@types/node": "^16.11.4"
"@types/jest": "^27.0.2",
"@types/node": "^16.11.4",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"doctoc": "^2.1.0",
"dotenv-cli": "^4.0.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-import-resolver-typescript": "^2.5.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.3.1",
"jest-coverage-badges": "^1.1.2",
"lint-staged": "^11.2.3",
"prettier": "^2.4.1",
"repository-check-dirty": "^3.1.1",
"ts-jest": "^27.0.7",
"ts-node": "^10.3.0",
"ts-node-dev": "^1.1.8",
"tsconfig-replace-paths": "0.0.5",
"typescript": "^4.4.4"
}
}
3 changes: 3 additions & 0 deletions packages/datever-cli/test/unit/lib/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe('tests', () => {
it('should be implemented ASAP!', () => expect(true).toBe(true));
});
5 changes: 3 additions & 2 deletions packages/datever-cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
"rootDir": "./",
"outDir": "./dist/ts",
"baseUrl": ".",
"types": ["node"]
"types": ["node", "jest"]
},
"exclude": [
"node_modules",
"build",
"dist"
],
"include": [
"src"
"src",
"test"
]
}
13 changes: 13 additions & 0 deletions packages/datever-cli/tsconfig.main.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "CommonJS",
"rootDir": "./",
"outDir": "./dist/main",
"baseUrl": ".",
"types": ["node"]
},
"include": [
"src"
]
}
18 changes: 1 addition & 17 deletions packages/datever/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1 @@
module.exports = {
moduleFileExtensions: ['js', 'json', 'ts'],
rootDir: 'test',
testRegex: '\\.(test|spec)\\.ts$',
transform: {
'^.+\\.(t|j)s$': 'ts-jest',
},
collectCoverageFrom: ['**/*.(t|j)s'],
moduleNameMapper: {
'^src/(.*)': '<rootDir>/../src/$1',
'^test/(.*)': '<rootDir>/$1',
'^src': '<rootDir>/../src',
'^package\\.json$': '<rootDir>/../package.json',
},
coverageDirectory: '../coverage',
testEnvironment: 'node',
};
module.exports = require('../../jest-base.config');
6 changes: 0 additions & 6 deletions packages/datever/lint-staged.config.js

This file was deleted.

10 changes: 5 additions & 5 deletions packages/datever/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@
"build:parser": "shx mkdir -p dist/main/src/lib/parser && shx mkdir -p dist/module/src/lib/parser && peggy --format commonjs -o dist/main/src/lib/parser/rawParser.js src/lib/parser/rawParser.pegjs && peggy --format es -o dist/main/src/lib/parser/rawParser.js src/lib/parser/rawParser.pegjs",
"build:parser:in-src": "peggy --format es -o src/lib/parser/rawParser.js src/lib/parser/rawParser.pegjs",
"ci:build:version": "pnpm run build && pnpm run lint && pnpm run format && pnpm run test",
"ci:build:publish": "pnpm run build && pnpm run test:cov && pnpm run ci:test:cov-badges && pnpm run ci:git:add-badges && pnpm run docs:readme && git add README.md && ci:git:commit-docs",
"ci:test:cov-badges": "pnpm run test:cov-badges && || echo \"*** WARNING: Failed to generate test badges.\"",
"ci:git:add-badges": "git add img/badges || echo \"*** WARNING: Ignoring badge file \\\"${badge}\\\".",
"ci:build:publish": "pnpm run build && pnpm run test:cov && pnpm run ci:test:cov-badges && pnpm run ci:git:add-badges && pnpm run docs:readme && git add README.md && pnpm run ci:git:commit-docs",
"ci:test:cov-badges": "pnpm run test:cov-badges || echo \"*** WARNING: Failed to generate test badges.\"",
"ci:git:add-badges": "git add img/badges || echo \"*** WARNING: Ignoring badge file \\\"${badge}\\\".\"",
"ci:git:commit-docs": "pnpm run git:check-clean || git commit --message \"chore(release): update documentation and badges\"",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\"",
"lint:fix": "pnpm run lint -- --fix",
"lint:staged-noargs": "eslint --max-warnings 0",
"format": "pnpm run format:cli -- --check",
"format:cli": "prettier \"src/**/*.ts\" \"test/**/*.ts\"",
"format:fix": "pnpm run format:cli -- --write",
"format:staged-noargs": "prettier",
"format:staged-noargs": "prettier --check",
"test": "jest --passWithNoTests",
"test:cov": "jest --coverage --passWithNoTests",
"test:cov": "jest --coverage --passWithNoTests --coverageReporters=\"json-summary\"",
"test:cov-badges": "jest-coverage-badges --input coverage/coverage-summary.json --output ./img/badges",
"test:dev": "dotenv -- jest",
"test:watch": "pnpm run test:dev -- --watch",
Expand Down
40 changes: 40 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"rootDir": "./",
"outDir": "./dist/ts",
"baseUrl": ".",
"paths": {
"src/*": [
"src/*"
Expand Down

0 comments on commit 70a3678

Please sign in to comment.