This repository has been archived by the owner on Dec 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
deploy-to-github.js
50 lines (45 loc) · 1.8 KB
/
deploy-to-github.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var ghpages = require('gh-pages');
var Console = require('bc-console');
var webpack = require('webpack');
var path = require('path');
var fs = require('fs');
var remoteOriginUrl = require('remote-origin-url');
var gh = require('parse-github-url');
if (!fs.existsSync(path.resolve(__dirname,'.git'))){
Console.error("No repository found on this project");
Console.help("Follow this steps to create a new repository for your project: http://kbroman.org/github_tutorial/pages/init.html");
return;
}
const origin = remoteOriginUrl.sync();
if(!origin || origin==''){
Console.error("No remote origin has been found on this repository");
Console.help(`Check your remote by doing:
$ git remote get-url origin
Add your remote by doing:
$ git remote add origin <github_repository_url>
`);
return;
}
Console.info("The remote was found successfully, starting the deploy from here: "+origin);
const repository = gh(origin);
const compiler = webpack(require(path.resolve(__dirname, 'webpack.config.js')));
compiler.run((err, stats) => {
if (err || stats.hasErrors()) {
console.log(stats.toString({
colors: true
}));
Console.error("There was an error compiling, review above");
return;
}
Console.info("Your code compiled successfully, proceding to deploy...");
ghpages.publish('public', function(err) {
if(err){
console.error(err);
Console.error("There was an error publishing your website");
return;
}
//https://<github_user>.github.io/<repository-name>
Console.success(`Your website has been deployed successfully here: https://${repository["owner"]}.github.io/${repository["name"]}/`);
Console.info(`Changes on your deployed website take 10 min aprox to show, please be patient. Happy coding!`);
});
});