Commit 7f077c9b authored by Allen Bai's avatar Allen Bai

feat: first commit

parent 9d00aad8
{
"presets": [
"@babel/preset-typescript",
[
"@babel/preset-env",
{
"modules": false
}
]
],
"plugins": ["@babel/plugin-transform-runtime", "@babel/plugin-proposal-class-properties"]
}
dist
code
!.eslintrc.js
\ No newline at end of file
/** @format */
module.exports = {
parser: '@typescript-eslint/parser', //定义ESLint的解析器
extends: ['prettier/@typescript-eslint', 'plugin:prettier/recommended'], //定义文件继承的子规范
env: {
//指定代码的运行环境
browser: true,
node: true
},
plugins: ['prettier'],
// add your custom rules here
rules: {
'prettier/prettier': 'error',
// allow async-await
'generator-star-spacing': 0,
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'prod' ? 2 : 0
}
}
node_modules
dist
\ No newline at end of file
{
"printWidth": 120,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"jsxBracketSameLine": true,
"arrowParens": "avoid",
"insertPragma": true,
"tabWidth": 4,
"useTabs": false,
"bracketSpacing": true
}
\ No newline at end of file
<!-- @format -->
# 推啊埋点 SDK
[推啊前端埋点方案](https://www.yuque.com/docs/share/212c6065-f556-492b-a27d-748d509e3583?#)
## 开发
如果已经打包过就直接运行如下命令,开启监听,文件改动会同步打包到 dist 下
```
yarn watch
# Or
npm run watch
```
`src/index.ts` 是入口文件,方法挂载
更改文件之后,在本地调试的时候运行如下命令,把包链接到本地
```
yarn link
# Or
npm link
```
出现如下提示
> You can now run `yarn link "@tuia/log-sdk"` in the projects where you want to use this package and it will be used instead.
然后在需要调试的项目中(其他使用这个包的项目)`yarn link "@tuia/log-sdk"` 把本地的包链接到改项目进行调试
## 打包
打包生产环境sdk (压缩后)
```
yarn build
# Or
npm run build
```
打包开发环境 (压缩前)方便调试
```
yarn build:debug
# Or
npm run build:debug
```
## 发布前准备工作
1. 首先确保已经登录 npm 账号并且拥有发布权限
2. 生成版本号、打tag和生成更改日志,其他用法详情见[standard-version](https://github.com/conventional-changelog/standard-version)
1) 指定版本号,如0.1.0-beta
```
yarn release -- --release-as <版本号>
# Or
npm run release -- --release-as <版本号>
```
2) 不指定版本号,直接自动累加
```
yarn release
# Or
npm run release
```
成功之后把 tag 推到远程
```
git push --follow-tags origin master
```
## 发布到 npm (谨慎)
```
yarn deploy
or
npm run deploy
```
## 注意事项
如果直接使用 `npm publish --access public` 命令发布的话,发布之前要保证根目录下的 dist 包是最新的,版本号是最新的(之前没有已经发布的版本),所有代码都提交到远程 master
在发布npm版本之后,要执行 `npm run pub`同步最新的版本到 cdn 以便用来script标签引入来使用
`yarn release``yarn deploy` 是这一系列的组合命令
## TODO
- [x] elint+prettier+commit 规范代码开发&提交
- [x] standard-version 生成版本号、打tag和生成更改日志
- [x] 支持模块化方式导入和script标签方式使用
## SDK 使用
[推啊埋点SDK使用文档](https://www.yuque.com/docs/share/444fe742-1624-4298-937d-af8f9a14043d)
\ No newline at end of file
/** @format */
/**
* 打包发布到npm的时候同步一份该版本到cdn上以便script方式引入 版本得放路径管理不能放文件后缀
*/
const chalk = require('chalk')
const path = require('path')
const TuiaAutoUpload = require('tuia-auto-upload')
const pkg = require('./package.json')
const publicPath = `//yun.tuisnake.com/tuia/${pkg.name}/${pkg.version}/dist/`
const deploy = async () => {
console.log(chalk.cyan('dist文件 开始上传>>>>>>>>>>\n'))
const uploader = await new TuiaAutoUpload({
dir: path.join(__dirname, `./dist/`),
originDir: `/tuia/${pkg.name}/${pkg.version}/dist/`
})
await uploader.start()
console.log(chalk.cyan(`入口文件cdn地址为:\n ${publicPath}logHub.main.js`))
}
deploy()
/** @format */
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [
2,
'always',
['build', 'ci', 'chore', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'style', 'test']
]
}
}
{
"name": "@tuia/ipc",
"version": "0.0.1",
"description": "推啊IPC备案号获取",
"main": "libs/tuiaIPC.js",
"module": "libs/tuiaIPC.module.js",
"author": "ltt",
"license": "MIT",
"scripts": {
"watch": "rollup -c -w",
"build": "npm run clean && cross-env NODE_ENV=prod && rollup -c",
"build:debug": "npm run clean && cross-env NODE_ENV=dev rollup -c",
"clean": "rm -rf ./dist",
"pub": "node ./build.js",
"deploy": "npm run build && npm publish --access public && npm run pub",
"lint": "prettier --write src",
"release": "standard-version"
},
"typescript": ">=4.0",
"files": [
"dist"
],
"devDependencies": {
"@babel/core": "^7.12.9",
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/plugin-transform-runtime": "^7.12.1",
"@babel/preset-env": "^7.12.1",
"@babel/preset-typescript": "^7.12.7",
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^4.9.0",
"@typescript-eslint/parser": "^4.9.0",
"babel-eslint": "^10.1.0",
"chalk": "^4.1.0",
"cross-env": "^7.0.2",
"eslint": "^7.15.0",
"eslint-config-prettier": "^7.0.0",
"eslint-plugin-prettier": "^3.2.0",
"husky": "^4.3.4",
"lint-staged": "^10.5.3",
"prettier": "^2.2.1",
"rollup": "^2.33.2",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.29.0",
"standard-version": "^9.0.0",
"tslib": "^2.0.3",
"tuia-auto-upload": "^2.0.19",
"typescript": "^4.1.2"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -e $HUSKY_GIT_PARAMS"
}
},
"lint-staged": {
"*.{.ts,.tsx}": [
"prettier --write",
"eslint --fix",
"git add"
]
}
}
/** @format */
import typescript from 'rollup-plugin-typescript2' // 处理typescript
import babel from 'rollup-plugin-babel'
import commonjs from 'rollup-plugin-commonjs'
import {nodeResolve} from '@rollup/plugin-node-resolve'
import {terser} from 'rollup-plugin-terser'
import {DEFAULT_EXTENSIONS} from '@babel/core'
const isDev = process.env.NODE_ENV === 'dev'
export default {
input: './src/index.ts', // 入口文件
output: [
{
file: `dist/logHub.main.js`, // 打包之后的文件名以及存放位置
format: 'umd', // 以什么模式打包,支持umd,cmd,esm...
name: 'logHub'
},
{
file: `dist/logHub.module.js`, // 打包之后的文件名以及存放位置
format: 'es', // 以什么模式打包,支持umd,cmd,esm...
name: 'logHub'
}
],
plugins: [
// https://github.com/rollup/rollup-plugin-babel/issues/318
// put TS plugin before babel plugin in your plugins array
typescript({
exclude: 'node_modules/**',
typescript: require('typescript')
}),
babel({
exclude: 'node_modules/**',
runtimeHelpers: true,
// babel 默认不支持 ts 需要手动添加
extensions: [...DEFAULT_EXTENSIONS, '.ts']
}),
nodeResolve({
mainField: ['jsnext:main', 'browser', 'module', 'main'],
browser: true
}),
commonjs(),
!isDev && terser()
]
}
/** @format */
function request() {
return new Promise((resolve, reject) => {})
}
export function getIPCByDomain(domain: string) {}
export function getIPC() {}
export function mountIPCFooter(dom, domain: string, opts) {}
const __TUIA__IPC_HELPER__ = {
getIPCByDomain,
getIPC,
mountIPCFooter
}
export default __TUIA__IPC_HELPER__
{
"compilerOptions": {
"declaration": true // 生成*.d.ts
}
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment