UNPKG

2.13 kBJavaScriptView Raw
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'use strict';
14
15const { getOrCreateLogger } = require('./log-common.js');
16const yargsBuild = require('./yargs-build.js');
17
18module.exports = function pack() {
19 let executor;
20
21 return {
22 set executor(value) {
23 executor = value;
24 },
25 command: 'package [files..]',
26 desc: 'Create Adobe I/O runtime packages',
27 builder: (yargs) => {
28 yargsBuild(yargs)
29 .option('force', {
30 describe: 'Forces creation of packages even if the sources are not modified.',
31 type: 'boolean',
32 default: false,
33 })
34 .option('minify', {
35 describe: 'Enables minification of the final action bundle.',
36 type: 'boolean',
37 default: false,
38 })
39 .option('target', {
40 alias: 'o',
41 default: '.hlx/build',
42 type: 'string',
43 describe: 'Target directory for packaged actions',
44 })
45 .group(['force', 'minify', 'target'], 'Package options')
46 .help();
47 },
48 handler: async (argv) => {
49 if (!executor) {
50 // eslint-disable-next-line global-require
51 const PackageCommand = require('./package.cmd'); // lazy load the handler to speed up execution time
52 executor = new PackageCommand(getOrCreateLogger(argv));
53 }
54
55 await executor
56 .withTarget(argv.target)
57 .withFiles(argv.files)
58 .withOnlyModified(!argv.force)
59 .withMinify(argv.minify)
60 .withCustomPipeline(argv.customPipeline)
61 .run();
62 },
63 };
64};