-
Notifications
You must be signed in to change notification settings - Fork 3
/
cli.js
executable file
·90 lines (75 loc) · 2.92 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
#!/usr/bin/env node
// The Static Plus command-line tool
//
// 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.
var fs = require('fs')
var URL = require('url')
var util = require('util')
var optimist = require('optimist')
//var sp = require('./api')
var Deuce = require('./deuce')
var OPTS = optimist.describe('prefix', 'Production hostname prefix')
.default('prefix', 'www.')
.describe('staging-prefix', 'Staging hostname prefix')
.default('staging-prefix', 'staging.')
.describe('bounce-prefix', 'Prefix to bounce to production (e.g. "")')
.default('bounce-prefix', null)
.describe('seed', 'Seed build data from a directory')
.describe('publish', 'Push website attachments from a directory')
.describe('ro', 'Make the site read-only except _admin and "editor" roles')
.boolean('ro')
.describe('watch', 'Continue updating seed or publish directory')
.boolean('watch')
.usage('$0 <couch> <db> <domain> [--seed=...] [--publish=...]')
function main(argv) {
var couch = argv._[0]
, db = argv._[1]
, host = argv._[2]
if(argv.help || !couch || !db || !host)
return OPTS.showHelp()
if(argv.cycle) {
console.log('push_wait = %j', argv.cycle)
Deuce = Deuce.defaults({'push_wait': +argv.cycle})
}
var site = new Deuce
site.db = db
site.hostname = host
site.watch = argv.watch
site.is_read_only = argv.ro
if('prefix' in argv)
site.production_prefix = argv.prefix || '' // I think Optimist turns "" into 0.
if('staging-prefix' in argv)
site.staging_prefix = argv['staging-prefix'] || ''
if('bounce-prefix' in argv)
site.bounce_prefix = argv['bounce-prefix'] || ''
//if(argv.log)
// site.log.transports.console.level = argv.log
couch = URL.parse(couch)
if(argv.creds)
couch.auth = argv.creds
site.couch = URL.format(couch)
if(!argv.seed)
site.run()
else
site.run('db', function() {
// Sort of re-implement the end of the run() method.
console.debug('DB is ready; update seed document')
site.seed(argv.seed)
site.on('seed', function() { site.ddoc() })
site.on('ddoc', function() { site.follow() })
})
if(argv.publish)
site.on('ddoc', function() { site.update(argv.publish) })
}
if(require.main === module)
main(OPTS.argv)