UNPKG

6.01 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3/***************************************************************************************
4 * (c) 2017 Adobe. All rights reserved.
5 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License. You may obtain a copy
7 * of the License at http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under
10 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11 * OF ANY KIND, either express or implied. See the License for the specific language
12 * governing permissions and limitations under the License.
13 ****************************************************************************************/
14const {hideBin} = require('yargs/helpers');
15const argv = require('yargs/yargs')(hideBin(process.argv))
16 .scriptName('@adobe/reactor-uploader')
17 .usage('Usage: $0 <zipPath> [options]')
18 .command('zipPath', 'The local path to the extension package zip file you wish to upload.')
19 .options({
20 'private-key': {
21 type: 'string',
22 describe: 'For authentication using an Adobe I/O integration. The local path (relative or absolute) to the RSA private key. Instructions on how to generate this key can be found in the Getting Started guide (https://developer.adobelaunch.com/guides/extensions/getting-started/) and should have been used when creating your integration through the Adobe I/O console. Optionally, rather than passing the private key path as a command line argument, it can instead be provided by setting one of the following environment variables, depending on the environment that will be receiving the extension package: REACTOR_IO_INTEGRATION_PRIVATE_KEY_DEVELOPMENT, REACTOR_IO_INTEGRATION_PRIVATE_KEY_QE, REACTOR_IO_INTEGRATION_PRIVATE_KEY_INTEGRATION, REACTOR_IO_INTEGRATION_PRIVATE_KEY'
23 },
24 'org-id': {
25 type: 'string',
26 describe: 'For authentication using an Adobe I/O integration. Your organization ID. You can find this on the overview screen for the integration you have created within the Adobe I/O console (https://console.adobe.io).'
27 },
28 'tech-account-id': {
29 type: 'string',
30 describe: 'For authentication using an Adobe I/O integration. Your technical account ID. You can find this on the overview screen for the integration you have created within the Adobe I/O console (https://console.adobe.io).'
31 },
32 'api-key': {
33 type: 'string',
34 describe: 'For authentication using an Adobe I/O integration. Your API key/Client ID. You can find this on the overview screen for the integration you have created within the Adobe I/O console (https://console.adobe.io).'
35 },
36 'client-secret': {
37 type: 'string',
38 describe: 'For authentication using an Adobe I/O integration. Your client secret. You can find this on the overview screen for the integration you have created within the Adobe I/O console (https://console.adobe.io). Optionally, rather than passing the client secret as a command line argument, it can instead be provided by setting one of the following environment variables, depending on the environment that will be receiving the extension package: REACTOR_IO_INTEGRATION_CLIENT_SECRET_DEVELOPMENT, REACTOR_IO_INTEGRATION_CLIENT_SECRET_QE, REACTOR_IO_INTEGRATION_CLIENT_SECRET_INTEGRATION, REACTOR_IO_INTEGRATION_CLIENT_SECRET'
39 },
40 environment: {
41 type: 'string',
42 describe: 'The environment to which the extension packaqe should be uploaded (for Adobe internal use only).',
43 choices: ['development', 'qe', 'integration']
44 },
45 verbose: {
46 type: 'boolean',
47 describe: 'Logs additional information useful for debugging.'
48 }
49 })
50 .epilogue('For more information, see https://www.npmjs.com/package/@adobe/reactor-uploader.')
51 .argv;
52
53const chalk = require('chalk');
54const getEnvironment = require('./getEnvironment');
55const getIntegrationAccessToken = require('./getIntegrationAccessToken');
56const getZipPath = require('./getZipPath');
57const getExtensionPackageManifest = require('./getExtensionPackageManifest');
58const getExtensionPackageFromServer = require('./getExtensionPackageFromServer');
59const uploadZip = require('./uploadZip');
60const monitorStatus = require('./monitorStatus');
61const envConfig = require('./envConfig');
62const checkOldProductionEnvironmentVariables = require('./checkOldProductionEnvironmentVariables');
63
64(async () => {
65 try {
66 if (argv.verbose) {
67 require('request-debug')(require('request-promise-native'), function(type, data, r) {
68 const filteredData = { ...data };
69 if (filteredData.headers && filteredData.headers.Authorization) {
70 filteredData.headers.Authorization = 'Bearer [USER_ACCESS_TOKEN]'
71 }
72 console.error({ [type]: filteredData })
73 return r;
74 });
75 }
76
77 const environment = getEnvironment(argv);
78 const envSpecificConfig = envConfig[environment];
79
80 checkOldProductionEnvironmentVariables();
81
82 const integrationAccessToken = await getIntegrationAccessToken(envSpecificConfig, argv);
83 const zipPath = await getZipPath(argv);
84 const extensionPackageManifest = await getExtensionPackageManifest(zipPath);
85 const extensionPackageFromServer = await getExtensionPackageFromServer(
86 envSpecificConfig,
87 integrationAccessToken,
88 extensionPackageManifest,
89 argv
90 );
91 const extensionPackageId = await uploadZip(
92 envSpecificConfig,
93 integrationAccessToken,
94 extensionPackageManifest,
95 extensionPackageFromServer,
96 zipPath,
97 argv
98 );
99 await monitorStatus(
100 envSpecificConfig,
101 integrationAccessToken,
102 extensionPackageId,
103 argv
104 );
105 } catch (error) {
106 if (argv.verbose) {
107 throw error;
108 }
109
110 console.log(chalk.bold.red(error.message));
111 console.log(chalk.bold.red('run in --verbose mode for more info'));
112 process.exitCode = 1;
113 }
114})();