fix: auto replace version

This commit is contained in:
qingwei.li 2017-05-31 08:25:00 +08:00
parent ec887c1b5f
commit 22b50f07c3
No known key found for this signature in database
GPG Key ID: B6DDC2F7AE80B2F4
9 changed files with 35 additions and 7 deletions

11
build/build-cover.js Normal file
View File

@ -0,0 +1,11 @@
var fs = require('fs')
var read = fs.readFileSync
var write = fs.writeFileSync
var version = process.env.VERSION || require('../package.json').version
var file = __dirname + '/../docs/_coverpage.md'
var cover = read(file, 'utf8').toString()
console.log('Replace version number in cover page...')
cover = cover.replace(/<small>(\S+)?<\/small>/g, '<small>' + version + '</small>')
write(file, cover)

View File

@ -1,13 +1,16 @@
var rollup = require('rollup') var rollup = require('rollup')
var buble = require('rollup-plugin-buble') var buble = require('rollup-plugin-buble')
var async = require('rollup-plugin-async') var async = require('rollup-plugin-async')
var isProd = process.argv[process.argv.length - 1] !== '--dev' var replace = require('rollup-plugin-replace')
rollup rollup
.rollup({ .rollup({
entry: 'packages/docsify-server-renderer/index.js', entry: 'packages/docsify-server-renderer/index.js',
plugins: [ plugins: [
async(), async(),
replace({
__VERSION__: process.env.VERSION || require('../package.json').version
}),
buble({ buble({
transforms: { transforms: {
generator: false generator: false

View File

@ -4,7 +4,9 @@ var commonjs = require('rollup-plugin-commonjs')
var nodeResolve = require('rollup-plugin-node-resolve') var nodeResolve = require('rollup-plugin-node-resolve')
var string = require('rollup-plugin-string') var string = require('rollup-plugin-string')
var uglify = require('rollup-plugin-uglify') var uglify = require('rollup-plugin-uglify')
var replace = require('rollup-plugin-replace')
var isProd = process.argv[process.argv.length - 1] !== '--dev' var isProd = process.argv[process.argv.length - 1] !== '--dev'
var version = process.env.VERSION || require('../package.json').version
var build = function (opts) { var build = function (opts) {
rollup rollup
@ -14,7 +16,10 @@ var build = function (opts) {
string({ include: '**/*.css' }), string({ include: '**/*.css' }),
buble(), buble(),
commonjs(), commonjs(),
nodeResolve() nodeResolve(),
replace({
__VERSION__: version
})
]) ])
}) })
.then(function (bundle) { .then(function (bundle) {

View File

@ -28,6 +28,7 @@
executeScript: true, executeScript: true,
loadNavbar: true, loadNavbar: true,
loadSidebar: true, loadSidebar: true,
coverpage: true,
name: 'docsify', name: 'docsify',
subMaxLevel: 2, subMaxLevel: 2,
mergeNavbar: true, mergeNavbar: true,
@ -37,7 +38,7 @@
function(hook, vm) { function(hook, vm) {
hook.beforeEach(function (html) { hook.beforeEach(function (html) {
var url = 'https://github.com/QingWei-Li/docsify/blob/master' + vm.router.getFile() var url = 'https://github.com/QingWei-Li/docsify/blob/master' + vm.router.getFile()
var editHtml = '[📝 EDIT DOCUMENT](' + url + ')\n' var editHtml = '[:memo: Edit Document](' + url + ')\n'
return editHtml return editHtml
+ html + html

View File

@ -1,6 +1,6 @@
![logo](_media/icon.svg) ![logo](_media/icon.svg)
# docsify <small>4.0</small> # docsify <small>4.1.7</small>
> A magical documentation site generator. > A magical documentation site generator.

View File

@ -53,8 +53,8 @@
plugins: [ plugins: [
function(hook, vm) { function(hook, vm) {
hook.beforeEach(function (html) { hook.beforeEach(function (html) {
var url = 'https://github.com/QingWei-Li/docsify/blob/master/docs' + vm.router.getFile() var url = 'https://github.com/QingWei-Li/docsify/blob/master/docs' + vm.route.file
var editHtml = '[📝 EDIT DOCUMENT](' + url + ')\n' var editHtml = '[:memo: Edit Document](' + url + ')\n'
return editHtml return editHtml
+ html + html

View File

@ -20,7 +20,7 @@
"themes" "themes"
], ],
"scripts": { "scripts": {
"build": "rm -rf lib themes && node build/build && mkdir lib/themes && mkdir themes && node build/build-css && npm run build:ssr", "build": "rm -rf lib themes && node build/build && mkdir lib/themes && mkdir themes && node build/build-css && npm run build:ssr && node build/build-cover",
"dev:build": "rm -rf lib themes && mkdir themes && node build/build --dev && node build/build-css --dev", "dev:build": "rm -rf lib themes && mkdir themes && node build/build --dev && node build/build-css --dev",
"dev": "node app & nodemon -w src -e js,css --exec 'npm run dev:build'", "dev": "node app & nodemon -w src -e js,css --exec 'npm run dev:build'",
"build:ssr": "node build/build-ssr", "build:ssr": "node build/build-ssr",
@ -47,6 +47,7 @@
"rollup-plugin-buble": "^0.15.0", "rollup-plugin-buble": "^0.15.0",
"rollup-plugin-commonjs": "^8.0.2", "rollup-plugin-commonjs": "^8.0.2",
"rollup-plugin-node-resolve": "^2.0.0", "rollup-plugin-node-resolve": "^2.0.0",
"rollup-plugin-replace": "^1.1.1",
"rollup-plugin-string": "^2.0.2", "rollup-plugin-string": "^2.0.2",
"rollup-plugin-uglify": "^1.0.1", "rollup-plugin-uglify": "^1.0.1",
"serve-static": "^1.12.1" "serve-static": "^1.12.1"

View File

@ -139,3 +139,5 @@ export default class Renderer {
} }
} }
} }
Renderer.version = '__VERSION__'

View File

@ -22,6 +22,11 @@ eventMixin(proto)
*/ */
initGlobalAPI() initGlobalAPI()
/**
* Version
*/
Docsify.version = '__VERSION__'
/** /**
* Run Docsify * Run Docsify
*/ */