Skip to content

Commit

Permalink
fix: auto replace version
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed May 31, 2017
1 parent ec887c1 commit 22b50f0
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 7 deletions.
11 changes: 11 additions & 0 deletions build/build-cover.js
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 4 additions & 1 deletion build/build-ssr.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
var rollup = require('rollup')
var buble = require('rollup-plugin-buble')
var async = require('rollup-plugin-async')
var isProd = process.argv[process.argv.length - 1] !== '--dev'
var replace = require('rollup-plugin-replace')

rollup
.rollup({
entry: 'packages/docsify-server-renderer/index.js',
plugins: [
async(),
replace({
__VERSION__: process.env.VERSION || require('../package.json').version
}),
buble({
transforms: {
generator: false
Expand Down
7 changes: 6 additions & 1 deletion build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ var commonjs = require('rollup-plugin-commonjs')
var nodeResolve = require('rollup-plugin-node-resolve')
var string = require('rollup-plugin-string')
var uglify = require('rollup-plugin-uglify')
var replace = require('rollup-plugin-replace')
var isProd = process.argv[process.argv.length - 1] !== '--dev'
var version = process.env.VERSION || require('../package.json').version

var build = function (opts) {
rollup
Expand All @@ -14,7 +16,10 @@ var build = function (opts) {
string({ include: '**/*.css' }),
buble(),
commonjs(),
nodeResolve()
nodeResolve(),
replace({
__VERSION__: version
})
])
})
.then(function (bundle) {
Expand Down
3 changes: 2 additions & 1 deletion dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
executeScript: true,
loadNavbar: true,
loadSidebar: true,
coverpage: true,
name: 'docsify',
subMaxLevel: 2,
mergeNavbar: true,
Expand All @@ -37,7 +38,7 @@
function(hook, vm) {
hook.beforeEach(function (html) {
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
+ html
Expand Down
2 changes: 1 addition & 1 deletion docs/_coverpage.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![logo](_media/icon.svg)

# docsify <small>4.0</small>
# docsify <small>4.1.7</small>

> A magical documentation site generator.
Expand Down
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
plugins: [
function(hook, vm) {
hook.beforeEach(function (html) {
var url = 'https://github.com/QingWei-Li/docsify/blob/master/docs' + vm.router.getFile()
var editHtml = '[📝 EDIT DOCUMENT](' + url + ')\n'
var url = 'https://github.com/QingWei-Li/docsify/blob/master/docs' + vm.route.file
var editHtml = '[:memo: Edit Document](' + url + ')\n'

return editHtml
+ html
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"themes"
],
"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": "node app & nodemon -w src -e js,css --exec 'npm run dev:build'",
"build:ssr": "node build/build-ssr",
Expand All @@ -47,6 +47,7 @@
"rollup-plugin-buble": "^0.15.0",
"rollup-plugin-commonjs": "^8.0.2",
"rollup-plugin-node-resolve": "^2.0.0",
"rollup-plugin-replace": "^1.1.1",
"rollup-plugin-string": "^2.0.2",
"rollup-plugin-uglify": "^1.0.1",
"serve-static": "^1.12.1"
Expand Down
2 changes: 2 additions & 0 deletions packages/docsify-server-renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,5 @@ export default class Renderer {
}
}
}

Renderer.version = '__VERSION__'
5 changes: 5 additions & 0 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ eventMixin(proto)
*/
initGlobalAPI()

/**
* Version
*/
Docsify.version = '__VERSION__'

/**
* Run Docsify
*/
Expand Down

0 comments on commit 22b50f0

Please sign in to comment.