This repository has been archived by the owner on Nov 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcli.js
executable file
·148 lines (132 loc) · 4.57 KB
/
cli.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#! /usr/bin/env node
/**
* Copyright 2015 Mozilla
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
var packageJson = require('./package.json');
var program = require('commander');
var promptly = require('promisified-promptly');
var fs = require('fs');
var chalk = require('chalk');
// The scripts that implement the various commands/tasks we expose.
var configure = require('./lib/configure');
var deploy = require('./lib/deploy');
var offline = require('./lib/offline');
var bootstrap = require('./lib/bootstrap');
var integrate = require('./lib/integrate');
program
.version(packageJson.version);
program
.command('configure')
.description('configure repository to auto-deploy to GitHub Pages using Travis CI')
.action(function(env, options) {
configure()
.then(function() {
process.exit(0);
}, function(err) {
process.stderr.write(chalk.red.bold(err) + '\n');
process.exit(1);
});
});
program
.command('deploy [dir]')
.description('deploy directory to GitHub Pages')
.option('-m, --message <message>', 'commit message')
.action(function(dir, options) {
deploy({
rootDir: dir,
cloneDir: '.gh-pages-cache',
message: options.message,
})
.then(function() {
// For perf, don't delete the repository. This means users will have to
// add .gh-pages-cache to their .gitignore file to hide its `git status`.
// return fse.removeSync('.gh-pages-cache');
fs.access('.gitignore', function(err) {
if (err) {
process.stdout.write(chalk.blue.bold(
'ℹ .gh-pages-cache is a temporary repository that we use to push changes\n' +
' to your gh-pages branch. We suggest you add it to your .gitignore.\n'
));
return;
}
var gitignore = fs.readFileSync('.gitignore', 'utf8');
if (gitignore.indexOf('.gh-pages-cache') === -1) {
process.stdout.write(chalk.yellow.bold(
'⚠ .gh-pages-cache is a temporary repository that I use to push\n' +
' changes to your gh-pages branch. It isn\'t in your .gitignore file,\n' +
' which means that Git will report it as an untracked file.\n\n'
));
return promptly.confirm('Do you want to add .gh-pages-cache to .gitignore (Y/n)?', { default: true })
.then(function(answer) {
if (answer) {
gitignore += '\n.gh-pages-cache\n';
fs.writeFileSync('.gitignore', gitignore);
}
});
}
});
})
.catch(function(err) {
process.stderr.write(chalk.red.bold(err) + '\n');
process.exit(1);
});
});
program
.command('offline [dir]')
.description('offline the files in the directory by generating offline-worker.js script')
.option('--file-globs [fileGlobs]', 'a comma-separated list of file globs to offline (default: \'**/*\')', '**/*')
.option('--import-scripts <importScripts>', 'a comma-separated list of additional scripts to import into offline-worker.js')
.action(function(dir, options) {
offline({
rootDir: dir,
fileGlobs: options.fileGlobs ? options.fileGlobs.split(',') : null,
importScripts: options.importScripts ? options.importScripts.split(',') : null,
})
.catch(function(err) {
process.stderr.write(chalk.red.bold(err) + '\n');
process.exit(1);
});
});
program
.command('bootstrap [dir]')
.description('bootstrap the directory with a template app')
.action(function(dir) {
bootstrap({
rootDir: dir,
})
.then(function() {
process.exit(0);
}, function(err) {
process.stderr.write(chalk.red.bold(err) + '\n');
process.exit(1);
});
});
program
.command('integrate [dir]')
.description('integrate the offline-manager.js script into your app')
.action(function(dir) {
integrate({
dir: dir,
})
.catch(function(err) {
process.stderr.write(chalk.red.bold(err) + '\n');
process.exit(1);
});
});
program.parse(process.argv);
if (!process.argv.slice(2).length) {
program.outputHelp();
}