Skip to content

Commit

Permalink
chore: basic functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
wangfupeng1988 committed Feb 17, 2022
1 parent a57aeea commit 89b6836
Show file tree
Hide file tree
Showing 39 changed files with 10,596 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["@babel/preset-env"],
"plugins": []
}
59 changes: 59 additions & 0 deletions .cz-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module.exports = {
types: [
{
value: 'WIP',
name: '💡 WIP: Work in progress',
},
{
value: 'feat',
name: '🚀 feat: A new feature',
},
{
value: 'fix',
name: '🔧 fix: A bug fix',
},
{
value: 'refactor',
name: '🔨 refactor: A code change that neither fixes a bug nor adds a feature',
},
{
value: 'release',
name: '🛳 release: Bump to a new Semantic version',
},
{
value: 'docs',
name: '📚 docs: Documentation only changes',
},
{
value: 'test',
name: '🔍 test: Add missing tests or correcting existing tests',
},
{
value: 'perf',
name: '⚡️ perf: Changes that improve performance',
},
{
value: 'chore',
name:
"🚬 chore: Changes that don't modify src or test files. Such as updating build tasks, package manager",
},
{
value: 'workflow',
name:
'📦 workflow: Changes that only affect the workflow. Such as updating build systems or CI etc.',
},
{
value: 'style',
name:
'💅 style: Code Style, Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)',
},
{
value: 'revert',
name: '⏱ revert: Revert to a commit',
},
],
// Specify the scopes for your particular project
scopes: [],
allowCustomScopes: true,
allowBreakingChanges: ['feat', 'fix'],
}
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# editorconfig.org
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.txt]
insert_final_newline = false
trim_trailing_whitespace = false
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/*
dist/
lib/
*.html
31 changes: 31 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
env: {
browser: true,
es6: true,
mocha: true,
jest: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
plugins: ['@typescript-eslint', 'prettier'],
rules: {
'no-unused-vars': 0,
'prettier/prettier': [
'error',
{ singleQuote: true, semi: false, parser: 'flow' },
],
},
}
31 changes: 31 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: test and build

on:
push:
branches:
- 'main'
- 'master'
- 'dev'
- 'feature-*'
- 'fix-*'
- 'hotfix-*'
- 'refactor-*'
paths:
- '.github/workflows/*'
- 'src/**'
- 'example/**'
- 'test/**'
- 'build/**'

jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/
- run: npm i
- run: npm run test
- run: npm run build
22 changes: 22 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: publish npm Package

on:
push:
tags:
- "v*.*.*"

jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/
- run: npm i
- run: npm run test
- run: npm run build
- run: npm publish --access=public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@ dist

# TernJS port file
.tern-port

ISSUE.md
7 changes: 7 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.github/
.vscode/
build/
node_modules/
test/
yarn.lock
package-lock.json
25 changes: 25 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
// 箭头函数只有一个参数的时候可以忽略括号
arrowParens: 'avoid',
// 括号内部不要出现空格
bracketSpacing: true,
// 行结束符使用 Unix 格式
endOfLine: 'lf',
// true: Put > on the last line instead of at a new line
jsxBracketSameLine: false,
// 行宽
printWidth: 100,
// 换行方式
proseWrap: 'preserve',
// 分号
semi: false,
// 使用单引号
singleQuote: true,
// 缩进
tabWidth: 2,
// 使用 tab 缩进
useTabs: false,
// 后置逗号,多行对象、数组在最后一行增加逗号
trailingComma: 'es5',
parser: 'typescript',
}
19 changes: 19 additions & 0 deletions .release-it.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
git: {
tagName: "v${version}",
commitMessage: "release: v${version}",
requireCleanWorkingDir: false,
requireBranch: "main",
},
hooks: {
"before:init": ["git pull origin main", "npm run test"],
},
npm: {
publish: false,
},
prompt: {
ghRelease: false,
glRelease: false,
publish: false,
},
}
23 changes: 23 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"editor.formatOnSave": true,
"cSpell.words": [
"codesandbox",
"commitlint",
"Elems",
"hoverbar",
"prettierrc",
"snabbdom",
"vnode",
"wangeditor",
"wangfupeng"
],
"typescript.tsdk": "node_modules/typescript/lib",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": [
"javascript"
],
"editor.detectIndentation": false,
"editor.tabSize": 2
}
1 change: 1 addition & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry "https://registry.npm.taobao.org"
41 changes: 41 additions & 0 deletions DEV.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Dev doc

## 主要目录

- `src` 源代码
- `test` 单元测试
- `example` 本地测试 demo ,不用于 build
- `build` 打包配置

## dev 本地运行

`yarn dev` 启动本地服务,**使用 example 目录**

`yarn test` 单元测试,使用 test 目录。

## build 构建

`yarn build` 构建代码,**使用 src 目录**

## release 发布

第一,升级 package.json 版本

第二,提交 git tag 可触发 github actions 并发布 npm

```sh
git tag -a v1.0.1 -m "v1.0.1" # 和 package.json 版本同步即可
git push origin --tags
```

## 注意事项

package.json
- 定义 `"main": "dist/index.js"`
- 定义 `"module": "dist/index.js"`
- 定义 `"types": "dist/src/index.d.ts"`
- `@wangeditor/core` `@wangeditor/editor` 不要安装在 `dependencies` ,否则用户安装时也会安装它们

webpack 配置
- 定义 `library`
- 定义 `externals` ,构建时忽略 `@wangeditor/core` `@wangeditor/editor` ,否则体积会很大
3 changes: 3 additions & 0 deletions README-en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# wangEditor-plugin-mention

WIP...
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# wangEditor-plugin-mention
wangEditor mention plugin

开发中...
11 changes: 11 additions & 0 deletions build/paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const path = require('path')

const srcPath = path.join(__dirname, '..', 'src')
const examplePath = path.join(__dirname, '..', 'example')
const distPath = path.join(__dirname, '..', 'dist')

module.exports = {
srcPath,
examplePath,
distPath,
}
41 changes: 41 additions & 0 deletions build/webpack.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const { srcPath } = require('./paths.js')

module.exports = {
module: {
rules: [
{
test: /\.js$/,
use: ['babel-loader'],
include: srcPath,
exclude: /node_modules/,
},
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader', 'postcss-loader'], // loader 的执行顺序是:从后往前
},
{
test: /\.less$/,
use: ['style-loader', 'css-loader', 'postcss-loader', 'less-loader'], // 增加 'less-loader' ,注意顺序
},
{
test: /\.(woff2?|ttf|eot|otf)(\?.*)?$/,
use: [
{
loader: 'url-loader',
options: {
limit: 500 * 1024, // <=500kb 则使用 base64 (即,希望字体文件一直使用 base64 ,而不单独打包)
},
},
],
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
}
28 changes: 28 additions & 0 deletions build/webpack.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const path = require('path')
const webpack = require('webpack')
const { merge } = require('webpack-merge')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpackCommonConf = require('./webpack.common.js')
const { distPath, examplePath } = require('./paths.js')

module.exports = merge(webpackCommonConf, {
mode: 'development',
entry: path.join(examplePath, 'index'),
devServer: {
port: 3000,
progress: true, // 显示打包的进度条
contentBase: distPath, // 根目录
// open: true, // 自动打开浏览器
compress: true, // 启动 gzip 压缩
},
devtool: 'eval-cheap-source-map',
plugins: [
new webpack.DefinePlugin({
ENV: JSON.stringify('development'),
}),
new HtmlWebpackPlugin({
template: path.join(examplePath, 'index.html'),
filename: 'index.html',
}),
],
})
Loading

0 comments on commit 89b6836

Please sign in to comment.