Skip to content

Instantly share code, notes, and snippets.

@rjoydip-zz
Last active May 25, 2020 01:31
Show Gist options
  • Select an option

  • Save rjoydip-zz/bf578fcc07689c0d861453d2bcd56c01 to your computer and use it in GitHub Desktop.

Select an option

Save rjoydip-zz/bf578fcc07689c0d861453d2bcd56c01 to your computer and use it in GitHub Desktop.
How to config vuepress to your project

Generate documentation

How to config vuepress to your project.

Instruction

  1. create .vuepress folder.
  2. Create config.js file
  3. Add below snippet in config.js.
const readPkgUp = require('read-pkg-up');

const pkgjson = (readPkgUp.sync()).pkg;

module.exports = {
	title: pkgjson.title,
	description: pkgjson.description,
	base: '/PROJECT_URL/',
	themeConfig: {
		search: true,
		navbar: true,
		nav: [{
				text: 'Home',
				link: '/'
			},
			{
				text: 'Github',
				link: 'GITHUB_REPO_LINK'
			},
		],
		sidebar: [
			['/', 'Tabe of contents']
		], // Assumes GitHub. Can also be a full GitLab url.
		repo: '<REPO_URL>',
		// Customising the header label
		// Defaults to "GitHub"/"GitLab"/"Bitbucket" depending on `themeConfig.repo`
		repoLabel: 'Contribute!',
		// if your docs are in a different repo from your main project:
		docsRepo: '<DOCS_REPO_URL>',
		// if your docs are not at the root of the repo:
		docsDir: 'docs',
		// if your docs are in a specific branch (defaults to 'master'):
		docsBranch: '<DOCS_BRACH>',
	}
};
  1. Create docs folder. (optional)
  2. Create doc-gen.js and add below snippet.
const path = require('path')
const shell = require('shelljs');

const join = path.join;
const src = __dirname;
const dist = join(__dirname, 'docs');

if (!shell.which('git')) {
	shell.echo('Sorry, this script requires git');
	shell.exit(1);
}

shell.rm('-rf', 'docs');
shell.mkdir('-p', join(src, 'docs'));
shell.cp('-R', join(src, '.vuepress'), join(dist, '.vuepress'));
shell.cp('-R', join(src, 'README.md'), join(dist, 'README.md'));
// copy folder if needed
shell.echo('Docs re-created');

if (process.argv[2] === 'prod') {
	shell.exec('npm run docs:build', {
		async: true
	});
} else {
	shell.exec('npm run docs:dev', {
		async: true
	});
}
  1. Create a deploy.sh file in root.
#! /usr/bin/env sh

# abort on errors
set -e

# generate docs
npm run docs:gen prod

# build
npm run docs:build

# Copy README.md to dist

cp README.md docs/.vuepress/dist

# navigate into the build output directory
cd docs/.vuepress/dist

# if you are deploying to a custom domain
# echo 'www.example.com' > CNAME

git init
git add -A
git commit -m 'deploy'

git push -f <PROJECT_GITHUB_URL> master:gh-pages

cd -
  1. Add scripts in package.json.
"start": "nodemon node doc-gen.js",
"docs:dev": "vuepress dev docs",
"docs:build": "vuepress build docs",
"deploy": "deploy.sh"
  1. Add below devdependences.
"nodemon": "^1.18.3",
"read-pkg-up": "^4.0.0",
"shelljs": "^0.8.2",
"vuepress": "^0.14.1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment