forked from code-farmer-i/vue-markdown-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76aa349
commit a2ce07b
Showing
76 changed files
with
2,109 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"root": true, | ||
"extends": ["@vant"], | ||
"rules": { | ||
"linebreak-style": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# npm | ||
node_modules | ||
package-lock.json | ||
|
||
# dist file | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "es5" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": ["@vant/stylelint-config"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
presets: ['@vue/cli-plugin-babel/preset'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const fs = require('fs-extra'); | ||
const path = require('path'); | ||
const packageJson = require('../package.json'); | ||
|
||
const version = process.env.VERSION || packageJson.version; | ||
const tips = '// This file is auto generated by build/build-entry.js'; | ||
|
||
function buildEntry() { | ||
const content = `${tips} | ||
import MarkdownEditor from './markdown-editor.vue'; | ||
import markdownItInstance from '@/utils/markdown-it'; | ||
import '@/assets/css/font'; | ||
const version = '${version}'; | ||
const install = (Vue) => { | ||
Vue.component(MarkdownEditor.name, MarkdownEditor); | ||
}; | ||
if (typeof window !== 'undefined' && window.Vue) { | ||
install(window.Vue); | ||
} | ||
MarkdownEditor.version = version; | ||
MarkdownEditor.install = install; | ||
MarkdownEditor.markdownIt = markdownItInstance; | ||
export default MarkdownEditor; | ||
`; | ||
|
||
fs.writeFileSync(path.join(__dirname, '../src/index.js'), content); | ||
} | ||
|
||
buildEntry(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const runTasks = require('./utils/run-tasks'); | ||
const selectVersion = require('./utils/select-version'); | ||
const checkNpmPermission = require('./utils/check-npm-permission'); | ||
|
||
const packageJson = require('../package.json'); | ||
const currentVersion = packageJson.version; | ||
|
||
async function release() { | ||
const hasPublishPackagePermission = await checkNpmPermission( | ||
packageJson.name | ||
); | ||
|
||
const { version: releaseVersion, isBeta } = await selectVersion( | ||
currentVersion | ||
); | ||
|
||
// set version | ||
await runTasks([`npm version ${releaseVersion} --no-git-tag-version`]); | ||
|
||
try { | ||
// build | ||
await runTasks(['npm run build:entry', 'npm run build:pkg']); | ||
|
||
//commit | ||
await runTasks([ | ||
'git add .', | ||
`git tag v${releaseVersion}`, | ||
`git commit -m "chore: release ${releaseVersion}"`, | ||
]); | ||
|
||
// push | ||
await runTasks([ | ||
'git push', | ||
`git push origin refs/tags/v${releaseVersion}`, | ||
]); | ||
|
||
// publish | ||
if (isBeta) { | ||
runTasks(['npm publish --tag beta']); | ||
} else { | ||
runTasks(['npm publish']); | ||
} | ||
} catch (e) { | ||
// rollback version and delete local tag | ||
runTasks([ | ||
`npm version ${currentVersion} --no-git-tag-version`, | ||
`git tag -d v${releaseVersion}`, | ||
]); | ||
} | ||
} | ||
|
||
release(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const exec = require('./exec'); | ||
const signale = require('signale'); | ||
|
||
// 检查npm 是否登录 | ||
async function checkNpmLogin() { | ||
try { | ||
const npmUserName = await exec('npm whoami'); | ||
|
||
return npmUserName.replace(/[\r\n]/g, ''); | ||
} catch (e) { | ||
signale.error('请检查npm 登录状态'); | ||
} | ||
} | ||
|
||
// 检查是否有当前包的发布权限 | ||
async function checkPackagePermission(userName, packageName) { | ||
try { | ||
const packagePermissionInfo = JSON.parse( | ||
await exec(`npm access ls-collaborators ${packageName}`) | ||
); | ||
|
||
return ( | ||
Object.keys(packagePermissionInfo).includes(userName) && | ||
packagePermissionInfo[userName].includes('write') | ||
); | ||
} catch (e) { | ||
signale.error('确认包发布权限失败'); | ||
} | ||
} | ||
|
||
module.exports = async function checkNpmPermission(packageName) { | ||
const userName = await checkNpmLogin(); | ||
|
||
const hasPublishPackagePermission = await checkPackagePermission( | ||
userName, | ||
packageName | ||
); | ||
|
||
return hasPublishPackagePermission; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const shell = require('shelljs'); | ||
const signale = require('signale'); | ||
|
||
module.exports = function (shellScript, options = { silent: true }) { | ||
signale.start(shellScript); | ||
signale.pending(shellScript); | ||
|
||
return new Promise((resolve, reject) => { | ||
shell.exec(shellScript, options, function (code, stdout, stderr) { | ||
if (code === 0) { | ||
signale.success(shellScript); | ||
resolve(stdout); | ||
} else { | ||
signale.error(shellScript); | ||
reject(stderr); | ||
} | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const semver = require('semver'); | ||
|
||
module.exports.isBetaVersion = function (version) { | ||
const res = semver.prerelease(version); | ||
|
||
return !!res && res[0] === 'beta'; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const shell = require('shelljs'); | ||
const signale = require('signale'); | ||
const { Signale } = signale; | ||
|
||
module.exports = function runTasks(tasks) { | ||
tasks.forEach((task) => { | ||
signale.start(task); | ||
|
||
const interactive = new Signale({ interactive: true }); | ||
interactive.pending(task); | ||
const result = shell.exec(`${task}`); | ||
if (result.code !== 0) { | ||
interactive.error(task); | ||
} else { | ||
interactive.success(task); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const semver = require('semver'); | ||
const inquirer = require('inquirer'); | ||
const { isBetaVersion } = require('./index'); | ||
const getReleaseVersion = require('./get-release-version'); | ||
|
||
const customVersionOption = '自定义版本号'; | ||
|
||
module.exports = async function selectVersion(curVersion) { | ||
const releaseVersions = getReleaseVersion(curVersion); | ||
|
||
const question = [ | ||
{ | ||
type: 'list', | ||
message: `请选择要发布的版本号(当前版本:${curVersion}):`, | ||
name: 'version', | ||
choices: [...releaseVersions, customVersionOption], | ||
}, | ||
{ | ||
type: 'input', | ||
message: '请输入要发布的版本号:', | ||
name: 'customVersion', | ||
when: function (answers) { | ||
return answers.version === customVersionOption; | ||
}, | ||
validate(releaseVersion) { | ||
if (!semver.valid(releaseVersion)) { | ||
return '请按照Semantic Version规范定义版本号'; | ||
} | ||
|
||
if (semver.lt(releaseVersion, curVersion)) { | ||
return '发布的版本号应该是递增的'; | ||
} | ||
|
||
return true; | ||
}, | ||
}, | ||
{ | ||
type: 'confirm', | ||
name: 'confirm', | ||
message: function ({ version, customVersion }) { | ||
return `确认发布版本 ${customVersion || version} ?`; | ||
}, | ||
when: function (answers) { | ||
return answers.version || answers.customVersion; | ||
}, | ||
}, | ||
]; | ||
|
||
const answers = await inquirer.prompt(question); | ||
const selectedVersion = answers.customVersion || answers.version; | ||
|
||
if (answers.confirm && selectedVersion) { | ||
return { | ||
version: selectedVersion, | ||
isBeta: isBetaVersion(selectedVersion), | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const { VueLoaderPlugin } = require('vue-loader'); | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
resolve: { | ||
extensions: ['.js', '.vue', '.css'], | ||
alias: { | ||
'@': path.join(__dirname, '../src'), | ||
}, | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.vue$/, | ||
use: [ | ||
{ | ||
loader: 'vue-loader', | ||
options: { | ||
compilerOptions: { | ||
preserveWhitespace: false, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
test: /\.(js)$/, | ||
exclude: /node_modules/, | ||
use: { | ||
loader: 'babel-loader', | ||
// enable sub-packages to find babel config | ||
options: { | ||
rootMode: 'upward', | ||
}, | ||
}, | ||
}, | ||
{ | ||
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, | ||
loader: 'url-loader', | ||
options: { | ||
limit: 10000, | ||
name: 'fonts/[name].[hash:7].[ext]', | ||
}, | ||
}, | ||
], | ||
}, | ||
plugins: [new VueLoaderPlugin()], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const path = require('path'); | ||
const merge = require('webpack-merge'); | ||
const config = require('./webpack.base'); | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
|
||
module.exports = merge(config, { | ||
entry: { | ||
dev: './dev/main.js', | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css/, | ||
sideEffects: true, | ||
use: ['style-loader', 'css-loader', 'postcss-loader'], | ||
}, | ||
{ | ||
test: /\.scss/, | ||
sideEffects: true, | ||
use: ['style-loader', 'css-loader', 'postcss-loader', 'sass-loader'], | ||
}, | ||
], | ||
}, | ||
devServer: { | ||
open: true, | ||
progress: true, | ||
host: '0.0.0.0', | ||
stats: 'errors-only', | ||
disableHostCheck: true, | ||
}, | ||
output: { | ||
path: path.join(__dirname, '../dev/dist'), | ||
publicPath: '/', | ||
chunkFilename: 'async_[name].js', | ||
}, | ||
optimization: { | ||
splitChunks: { | ||
cacheGroups: { | ||
chunks: { | ||
chunks: 'all', | ||
minChunks: 2, | ||
minSize: 0, | ||
name: 'chunks', | ||
}, | ||
}, | ||
}, | ||
}, | ||
plugins: [ | ||
new HtmlWebpackPlugin({ | ||
template: path.join(__dirname, '../dev/index.html'), | ||
filename: 'index.html', | ||
}), | ||
], | ||
}); |
Oops, something went wrong.