├── .gitignore
├── example
├── style.css
└── index.html
├── package.json
├── bin
└── gh-pages-deploy
├── LICENSE
├── README.md
└── index.js
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 |
--------------------------------------------------------------------------------
/example/style.css:
--------------------------------------------------------------------------------
1 | html {
2 | font-family: monospace;
3 | color: #50F6C5;
4 | background: #414141;
5 | text-align: center;
6 | }
7 |
8 | article {
9 | margin: 200px auto;
10 | width: 30%;
11 | }
12 |
13 | a {
14 | color: #FFA500;
15 | text-decoration: none;
16 | }
17 |
18 | .term {
19 | background: #000;
20 | padding: 14px;
21 | width: 80%;
22 | margin: auto;
23 | }
24 |
25 | .term span {
26 | color: #FF7FF9;
27 | -webkit-touch-callout: none;
28 | -webkit-user-select: none;
29 | -khtml-user-select: none;
30 | -moz-user-select: none;
31 | -ms-user-select: none;
32 | user-select: none;
33 | }
--------------------------------------------------------------------------------
/example/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | gh-pages-deploy
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | you@mainframe$ npm install gh-pages-deploy
14 |
15 | <3 davejustice
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "gh-pages-deploy",
3 | "version": "0.5.1",
4 | "description": "deploy to gh-pages with one command",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1",
8 | "deploy": "./bin/gh-pages-deploy"
9 | },
10 | "author": "meandave",
11 | "license": "MIT",
12 | "bin": "./bin/gh-pages-deploy",
13 | "gh-pages-deploy": {
14 | "staticpath": "example"
15 | },
16 | "repository": {
17 | "type": "git",
18 | "url": "https://github.com/meandavejustice/gh-pages-deploy.git"
19 | },
20 | "bugs": {
21 | "url": "https://github.com/meandavejustice/gh-pages-deploy.git"
22 | },
23 | "homepage": "https://github.com/meandavejustice/gh-pages-deploy",
24 | "dependencies": {
25 | "chalk": "^1.1.1",
26 | "gasket": "^2.0.0",
27 | "prompt": "1.0.0",
28 | "require-module": "^0.1.0"
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/bin/gh-pages-deploy:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var chalk = require('chalk');
3 | var packageJSON = require('require-module')('./package.json');
4 | var deploy = require('../index');
5 |
6 | var cfg = packageJSON['gh-pages-deploy'] || {};
7 |
8 | var buildCmd = deploy.getFullCmd(cfg);
9 |
10 | deploy.displayCmds(deploy.getFullCmd(cfg));
11 |
12 | if (cfg.noprompt) {
13 | deploy.execBuild(buildCmd, cfg);
14 | } else {
15 | var prompt = require('prompt');
16 | prompt.message = chalk.cyan("gh-pages-deploy:");
17 | prompt.delimiter = chalk.green(" ^ ");
18 | prompt.start();
19 |
20 | var question = {
21 | properties: {
22 | deploy: {
23 | description: chalk.magenta('Would you like to deploy to github using these commands? (Y/N)')
24 | }
25 | }
26 | };
27 |
28 | prompt.get(question, function(err, result) {
29 | if (result.deploy.toLowerCase() === 'n') process.exit(0);
30 | deploy.execBuild(buildCmd, cfg);
31 | });
32 | }
33 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Dave Justice
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GH-pages-deploy
2 |
3 | [](https://npmjs.org/package/gh-pages-deploy)
4 |
5 | Deploy straight to [github pages](https://pages.github.com/) with one simple command.
6 |
7 | ## Usage
8 |
9 | ```
10 | # install it from npm and symlink it into your PATH
11 | npm install gh-pages-deploy -g
12 |
13 | # now run it!
14 | gh-pages-deploy
15 | ```
16 |
17 | You can also use `npm run` to package it with your app without installing it globally.
18 |
19 | First add this to your scripts section of `package.json`:
20 |
21 | ```JSON
22 | "scripts": {
23 | "deploy": "gh-pages-deploy",
24 | "clean-source": "rimraf README.md src webroot package.json"
25 | },
26 | ```
27 |
28 | And then install `gh-pages-deploy` as a devDependency:
29 |
30 | ```
31 | npm install gh-pages-deploy --save-dev
32 | ```
33 |
34 | And now you can run `npm run deploy` to run the `gh-pages-deploy` installed in the local `node_modules` folder (even if you have never done `npm install gh-pages-deploy -g`).
35 |
36 | You can also provide a custom commit message via command line argument:
37 |
38 | ```JSON
39 | "scripts": {
40 | "deploy": "gh-pages-deploy -- 'A custom commit message'",
41 | },
42 | ```
43 |
44 | ## Options
45 |
46 | To configure `gh-pages-deploy` all you need to do is specify a couple of things in your `package.json` (all of which are optional)
47 |
48 | ``` JSON
49 | "gh-pages-deploy": {
50 | "staticpath": "dist",
51 | "cname": "nope.org",
52 | "prep": [
53 | "build-sass",
54 | "optimize-img"
55 | ],
56 | "commit": "a custom commit message",
57 | "post": [
58 | "clean-source"
59 | ],
60 | "noprompt": false
61 | },
62 |
63 | ```
64 |
65 | * "staticpath" path to your files to be copied over to the root directory
66 | * "cname" content for CNAME file
67 | * "prep" an array of script names to run before pushing to github, this can be
68 | any script that you have declared in your "scripts" object in your `package.json`.
69 | * "commit" a custom commit message to be used when committing to git
70 | * "post" an array of script names to run after "prep", but before add/commit/push
71 | * "noprompt" if this is set to true, the prompt will be bypassed and you will never
72 | need to confirm the commands before deploying.
73 |
74 | ## About
75 |
76 | This repo uses `gh-pages-deploy`. Checkout the [gh-pages](https://github.com/meandavejustice/gh-pages-deploy/tree/gh-pages)
77 | branch and the result at [http://davejustice.com/gh-pages-deploy/](http://davejustice.com/gh-pages-deploy/).
78 |
79 |
80 | This was inspired after a conversation with [max ogden](https://github.com/maxogden) regarding the setup of
81 | the [Code For Portland](http://www.codeforportland.org/) Jekyll Pages. Inspired by the [
82 | leveldb.org repository](https://github.com/Level/leveldb.org/blob/master/package.json#L13), I
83 | wanted an easier way for people to generate static pages and deploy to github without
84 | being tied to just jekyll.
85 |
86 | ## LICENSE
87 |
88 | MIT
89 |
90 |
91 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | var exec = require('child_process').exec;
2 | var gasket = require('gasket');
3 | var chalk = require('chalk');
4 | var prompt = require('prompt');
5 |
6 | var packageJSON = require('require-module')('./package.json');
7 | var cfg = packageJSON['gh-pages-deploy'] || {};
8 |
9 | prompt.message = "gh-pages-deploy".grey;
10 | prompt.delimiter = "=>".grey;
11 |
12 | var gitbranch = "git branch -f gh-pages";
13 | var gitcheckout = "git checkout gh-pages";
14 | var gitreset = "git reset --hard origin/master";
15 | var gitadd = "git add -A .";
16 | var defaultmessage = "gh-pages update";
17 | var gitcommit = "git commit -a -m '" + (process.argv[3] || cfg.commit || defaultmessage) + "'";
18 | var gitpush = "git push origin gh-pages --force";
19 | var gitcheckmaster = "git checkout master";
20 | var getcurrentbranch = "git rev-parse --abbrev-ref HEAD";
21 |
22 | var question = {
23 | properties: {
24 | recover: {
25 | description: 'There was an error. Would you like to try and recover your original state? (Y/N)'.magenta
26 | }
27 | }
28 | };
29 |
30 | function getBuildCmd(prepCmds, postCmds) {
31 | return [
32 | gitbranch,
33 | gitcheckout,
34 | gitreset
35 | ].concat(
36 | prepCmds,
37 | postCmds,
38 | [
39 | gitadd,
40 | gitcommit,
41 | gitpush,
42 | gitcheckmaster
43 | ]
44 | )
45 | }
46 |
47 | function getPrepCmd(cfg) {
48 | var prefix = 'npm run ';
49 | var userCmds = [];
50 | if (cfg.prep) {
51 | userCmds = cfg.prep.map(function(script) {
52 | return prefix + script;
53 | });
54 | }
55 |
56 | if (cfg.staticpath) userCmds.push("cp -r " + cfg.staticpath + "/* .");
57 | if (cfg.cname) userCmds.push("echo '" + cfg.cname + "' > CNAME");
58 |
59 | return userCmds;
60 | }
61 |
62 | function getPostCmd(cfg) {
63 | var prefix = 'npm run ';
64 | var userCmds = [];
65 | if (cfg.post) {
66 | userCmds = cfg.post.map(function(script) {
67 | return prefix + script;
68 | });
69 | }
70 |
71 | return userCmds;
72 | }
73 |
74 | function displayCmds(cmd) {
75 | console.log(chalk.gray('Preparing to deploy to gh-pages with these commands: \n'));
76 | cmd.forEach(function(script, idx) {
77 | if (script !== null) {
78 | if (idx === 0) {
79 | console.log(chalk.blue(' '+ script + '\n'));
80 | } else {
81 | console.log(chalk.blue(script + '\n'));
82 | }
83 | }
84 | });
85 | }
86 |
87 | function getRecoverCmd(currentBranch) {
88 | return ["echo recovering your original state",
89 | "echo checking out "+currentBranch,
90 | "git checkout "+currentBranch];
91 | }
92 |
93 | function execBuild(buildCmd, cfg) {
94 | exec(getcurrentbranch, function (error, stdout, stderr) {
95 | var currentBranch = stdout;
96 |
97 | var pipelines = gasket({
98 | build: buildCmd,
99 | recover: prepBuild(getRecoverCmd(currentBranch))
100 | });
101 | pipelines.run('build').on('error', function(err) {
102 | if (!cfg.noprompt) {
103 | prompt.start();
104 | prompt.get(question, function(err,result) {
105 | if (result.recover.toLowerCase() === 'n') process.exit(0);
106 | pipelines.run('recover').pipe(process.stdout);
107 | });
108 | } else {
109 | pipelines.run('recover').pipe(process.stdout);
110 | }
111 |
112 | }).pipe(process.stdout)
113 | });
114 | }
115 |
116 | function prepBuild (cmds) {
117 | var freshArr = [];
118 | cmds.forEach(function(cmd) {
119 | freshArr.push(cmd);
120 | freshArr.push(null);
121 | });
122 | return freshArr;
123 | }
124 |
125 | function getFullCmd(cfg) {
126 | return prepBuild(getBuildCmd(getPrepCmd(cfg), getPostCmd(cfg)));
127 | }
128 |
129 | module.exports = {
130 | getFullCmd: getFullCmd,
131 | displayCmds: displayCmds,
132 | execBuild: execBuild
133 | }
134 |
--------------------------------------------------------------------------------