-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs): add versioning implementation (#2350)
* feat(docs): add versioning implementation * refactor(docs): remove rimraf, simplify package.json commands * feat(docs): add docs.archive to gh-pages script * refactor(docs): remove else, reduce nesting * feat(docs): docs versioning works with demo.serve * refactor(docs): deploy and serve from gh-pages, add version check * refactor(docs): clone/pull via js * chore(build): simplifed archieve script * chore(build): more tests
- Loading branch information
1 parent
6589ee9
commit 91cee71
Showing
15 changed files
with
214 additions
and
34 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 |
---|---|---|
|
@@ -26,6 +26,7 @@ npm-debug.log | |
/demo/dist | ||
/demo/temp | ||
/logs | ||
/gh-pages | ||
|
||
#System Files | ||
.DS_Store | ||
|
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
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
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
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
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
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
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 @@ | ||
{"version":"1.8.1"} |
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 @@ | ||
[{"version":"Current","url":"ngx-bootstrap","unprefixedUrl":""},{"version":"1.8.5","url":"ngx-bootstrap/old/1.8.5","unprefixedUrl":"old/1.8.5"}] |
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
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
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
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,110 @@ | ||
const fs = require('fs-extra'); | ||
const path = require('path'); | ||
|
||
const ghPagesDir = 'gh-pages/'; | ||
const oldVersionDir = 'gh-pages/old/'; | ||
const versionsFilePath = 'assets/json/versions.json'; | ||
const currentVersionFilePath = 'assets/json/current-version.json'; | ||
|
||
const demoSrcDir = 'demo/src'; | ||
const demoDistDir = 'demo/dist'; | ||
const hostname = 'ngx-bootstrap'; | ||
|
||
let prevVersion; | ||
const newVersion = require('../package.json').version; | ||
|
||
if (!fs.existsSync(ghPagesDir)) { | ||
throw new Error('gh-pages dir wasn\'t found. Run `npm run docs.fetch`'); | ||
} | ||
|
||
if (!fs.existsSync(demoDistDir)) { | ||
throw new Error('demo/dist dir wasn\'t found. Run `npm run demo.build`'); | ||
} | ||
|
||
try { | ||
prevVersion = require(path.join('../', ghPagesDir, currentVersionFilePath)).version; | ||
} catch (e) { | ||
prevVersion = require(path.join('../', demoSrcDir, currentVersionFilePath)).version; | ||
} | ||
|
||
console.log('Previous version:', prevVersion); | ||
console.log('New version:', newVersion); | ||
const isVersionChanged = prevVersion !== newVersion; | ||
|
||
|
||
fs.readdir('gh-pages') | ||
// filter files to operate on | ||
.then(filterFileToMove) | ||
// for local development, if version not changed, clean gh-pages folder | ||
.then(files => { | ||
if (isVersionChanged) { | ||
return files; | ||
} | ||
console.log('Version hasn\'t changed. Current gh-pages version will be replaced with the one from demo/dist'); | ||
return Promise.all(files.map(file => fs.remove(path.join(ghPagesDir, file)))) | ||
.then(() => files) | ||
}) | ||
// move old files to corresponding folder, skip for local dev | ||
.then(files => { | ||
if (!isVersionChanged) { | ||
return files; | ||
} | ||
|
||
fs.ensureDirSync(path.join(oldVersionDir, prevVersion)); | ||
|
||
return Promise.all(files | ||
.map(file => ({ | ||
from: path.join(ghPagesDir, file), | ||
to: path.join(oldVersionDir, prevVersion, file) | ||
})) | ||
.map((move) => fs.rename(move.from, move.to))); | ||
}) | ||
// copy demo dist to gh-pages folder | ||
.then(() => fs.copy(demoDistDir, ghPagesDir)) | ||
// generate new version json files | ||
.then(() => { | ||
if (isVersionChanged) { | ||
return generateJson(); | ||
} | ||
}) | ||
.catch(console.error.bind(console)); | ||
|
||
function filterFileToMove(files) { | ||
return files.filter((file) => file !== 'old' && file !== '.git'); | ||
} | ||
|
||
function generateJson() { | ||
return fs.readdir(oldVersionDir) | ||
.then(files => { | ||
let savedVersions = files.map(file => ({ | ||
version: file, | ||
url: hostname + '/old/' + file, | ||
unprefixedUrl: 'old/' + file | ||
})); | ||
|
||
savedVersions.unshift({version: 'Current', url: hostname, unprefixedUrl: ''}); | ||
|
||
return savedVersions; | ||
}) | ||
.then(versions => { | ||
const content = JSON.stringify(versions); | ||
|
||
return Promise | ||
.all(versions.map((ver) => { | ||
if (ver.version === 'Current') { | ||
return Promise.resolve(); | ||
} | ||
|
||
const _path = path.join(oldVersionDir, ver.version, versionsFilePath); | ||
fs.ensureFileSync(_path); | ||
return writeFile(_path, content); | ||
})) | ||
.then(() => writeFile(path.join(ghPagesDir, versionsFilePath), content)) | ||
.then(() => writeFile(path.join(ghPagesDir, currentVersionFilePath), JSON.stringify({version: newVersion}))) | ||
.then(() => writeFile(path.join(demoSrcDir, currentVersionFilePath), JSON.stringify({version: newVersion}))); | ||
}); | ||
} | ||
|
||
function writeFile(path, content) { | ||
return fs.writeFile(path, content, 'utf8'); | ||
} |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
module.exports = { | ||
"port": 4200, | ||
"server": { | ||
"baseDir": "./demo/dist", | ||
"baseDir": "./gh-pages", | ||
middleware : { 1 : require('compression')()} | ||
} | ||
}; |
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,17 @@ | ||
const fs = require('fs-extra'); | ||
const exec = require('child_process').exec; | ||
|
||
if (!fs.existsSync('gh-pages')) { | ||
console.log('Cloning the latest version of gh-pages'); | ||
runCmd("git clone -b gh-pages --single-branch --depth 1 git@github.com:valor-software/ngx-bootstrap.git gh-pages"); | ||
return; | ||
} | ||
console.log('Pulling the latest version of gh-pages'); | ||
runCmd("cd gh-pages && git pull && cd ../"); | ||
|
||
function runCmd(cmd) { | ||
exec(cmd, function (err) { | ||
if (err) console.log('exec err: ' + err); | ||
console.log('Done'); | ||
}); | ||
} |