This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd.ts
135 lines (116 loc) · 3.7 KB
/
cmd.ts
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
#!/usr/bin/env node
import { join } from 'path'
import minimist from 'minimist'
import debug from 'debug'
import {
findSites, runEleventy, matchSiteConfig,
Config, SiteConfig, RunOptions, DEFAULT_CONFIG,
logger
} from './lib'
const Eleventy = require('@11ty/eleventy')
const dbg = debug('eleventy-multisite:cmd')
const args = minimist(process.argv.slice(2), {
string: [
'basedir', 'outdir', 'config', 'exclude', 'pathprefix',
'b', 'o', 'c', 'E', 'P'
],
boolean: [
'watch', 'serve', 'dryrun',
'w', 'S', 'n'
],
})
args.basedir = args.basedir || args.b
args.outdir = args.outdir || args.o
args.config = args.config || args.c
args.exclude = args.exclude || args.E
args.watch = args.watch || args.w
args.serve = args.serve || args.S
args.port = args.port || args.p
args.dryrun = args.dryrun || args.n
args.pathprefix = args.pathprefix || args.P
if(args.version || args.v) {
console.log('eleventy-multisite', require('./package.json').version)
process.exit()
} else if(args.help || args.h) {
console.log(`Usage: eleventy-multisite [OPTIONS] SITE [SITE2 SITE3...]
Examples:
eleventy-multisite
eleventy-multisite --basedir . --outdir _build
Options:
-b, --basedir base directory of sites, default \`sites/\`
-o, --outdir base directory of output, default \`_out/\`
-c, --config configuration file path, default \`.eleventy.js\`
-E, --exclude exclude this glob pattern, can be specified multiple times
-w, --watch watch and rebuild as files change
-S, --serve start a web server serving built site, automatically \`--watch\`
can't watch more than one site in one command
-p, --port serve at this port, defualt 8080 (Eleventy default)
-n, --dryrun don't write to disk; passed to Eleventy
-P, --pathprefix see Eleventy doc [1]
-v, --version
-h, --help
1: https://www.11ty.dev/docs/config/#deploy-to-a-subdirectory-with-a-path-prefix
Arguments:
SITE glob patterns for sites to operate on, under \`basedir\`
`)
process.exit()
}
const globs = args._
if(globs.length === 0) {
dbg('no glob patterns specified, using config values')
}
const config: Config = Object.assign({}, DEFAULT_CONFIG, (new Eleventy(args.basedir, args.outdir, {
configPath: args.config,
})).eleventyConfig.userConfig.multisiteConfig || {}
)
if(args.basedir) {
config.baseDir = args.basedir
}
if(args.outdir) {
config.outDir = args.outdir
}
if(args.pathprefix) {
config.pathPrefix = args.pathprefix.split(',')
}
if(args.formats) {
config.templateFormats = args.formats.split(',')
}
dbg('global config %o', config)
const sites = findSites(config, globs.length == 0 ?
config.sites.map(spec => typeof spec === 'string' ? spec : spec[0]) :
globs
)
dbg('collected sites %o', sites)
if(args.serve && sites.length > 1) {
logger.error(`Can't serve more than one site.`)
process.exit(1)
}
if(sites.length == 0) {
logger.warn('No site is found.')
process.exit(1)
}
// TODO: get rid of this async workaround
(async () => {
for(let site of sites) {
logger.log(`running Eleventy for site ${site}`)
const siteConfig: SiteConfig = matchSiteConfig(config, site) || {}
dbg('site `%s` config %o', site, siteConfig)
const runOptions: RunOptions = {
sourceDir: join(config.baseDir, site),
outDir: join(config.outDir, site),
configPath: siteConfig.configPath,
globalConfigPath: args.config,
pathPrefix: siteConfig.pathPrefix || config.pathPrefix,
templateFormats: siteConfig.templateFormats || config.templateFormats,
port: args.port,
serve: args.serve,
watch: args.watch,
dryRun: args.dryrun,
incremental: args.incremental,
quite: args.quite,
ignoreGlobal: siteConfig.ignoreGlobal,
passthroughCopy: siteConfig.passthroughCopy,
}
await runEleventy(runOptions)
}
})()