1 | /*
|
2 | * Copyright 2018 Adobe. All rights reserved.
|
3 | * This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
4 | * you may not use this file except in compliance with the License. You may obtain a copy
|
5 | * of the License at http://www.apache.org/licenses/LICENSE-2.0
|
6 | *
|
7 | * Unless required by applicable law or agreed to in writing, software distributed under
|
8 | * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
9 | * OF ANY KIND, either express or implied. See the License for the specific language
|
10 | * governing permissions and limitations under the License.
|
11 | */
|
12 |
|
13 | ;
|
14 |
|
15 | const { getOrCreateLogger } = require('./log-common.js');
|
16 |
|
17 | module.exports = function demo() {
|
18 | let executor;
|
19 |
|
20 | return {
|
21 | set executor(value) {
|
22 | executor = value;
|
23 | },
|
24 | command: 'demo <name> [dir]',
|
25 | desc: 'Create example helix project.',
|
26 | builder: (yargs) => {
|
27 | yargs
|
28 | .option('type', {
|
29 | describe: 'Demo source type',
|
30 | type: 'string',
|
31 | choices: ['simple', 'full'],
|
32 | default: 'simple',
|
33 | })
|
34 | .positional('name', {
|
35 | type: 'string',
|
36 | describe: 'Name of the project to create',
|
37 | })
|
38 | .positional('dir', {
|
39 | type: 'string',
|
40 | describe: 'Parent directory of new project',
|
41 | default: '.',
|
42 | })
|
43 | .env('NO_HLX_ENV_SUPPORT_FOR_DEMO')
|
44 | .strict();
|
45 | },
|
46 | handler: async (argv) => {
|
47 | if (!executor) {
|
48 | // eslint-disable-next-line global-require
|
49 | const DemoCommand = require('./demo.cmd'); // lazy load the handler to speed up execution time
|
50 | executor = new DemoCommand(getOrCreateLogger(argv));
|
51 | }
|
52 |
|
53 | await executor
|
54 | .withDirectory(argv.dir)
|
55 | .withName(argv.name)
|
56 | .withType(argv.type)
|
57 | .run();
|
58 | },
|
59 | };
|
60 | };
|