init
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
dist
|
||||
node_modules
|
||||
pnpm-lock.yaml
|
||||
package-lock.json
|
||||
yarn.lock
|
||||
docker
|
||||
Dockerfile*
|
||||
LICENSE
|
||||
yarn-error.log
|
||||
.history
|
||||
.vscode
|
||||
.dockerignore
|
||||
.DS_Store
|
||||
.eslintignore
|
||||
.editorconfig
|
||||
.gitignore
|
||||
.prettierignore
|
||||
.eslintcache
|
||||
*.lock
|
||||
**/*.svg
|
||||
**/*.md
|
||||
**/*.svg
|
||||
**/*.ejs
|
||||
**/*.html
|
||||
**/*.png
|
||||
**/*.toml
|
||||
@@ -0,0 +1,8 @@
|
||||
/** @type {import("eslint").Linter.Config} */
|
||||
module.exports = {
|
||||
root: true,
|
||||
parserOptions: {
|
||||
project: true,
|
||||
},
|
||||
extends: [require.resolve('@3rapp/code-config/eslint/lib-ts')],
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
# compiled output
|
||||
/dist
|
||||
/node_modules
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
pnpm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
|
||||
# Tests
|
||||
/coverage
|
||||
/.nyc_output
|
||||
|
||||
# IDEs and editors
|
||||
/.idea
|
||||
.project
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
|
||||
# IDE - VSCode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
@@ -0,0 +1,26 @@
|
||||
dist
|
||||
node_modules
|
||||
pnpm-lock.yaml
|
||||
package-lock.json
|
||||
yarn.lock
|
||||
docker
|
||||
Dockerfile*
|
||||
LICENSE
|
||||
yarn-error.log
|
||||
.history
|
||||
.vscode
|
||||
.dockerignore
|
||||
.DS_Store
|
||||
.eslintignore
|
||||
.editorconfig
|
||||
.gitignore
|
||||
.prettierignore
|
||||
.eslintcache
|
||||
*.lock
|
||||
**/*.svg
|
||||
**/*.md
|
||||
**/*.svg
|
||||
**/*.ejs
|
||||
**/*.html
|
||||
**/*.png
|
||||
**/*.toml
|
||||
@@ -0,0 +1,17 @@
|
||||
module.exports = {
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all",
|
||||
"printWidth": 100,
|
||||
"proseWrap": "never",
|
||||
"endOfLine": "auto",
|
||||
"semi": true,
|
||||
"tabWidth": 4,
|
||||
"overrides": [
|
||||
{
|
||||
"files": ".prettierrc",
|
||||
"options": {
|
||||
"parser": "json"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "@3rapp/utils",
|
||||
"version": "0.0.0",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"main": "./dist/cjs/index.js",
|
||||
"module": "./dist/es/index.mjs",
|
||||
"types": "./dist/cjs/index.d.ts",
|
||||
"exports": {
|
||||
"import": {
|
||||
"types": "./dist/es/index.d.ts",
|
||||
"default": "./dist/es/index.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/cjs/index.d.cts",
|
||||
"default": "./dist/cjs/index.cjs"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "bunchee -w --tsconfig tsconfig.build.json",
|
||||
"build": "bunchee --tsconfig tsconfig.build.json",
|
||||
"lint": "eslint . --ext ts,tsx"
|
||||
},
|
||||
"dependencies": {
|
||||
"deepmerge": "^4.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@3rapp/code-config": "workspace:*",
|
||||
"@types/node": "^20.12.10",
|
||||
"bunchee": "^5.1.5",
|
||||
"eslint": "^8.57.0",
|
||||
"typescript": "^5.4.5"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './tools';
|
||||
@@ -0,0 +1,31 @@
|
||||
import { resolve } from 'path';
|
||||
|
||||
import deepmerge from 'deepmerge';
|
||||
|
||||
/**
|
||||
* 深度合并对象
|
||||
* @param x 初始值
|
||||
* @param y 新值
|
||||
* @param arrayMode 对于数组采取的策略,`replace`为直接替换,`merge`为合并数组
|
||||
*/
|
||||
export const deepMerge = <T1, T2>(
|
||||
x: Partial<T1>,
|
||||
y: Partial<T2>,
|
||||
arrayMode: 'replace' | 'merge' = 'merge',
|
||||
) => {
|
||||
const options: deepmerge.Options = {};
|
||||
if (arrayMode === 'replace') {
|
||||
options.arrayMerge = (_d, s, _o) => s;
|
||||
} else if (arrayMode === 'merge') {
|
||||
options.arrayMerge = (_d, s, _o) => Array.from(new Set([..._d, ...s]));
|
||||
}
|
||||
return deepmerge(x, y, options) as T2 extends T1 ? T1 : T1 & T2;
|
||||
};
|
||||
|
||||
export const pathResolve = (dir: string) => {
|
||||
const { stack } = new Error();
|
||||
const stackLines = stack.split('\n');
|
||||
const callerLine = stackLines[2].trim();
|
||||
const callerFilePath = callerLine.match(/\(([^:)]+):/)[1];
|
||||
return resolve(callerFilePath, '../', dir);
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"exclude": ["node_modules", "test", "dist", "**/*spec.ts", "**.js"]
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"extends": "@3rapp/code-config/typescript/nodejs.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"outDir": "./dist",
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["src", "test", "typings/**/*.d.ts", "**.js"]
|
||||
}
|
||||
Reference in New Issue
Block a user