Skip to content

Commit

Permalink
feat: 添加lerna模板
Browse files Browse the repository at this point in the history
  • Loading branch information
xuasir committed Mar 6, 2021
1 parent 1948c73 commit b46225f
Show file tree
Hide file tree
Showing 14 changed files with 279 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/create-lib/src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { join } from 'path'
import { existsSync, mkdirSync, readdirSync, writeFileSync } from 'fs'

const BuiltInTemp = ['ts-lib']
const BuiltInTemp = ['ts-lib', 'ts-lib-lerna']
const FileMap: Record<string, string> = {
_eslintignore: '.eslintignore',
'_eslintrc.js': '.eslintrc.js',
Expand Down
2 changes: 2 additions & 0 deletions packages/create-lib/src/template/ts-lib-lerna/_eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
3 changes: 3 additions & 0 deletions packages/create-lib/src/template/ts-lib-lerna/_eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: [require.resolve('@xus/eslint-config')]
}
104 changes: 104 additions & 0 deletions packages/create-lib/src/template/ts-lib-lerna/_gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
5 changes: 5 additions & 0 deletions packages/create-lib/src/template/ts-lib-lerna/_prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const prettier = require('@xus/eslint-config/prettier')

module.exports = {
...prettier
}
13 changes: 13 additions & 0 deletions packages/create-lib/src/template/ts-lib-lerna/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const path = require('path')

module.exports = {
preset: 'ts-jest',
rootDir: __dirname,
collectCoverage: true,
collectCoverageFrom: ['packages/**/src/**/**.ts'],
coverageDirectory: path.resolve(__dirname, 'coverage'),
coverageReporters: ['html', 'text'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
watchPathIgnorePatterns: ['node_modules'],
testMatch: ['packages/**/__test__/**/*spec.[jt]s?(x)']
}
6 changes: 6 additions & 0 deletions packages/create-lib/src/template/ts-lib-lerna/lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"packages": ["packages/*"],
"version": "independent",
"npmClient": "yarn",
"useWorkspaces": true
}
35 changes: 35 additions & 0 deletions packages/create-lib/src/template/ts-lib-lerna/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"private": true,
"workspaces": [
"packages/*"
],
"scripts": {
"build": "xus lib",
"lint-fix": "xus lint",
"test": "jest",
"changelog": "xus changelog",
"release": "xus release"
},
"license": "MIT",
"gitHooks": {
"pre-commit": "lint-staged",
"commit-msg": "xus commit-lint"
},
"lint-staged": {
"*.{ts}": [
"lint-fix",
"prettier --parser=typescript --write"
]
},
"devDependencies": {
"@types/jest": "^26.0.20",
"@types/node": "^14.14.22",
"@xus/cli": "^0.1.3",
"@xus/eslint-config": "^0.1.2",
"jest": "^26.6.3",
"lerna": "^3.22.1",
"lint-staged": "^10.2.11",
"ts-jest": "^26.4.4",
"typescript": "^4.1.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { helloWord } from '../src'

describe('test index ', () => {
test('test helloWord ', () => {
expect(helloWord()).toBe('hello-word')
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@scope/core",
"version": "1.0.0",
"description": "ts lib",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"types": "dist/index.d.ts",
"keywords": [
"ts",
"lib"
],
"author": "who am i",
"license": "MIT"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const helloWord = () => 'hello-word'
12 changes: 12 additions & 0 deletions packages/create-lib/src/template/ts-lib-lerna/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"skipLibCheck": true,
"esModuleInterop": true,
"moduleResolution": "node",
"lib": ["esnext", "dom"]
},
"exclude": ["**/__test__/**/*"]
}
47 changes: 47 additions & 0 deletions packages/create-lib/src/template/ts-lib-lerna/xus.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { defineConfig } from '@xus/cli'

export default defineConfig({
libBuild: {
targets: ['esm', 'cjs', 'browser'],
rollTypes: true
},
lint: {
eslint: {
include: 'packages/**/src/**/*',
ext: ['.ts']
},
stylelint: false
},
release: {
beforeRelease: [
{
bin: 'npm',
args: ['run', 'test'],
message: {
start: 'Test start',
succeed: 'Test succeed',
failed: 'Test failed'
}
},
{
bin: 'npm',
args: ['run', 'lint-fix'],
message: {
start: 'Lint start',
succeed: 'Lint succeed',
failed: 'Lint failed'
}
},
{
bin: 'npm',
args: ['run', 'build'],
message: {
start: 'Build start',
succeed: 'Build succeed',
failed: 'Build failed'
}
}
],
branch: 'main'
}
})
30 changes: 29 additions & 1 deletion packages/create-lib/src/template/ts-lib/xus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,35 @@ export default defineConfig({
stylelint: false
},
release: {
beforeRelease: [],
beforeRelease: [
{
bin: 'npm',
args: ['run', 'test'],
message: {
start: 'Test start',
succeed: 'Test succeed',
failed: 'Test failed'
}
},
{
bin: 'npm',
args: ['run', 'lint-fix'],
message: {
start: 'Lint start',
succeed: 'Lint succeed',
failed: 'Lint failed'
}
},
{
bin: 'npm',
args: ['run', 'build'],
message: {
start: 'Build start',
succeed: 'Build succeed',
failed: 'Build failed'
}
}
],
branch: 'main'
}
})

0 comments on commit b46225f

Please sign in to comment.