JustWe
JustWe

Reputation: 4484

Is possible build nodejs to static using Github pages online?

I am having two repositories:

  1. A Vuepress project which contains Nodejs source code & markdown files.
  2. The static Github-pages which build from Vuepress.

So if I create a new markdown post, I need to run a shell to build the static files and upload it to the second Github-pages repository.

I want to know is possible to do this online like:

  1. Create a markdown file in Github web page.
  2. Rebuild the project online(using a shell or script?).
  3. Update the Github-pages with generated static HTML/CSS files.

Upvotes: 1

Views: 1528

Answers (1)

Nil Vila
Nil Vila

Reputation: 59

I use this .js code:

#!/usr/bin/env node
const shell = require("shelljs");
const ghpages = require("gh-pages");

// Variables
const distDirectory = "docs/.vuepress/dist";
const commitMessage = "Site update";

// Exit if there is any error
shell.set("-e");

// Build Vuepress
shell.exec("vuepress build docs");

// Publish to GitHub Pages
ghpages.publish(distDirectory, {
  message: commitMessage
}, function(err) {
  if (err) {
    console.log(err);
    shell.exit(1);
  }
});

// Message when succesfully completed
console.log("\nDocumentation has been successfully updated\n");

Keep in mind shelljs and gh-pages must be installed.

What this does:

  • Build Vuepress
  • Publishes dist from master to gh-pages. The dist folder can be ignored by .gitignore.

Now to use it, run this command on Terminal:

./path/to/file.js

I'm sure this could be done with shell, but this works perfectly for me. Theorically, with only one command, you could lint JS and CSS, build Vuepress, update version, push to gh-pages, push to master and publish to npm.

Upvotes: 0

Related Questions