Skip to content

Commit

Permalink
feat: 工程化配置加入[no-ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
mapengda committed Mar 19, 2021
1 parent 6d68e45 commit 37b6cd3
Show file tree
Hide file tree
Showing 13 changed files with 314 additions and 119 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
77 changes: 77 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
module.exports = {
"env": {
"browser": true,
"commonjs": true,
"es6": true
},
"globals": {
"module": true
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"no-multiple-empty-lines": [
"error",
{
"max": 1
}
],
"comma-dangle": [
"error",
"only-multiline"
],
"function-paren-newline": [
"error",
"multiline-arguments"
],
"no-whitespace-before-property": [
"error"
],
"space-infix-ops": [
"error"
],
"space-unary-ops": [
"error"
],
"rest-spread-spacing": [
"error",
"never"
],
"object-property-newline": [
"error",
{
"allowAllPropertiesOnSameLine": true
}
],
"no-multi-spaces": [
"error"
],
"keyword-spacing": [
"error"
],
"object-curly-spacing": [
"error",
"always",
{
"objectsInObjects": false
}
],
"space-before-blocks": "error",
"comma-spacing": [
"error"
],
"@typescript-eslint/explicit-module-boundary-types": 0,
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-irregular-whitespace": 0
},
"plugins": [
"@typescript-eslint"
],
"extends": [
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser"
}
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit $1
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install lint-staged
40 changes: 40 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

language: node_js
node_js:
- 14

env:
- TEST=1 BUILD_NAME=bd

install:
- npm install

branches:
only:
- main
- /^ci-.*$/

stages:
- test
- name: publish
if: commit_message =~ /release/

_shared_build: &bd
script: npm run $BUILD_NAME
if: env(BUILD_NAME) =~ /^\w/

jobs:
exclude:
- if: branch = dev OR commit_message =~ /(no-ci)/
include:
- stage: test
script: npm run test

- stage: publish
script: npm run $BUILD_NAME
deploy:
provider: npm
api_key: $NPM_API_KEY
email: $EMAIL
on:
branch: main
14 changes: 14 additions & 0 deletions config/jest/cssTransform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";

// This is a custom Jest transformer turning style imports into empty objects.
// http://facebook.github.io/jest/docs/tutorial-webpack.html

module.exports = {
process() {
return "module.exports = {};";
},
getCacheKey() {
// The output is always the same.
return "cssTransform";
},
};
12 changes: 12 additions & 0 deletions config/jest/fileTransform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use strict";

const path = require("path");

// This is a custom Jest transformer turning file imports into filenames.
// http://facebook.github.io/jest/docs/tutorial-webpack.html

module.exports = {
process(src, filename) {
return `module.exports = ${JSON.stringify(path.basename(filename))};`;
},
};
7 changes: 7 additions & 0 deletions config/jest/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

// jest.mock("app/utils", () => {
// return {
// store: {}, // require("../src/app/utils/index"),
// PicFilter: jest.fn(),
// };
// });
74 changes: 37 additions & 37 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
module.exports = {
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
transformIgnorePatterns: ['\\\\node_modules\\\\'],

// Automatically clear mock calls and instances between every test
clearMocks: true,
// The directory where Jest should output its coverage files
coverageDirectory: 'coverage',

// An array of file extensions your modules use
moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node', 'web.js'],

// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
"<rootDir>/config/jest/fileTransform.js",
'\\.(css|less)$': "<rootDir>/config/jest/cssTransform.js",
'app\\/(.*)$': '<rootDir>/src/app/$1',
'@\\/(.*)$': '<rootDir>/src/app/$1',
},

// A preset that is used as a base for Jest's configuration
preset: 'ts-jest',

// The test environment that will be used for testing
testEnvironment: 'node',
setupFiles: [
// "<rootDir>/config/polyfills.js",
],
testPathIgnorePatterns: ["scripts"],
transform: {
// "^.+\\.(js|jsx)$": "<rootDir>/node_modules/babel-jest",
"^.+\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest",
// "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
// "^(?!.*\\.(css|json)$)": "<rootDir>/config/jest/fileTransform.js"
},
}
module.exports = {
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
transformIgnorePatterns: ['node_modules'],

// Automatically clear mock calls and instances between every test
clearMocks: true,
// The directory where Jest should output its coverage files
coverageDirectory: 'coverage',

// An array of file extensions your modules use
moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node', 'web.js'],

// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
"<rootDir>/config/jest/fileTransform.js",
'\\.(css|less)$': "<rootDir>/config/jest/cssTransform.js",
'app\\/(.*)$': '<rootDir>/src/app/$1',
'@\\/(.*)$': '<rootDir>/src/app/$1',
},

// A preset that is used as a base for Jest's configuration
preset: 'ts-jest',

// The test environment that will be used for testing
testEnvironment: 'node',
setupFiles: [
// "<rootDir>/config/polyfills.js",
],
testPathIgnorePatterns: ["scripts"],
transform: {
// "^.+\\.(js|jsx)$": "<rootDir>/node_modules/babel-jest",
"^.+\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest",
// "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
// "^(?!.*\\.(css|json)$)": "<rootDir>/config/jest/fileTransform.js"
},
}
35 changes: 31 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,48 @@
"author": "马鹏达",
"email": "1251208555@qq.com",
"scripts": {
"gen": "yarn tsc --declaration",
"test": "jest --config=jest.config.js"
"bd": "yarn tsc --declaration",
"test": "jest --config=jest.config.js",
"release": "standard-version",
"release:rc": "standard-version --prerelease rc",
"pup": "npm run release && git push --follow-tags origin master",
"pub": "npm run pup && npm publish",
"cz": "cz"
},
"keywords": ["vite", "vite plugin", "commonjs to es module"],
"keywords": [
"vite",
"vite plugin",
"commonjs to es module"
],
"dependencies": {
"@babel/cli": "^7.13.10",
"@babel/core": "^7.13.10",
"@babel/preset-env": "^7.13.10",
"glob": "^7.1.6"
},
"devDependencies": {
"@commitlint/cli": "^12.0.1",
"@commitlint/config-conventional": "^12.0.1",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.33",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"babel-jest": "^26.6.3",
"commitizen": "^4.2.3",
"eslint": "^7.22.0",
"husky": "^5.1.3",
"jest": "^26.6.3",
"lint-staged": "^10.5.4",
"standard-version": "^9.1.1",
"ts-jest": "^26.5.3",
"typescript": "^4.2.3"
},
"lint-staged": {
"*.[jt]sx?": "eslint --fix"
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
}
}
}
Loading

0 comments on commit 37b6cd3

Please sign in to comment.