1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | const path = require('path');
|
17 | const yargsBuild = require('./yargs-build.js');
|
18 | const yargsParams = require('./yargs-params.js');
|
19 | const yargsGithub = require('./yargs-github.js');
|
20 | const yargsAlgolia = require('./yargs-algolia.js');
|
21 | const { getOrCreateLogger } = require('./log-common.js');
|
22 |
|
23 | module.exports = function up() {
|
24 | let executor;
|
25 | return {
|
26 | set executor(value) {
|
27 | executor = value;
|
28 | },
|
29 | command: 'up [files...]',
|
30 | description: 'Run a Helix development server',
|
31 | builder: (yargs) => {
|
32 | yargsBuild(yargs);
|
33 | yargsGithub(yargs);
|
34 | yargsAlgolia(yargs);
|
35 | yargsParams(yargs, {
|
36 | name: 'dev-default',
|
37 | describe: 'Additional action parameters',
|
38 | alias: ['devDefault'],
|
39 | type: 'array',
|
40 | default: [],
|
41 | });
|
42 | yargs
|
43 | .option('open', {
|
44 | describe: 'Open a browser window',
|
45 | type: 'boolean',
|
46 | default: true,
|
47 | })
|
48 | .option('no-open', {
|
49 |
|
50 |
|
51 | alias: 'noOpen',
|
52 | describe: 'Disable automatic opening of browser window',
|
53 | type: 'boolean',
|
54 | })
|
55 | .option('livereload', {
|
56 | describe: 'Enable automatic reloading of modified sources in browser.',
|
57 | type: 'boolean',
|
58 | default: true,
|
59 | })
|
60 | .option('no-livereload', {
|
61 |
|
62 |
|
63 | alias: 'noLiveReload',
|
64 | describe: 'Disable live-reload',
|
65 | type: 'boolean',
|
66 | })
|
67 | .option('host', {
|
68 | describe: 'Override request.host',
|
69 | type: 'string',
|
70 | })
|
71 | .option('local-repo', {
|
72 | alias: 'localRepo',
|
73 | describe: 'Emulates a GitHub repository for the specified local git repository.',
|
74 | type: 'string',
|
75 | array: true,
|
76 | default: '.',
|
77 | })
|
78 |
|
79 | .coerce('localRepo', (value) => value.reduce((acc, curr) => {
|
80 | if (curr) {
|
81 | acc.push(...curr.split(/\s*,\s*/));
|
82 | }
|
83 | return acc;
|
84 | }, []))
|
85 | .option('no-local-repo', {
|
86 |
|
87 |
|
88 | alias: 'noLocalRepo',
|
89 | describe: 'Ignore local checkout, always fetch from GitHub',
|
90 | type: 'boolean',
|
91 | })
|
92 | .option('save-config', {
|
93 | alias: 'saveConfig',
|
94 | describe: 'Saves the default config.',
|
95 | type: 'boolean',
|
96 | default: false,
|
97 | })
|
98 | .option('port', {
|
99 | describe: 'Start development server on port',
|
100 | type: 'int',
|
101 | default: 3000,
|
102 | })
|
103 | .group(['port', 'open', 'no-open', 'host', 'local-repo', 'no-local-repo'], 'Server options')
|
104 | .help();
|
105 | },
|
106 | handler: async (argv) => {
|
107 | if (!executor) {
|
108 |
|
109 | const UpCommand = require('./up.cmd');
|
110 | executor = new UpCommand(getOrCreateLogger(argv));
|
111 | }
|
112 |
|
113 | await executor
|
114 | .withTargetDir(argv.target)
|
115 | .withFiles(argv.files)
|
116 | .withOverrideHost(argv.host)
|
117 | .withSaveConfig(argv.saveConfig)
|
118 | .withHttpPort(argv.port)
|
119 | .withLocalRepo(argv.localRepo)
|
120 | .withDevDefault(argv.devDefault)
|
121 | .withDevDefaultFile(argv.devDefaultFile)
|
122 | .withGithubToken(argv.githubToken)
|
123 |
|
124 |
|
125 | .withOpen(argv.open && path.basename(argv.$0) === 'hlx')
|
126 | .withLiveReload(argv.livereload)
|
127 | .withCustomPipeline(argv.customPipeline)
|
128 | .withAlgoliaAppID(argv.algoliaAppID)
|
129 | .withAlgoliaAPIKey(argv.algoliaAPIKey)
|
130 | .run();
|
131 | },
|
132 | };
|
133 | };
|