@adobe/helix-deploy 4.15.1 → 5.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,60 +10,47 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
  /* eslint-disable no-await-in-loop,no-restricted-syntax */
13
- const chalk = require('chalk');
14
- const {
15
- S3Client,
16
- CreateBucketCommand,
13
+ import chalk from 'chalk-template';
14
+ import {
15
+ CreateBucketCommand, DeleteBucketCommand, DeleteObjectCommand, DeleteObjectsCommand,
17
16
  ListBucketsCommand,
18
- ListObjectsV2Command,
19
- PutObjectCommand,
20
- DeleteBucketCommand,
21
- DeleteObjectCommand,
22
- DeleteObjectsCommand,
23
- } = require('@aws-sdk/client-s3');
24
- const {
25
- LambdaClient,
26
- CreateFunctionCommand,
17
+ ListObjectsV2Command, PutObjectCommand,
18
+ S3Client,
19
+ } from '@aws-sdk/client-s3';
20
+
21
+ import {
22
+ AddPermissionCommand,
23
+ CreateAliasCommand,
24
+ CreateFunctionCommand, GetAliasCommand,
27
25
  GetFunctionCommand,
26
+ LambdaClient, PublishVersionCommand, UpdateAliasCommand, UpdateFunctionCodeCommand,
28
27
  UpdateFunctionConfigurationCommand,
29
- UpdateFunctionCodeCommand,
30
- GetAliasCommand,
31
- PublishVersionCommand,
32
- CreateAliasCommand,
33
- UpdateAliasCommand,
34
- AddPermissionCommand,
35
- } = require('@aws-sdk/client-lambda');
36
- const {
28
+ } from '@aws-sdk/client-lambda';
29
+
30
+ import {
37
31
  ApiGatewayV2Client,
38
- GetApisCommand,
39
- GetApiCommand,
40
- GetStagesCommand,
41
- GetIntegrationsCommand,
42
32
  CreateApiCommand,
33
+ CreateIntegrationCommand, CreateRouteCommand,
43
34
  CreateStageCommand,
44
- CreateIntegrationCommand,
45
35
  DeleteIntegrationCommand,
46
- CreateRouteCommand,
47
- GetRoutesCommand,
48
- UpdateRouteCommand,
49
- } = require('@aws-sdk/client-apigatewayv2');
50
- const {
51
- SSMClient,
52
- PutParameterCommand,
53
- } = require('@aws-sdk/client-ssm');
54
- const {
55
- SecretsManagerClient,
56
- PutSecretValueCommand,
57
- } = require('@aws-sdk/client-secrets-manager');
58
-
59
- const path = require('path');
60
- const fse = require('fs-extra');
61
- const crypto = require('crypto');
62
- const BaseDeployer = require('./BaseDeployer');
63
- const ActionBuilder = require('../ActionBuilder.js');
64
- const AWSConfig = require('./AWSConfig.js');
65
-
66
- class AWSDeployer extends BaseDeployer {
36
+ GetApiCommand,
37
+ GetApisCommand,
38
+ GetIntegrationsCommand, GetRoutesCommand,
39
+ GetStagesCommand, UpdateRouteCommand,
40
+ } from '@aws-sdk/client-apigatewayv2';
41
+
42
+ import { PutParameterCommand, SSMClient } from '@aws-sdk/client-ssm';
43
+
44
+ import { PutSecretValueCommand, SecretsManagerClient } from '@aws-sdk/client-secrets-manager';
45
+
46
+ import path from 'path';
47
+ import fse from 'fs-extra';
48
+ import crypto from 'crypto';
49
+ import BaseDeployer from './BaseDeployer.js';
50
+ import ActionBuilder from '../ActionBuilder.js';
51
+ import AWSConfig from './AWSConfig.js';
52
+
53
+ export default class AWSDeployer extends BaseDeployer {
67
54
  constructor(baseConfig, config) {
68
55
  super(baseConfig);
69
56
 
@@ -228,26 +215,41 @@ class AWSDeployer extends BaseDeployer {
228
215
 
229
216
  this.log.info(`--: using lambda role "${this._cfg.role}"`);
230
217
 
218
+ // check if function already exists
219
+ let baseARN;
231
220
  try {
232
- this.log.info(`--: updating existing Lambda function ${functionName}`);
233
- await this._lambda.send(new GetFunctionCommand({
221
+ this.log.info(chalk`--: checking existing Lambda function {yellow ${functionName}}`);
222
+ const { Configuration: { FunctionArn } } = await this._lambda.send(new GetFunctionCommand({
234
223
  FunctionName: functionName,
235
224
  }));
236
- await this._lambda.send(new UpdateFunctionConfigurationCommand(functionConfig));
237
- await this._lambda.send(new UpdateFunctionCodeCommand({
238
- FunctionName: functionName,
239
- ...functionConfig.Code,
240
- }));
225
+ baseARN = FunctionArn;
226
+ this.log.info(chalk`{green ok}: exist {yellow ${FunctionArn}}`);
241
227
  } catch (e) {
242
228
  if (e.name === 'ResourceNotFoundException') {
243
- this.log.info(`--: creating new Lambda function ${functionName}`);
229
+ this.log.info(chalk`{green ok}: does not exist yet.`);
230
+ this.log.info(chalk`--: creating new Lambda function {yellow ${functionName}}`);
244
231
  await this._lambda.send(new CreateFunctionCommand(functionConfig));
245
232
  } else {
246
- this.log.error(`Unable to verify existence of Lambda function ${functionName}`);
233
+ this.log.error(chalk`Unable to verify existence of Lambda function {yellow ${functionName}}`);
247
234
  throw e;
248
235
  }
249
236
  }
250
237
 
238
+ // update existing function
239
+ if (baseARN) {
240
+ await this.checkFunctionReady(baseARN);
241
+ this.log.info(chalk`--: updating existing Lambda function configuration {yellow ${functionName}}`);
242
+ await this._lambda.send(new UpdateFunctionConfigurationCommand(functionConfig));
243
+ await this.checkFunctionReady(baseARN);
244
+ this.log.info('--: updating Lambda function code...');
245
+ await this._lambda.send(new UpdateFunctionCodeCommand({
246
+ FunctionName: functionName,
247
+ ...functionConfig.Code,
248
+ }));
249
+ }
250
+ await this.checkFunctionReady(baseARN);
251
+
252
+ this.log.info('--: publishing new version');
251
253
  const versiondata = await this._lambda.send(new PublishVersionCommand({
252
254
  FunctionName: functionName,
253
255
  }));
@@ -255,22 +257,23 @@ class AWSDeployer extends BaseDeployer {
255
257
  this._functionARN = versiondata.FunctionArn;
256
258
  // eslint-disable-next-line prefer-destructuring
257
259
  this._accountId = this._functionARN.split(':')[4];
258
-
259
260
  const versionNum = versiondata.Version;
261
+ this.log.info(chalk`{green ok}: version {yellow ${versionNum}} published.`);
262
+
260
263
  try {
261
264
  await this._lambda.send(new GetAliasCommand({
262
265
  FunctionName: functionName,
263
266
  Name: functionVersion,
264
267
  }));
265
268
 
266
- this.log.info(`--: updating existing alias ${functionName}:${functionVersion} to v${versionNum}`);
269
+ this.log.info(chalk`--: updating existing alias {yellow ${functionName}:${functionVersion}} to version {yellow ${versionNum}}`);
267
270
  const updatedata = await this._lambda.send(new UpdateAliasCommand({
268
271
  FunctionName: functionName,
269
272
  Name: functionVersion,
270
273
  FunctionVersion: versionNum,
271
274
  }));
272
-
273
275
  this._aliasARN = updatedata.AliasArn;
276
+ this.log.info(chalk`{green ok}: alias {yellow ${this._aliasARN}} updated.`);
274
277
  } catch (e) {
275
278
  if (e.name === 'ResourceNotFoundException') {
276
279
  this.log.info(`--: creating new alias ${functionName}:${functionVersion} at v${versionNum}`);
@@ -280,6 +283,7 @@ class AWSDeployer extends BaseDeployer {
280
283
  FunctionVersion: versionNum,
281
284
  }));
282
285
  this._aliasARN = createdata.AliasArn;
286
+ this.log.info(chalk`{green ok}: alias {yellow ${this._aliasARN}} created.`);
283
287
  } else {
284
288
  this.log.error(`Unable to verify existence of Lambda alias ${functionName}:${functionVersion}`);
285
289
  throw e;
@@ -422,7 +426,7 @@ class AWSDeployer extends BaseDeployer {
422
426
  // ignore, most likely the permission already exists
423
427
  }
424
428
 
425
- this.log.info(chalk`{green ok:} function deployed: ${chalk.blueBright(this._functionURL)}`);
429
+ this.log.info(chalk`{green ok:} function deployed: {blueBright ${this._functionURL}}`);
426
430
  }
427
431
 
428
432
  async test() {
@@ -530,7 +534,7 @@ class AWSDeployer extends BaseDeployer {
530
534
  });
531
535
  const unused = [];
532
536
  if (filter) {
533
- this.log.info(chalk`Integrations / Routes for {gray ${filter}}`);
537
+ this.log.info(chalk`Integrations / Routes for {grey ${filter}}`);
534
538
  } else {
535
539
  this.log.info('Integrations / Routes');
536
540
  }
@@ -689,17 +693,17 @@ class AWSDeployer extends BaseDeployer {
689
693
  }
690
694
  }
691
695
 
692
- async checkFunctionReady() {
696
+ async checkFunctionReady(arn) {
693
697
  let tries = 3;
694
698
  while (tries > 0) {
695
699
  try {
696
700
  tries -= 1;
697
701
  this.log.info(chalk`--: checking function state ...`);
698
702
  const { Configuration } = await this._lambda.send(new GetFunctionCommand({
699
- FunctionName: this._functionARN,
703
+ FunctionName: arn ?? this._functionARN,
700
704
  }));
701
- if (Configuration.State !== 'Active') {
702
- this.log.warn(chalk`{yellow warn:} function is {blue ${Configuration.State}} and last update was {blue ${Configuration.LastUpdateStatus}}.`);
705
+ if (Configuration.State !== 'Active' || Configuration.LastUpdateStatus === 'InProgress') {
706
+ this.log.info(chalk`{yellow !!:} function is {blue ${Configuration.State}} and last update was {blue ${Configuration.LastUpdateStatus}} (retry...)`);
703
707
  } else {
704
708
  this.log.info(chalk`{green ok:} function is {blue ${Configuration.State}} and last update was {blue ${Configuration.LastUpdateStatus}}.`);
705
709
  return;
@@ -752,4 +756,3 @@ class AWSDeployer extends BaseDeployer {
752
756
  }
753
757
 
754
758
  AWSDeployer.Config = AWSConfig;
755
- module.exports = AWSDeployer;
@@ -9,7 +9,7 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- class AzureConfig {
12
+ export default class AzureConfig {
13
13
  constructor() {
14
14
  Object.assign(this, {
15
15
  appName: '',
@@ -36,5 +36,3 @@ class AzureConfig {
36
36
  });
37
37
  }
38
38
  }
39
-
40
- module.exports = AzureConfig;
@@ -9,13 +9,14 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- const msRestNodeAuth = require('@azure/ms-rest-nodeauth');
13
- const { WebSiteManagementClient } = require('@azure/arm-appservice');
14
- const fs = require('fs');
15
- const BaseDeployer = require('./BaseDeployer');
16
- const AzureConfig = require('./AzureConfig.js');
12
+ import msRestNodeAuth from '@azure/ms-rest-nodeauth';
13
+ import { WebSiteManagementClient } from '@azure/arm-appservice';
17
14
 
18
- class AzureDeployer extends BaseDeployer {
15
+ import fs from 'fs';
16
+ import BaseDeployer from './BaseDeployer.js';
17
+ import AzureConfig from './AzureConfig.js';
18
+
19
+ export default class AzureDeployer extends BaseDeployer {
19
20
  constructor(baseConfig, config) {
20
21
  super(baseConfig);
21
22
  Object.assign(this, {
@@ -229,4 +230,3 @@ class AzureDeployer extends BaseDeployer {
229
230
  }
230
231
 
231
232
  AzureDeployer.Config = AzureConfig;
232
- module.exports = AzureDeployer;
@@ -9,12 +9,12 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- const path = require('path');
13
- const chalk = require('chalk');
14
- const semver = require('semver');
15
- const fetchAPI = require('@adobe/helix-fetch');
12
+ import path from 'path';
13
+ import chalk from 'chalk-template';
14
+ import semver from 'semver';
15
+ import { h1, context } from '@adobe/helix-fetch';
16
16
 
17
- class BaseDeployer {
17
+ export default class BaseDeployer {
18
18
  constructor(cfg) {
19
19
  this.isDeployer = true;
20
20
  this.cfg = cfg;
@@ -42,8 +42,8 @@ class BaseDeployer {
42
42
  getOrCreateFetchContext() {
43
43
  if (!this._fetchContext) {
44
44
  this._fetchContext = process.env.HELIX_FETCH_FORCE_HTTP1
45
- ? fetchAPI.h1()
46
- : fetchAPI.context();
45
+ ? h1()
46
+ : context();
47
47
  }
48
48
  return this._fetchContext;
49
49
  }
@@ -99,7 +99,7 @@ class BaseDeployer {
99
99
  while (retry404 >= 0) {
100
100
  // eslint-disable-next-line no-param-reassign
101
101
  const testUrl = `${url}${this.cfg.testPath || ''}`;
102
- this.log.info(`--: requesting: ${chalk.blueBright(testUrl)} ...`);
102
+ this.log.info(chalk`--: requesting: {blueBright ${testUrl}} ...`);
103
103
  // eslint-disable-next-line no-await-in-loop
104
104
  const ret = await this.fetch(testUrl, {
105
105
  headers,
@@ -110,21 +110,21 @@ class BaseDeployer {
110
110
  const body = await ret.text();
111
111
  const id = idHeader ? ret.headers.get(idHeader) : 'n/a';
112
112
  if (ret.ok) {
113
- this.log.info(`id: ${chalk.grey(id)}`);
114
- this.log.info(`${chalk.green('ok:')} ${ret.status}`);
115
- this.log.debug(chalk.grey(JSON.stringify(ret.headers.plain(), null, 2)));
113
+ this.log.info(chalk`id: {grey ${id}}`);
114
+ this.log.info(chalk`{green ok:} ${ret.status}`);
115
+ this.log.debug(chalk`{grey ${JSON.stringify(ret.headers.plain(), null, 2)}}`);
116
116
  this.log.debug('');
117
- this.log.debug(chalk.grey(body));
117
+ this.log.debug(chalk`{grey ${body}}`);
118
118
  return;
119
119
  }
120
120
  if (ret.status === 302 || ret.status === 301) {
121
- this.log.info(`${chalk.green('ok:')} ${ret.status}`);
122
- this.log.debug(chalk.grey(`Location: ${ret.headers.get('location')}`));
121
+ this.log.info(chalk`{green ok:} ${ret.status}`);
122
+ this.log.debug(chalk`{grey Location: ${ret.headers.get('location')}}`);
123
123
  return;
124
124
  }
125
- this.log.info(`id: ${chalk.grey(id)}`);
125
+ this.log.info(chalk`id: {grey ${id}}`);
126
126
  if ((ret.status === 404 || ret.status === 500) && retry404) {
127
- this.log.info(`${chalk.yellow('warn:')} ${ret.status} (retry)`);
127
+ this.log.info(chalk`{yellow warn:} ${ret.status} (retry)`);
128
128
  // eslint-disable-next-line no-param-reassign
129
129
  retry404 -= 1;
130
130
  // eslint-disable-next-line no-await-in-loop
@@ -132,7 +132,7 @@ class BaseDeployer {
132
132
  setTimeout(resolve, 1500);
133
133
  });
134
134
  } else {
135
- // this.log.info(`${chalk.red('error:')} test failed: ${ret.status} ${body}`);
135
+ // this.log.info(chalk`{red error:} test failed: ${ret.status} ${body}`);
136
136
  throw new Error(`test failed: ${ret.status} ${body}`);
137
137
  }
138
138
  }
@@ -164,7 +164,7 @@ class BaseDeployer {
164
164
  if (link === 'major' || link === 'minor') {
165
165
  if (!s) {
166
166
  // eslint-disable-next-line no-underscore-dangle
167
- this.log.warn(`${chalk.yellow('warn:')} unable to create version sequences. error while parsing version: ${this.cfg.version}`);
167
+ this.log.warn(chalk`{yellow warn:} unable to create version sequences. error while parsing version: ${this.cfg.version}`);
168
168
  return;
169
169
  }
170
170
  if (link === 'major') {
@@ -179,5 +179,3 @@ class BaseDeployer {
179
179
  return sfx;
180
180
  }
181
181
  }
182
-
183
- module.exports = BaseDeployer;
@@ -9,7 +9,7 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- class CloudflareConfig {
12
+ export default class CloudflareConfig {
13
13
  constructor() {
14
14
  Object.assign(this, {});
15
15
  }
@@ -67,5 +67,3 @@ class CloudflareConfig {
67
67
  });
68
68
  }
69
69
  }
70
-
71
- module.exports = CloudflareConfig;
@@ -9,13 +9,13 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- const path = require('path');
13
- const fs = require('fs');
14
- const FormData = require('form-data');
15
- const BaseDeployer = require('./BaseDeployer');
16
- const CloudflareConfig = require('./CloudflareConfig');
12
+ import path from 'path';
13
+ import fs from 'fs';
14
+ import FormData from 'form-data';
15
+ import BaseDeployer from './BaseDeployer.js';
16
+ import CloudflareConfig from './CloudflareConfig.js';
17
17
 
18
- class CloudflareDeployer extends BaseDeployer {
18
+ export default class CloudflareDeployer extends BaseDeployer {
19
19
  constructor(baseConfig, config) {
20
20
  super(baseConfig);
21
21
  Object.assign(this, {
@@ -142,4 +142,3 @@ class CloudflareDeployer extends BaseDeployer {
142
142
  }
143
143
 
144
144
  CloudflareDeployer.Config = CloudflareConfig;
145
- module.exports = CloudflareDeployer;
@@ -9,7 +9,7 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- class ComputeAtEdgeConfig {
12
+ export default class ComputeAtEdgeConfig {
13
13
  constructor() {
14
14
  Object.assign(this, {});
15
15
  }
@@ -89,5 +89,3 @@ class ComputeAtEdgeConfig {
89
89
  });
90
90
  }
91
91
  }
92
-
93
- module.exports = ComputeAtEdgeConfig;
@@ -9,14 +9,18 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- const { fork } = require('child_process');
13
- const path = require('path');
14
- const fs = require('fs/promises');
15
- const tar = require('tar');
16
- const getStream = require('get-stream');
17
- const Fastly = require('@adobe/fastly-native-promises');
18
- const BaseDeployer = require('./BaseDeployer');
19
- const ComputeAtEdgeConfig = require('./ComputeAtEdgeConfig');
12
+ import { fork } from 'child_process';
13
+ import { fileURLToPath } from 'url';
14
+ import path from 'path';
15
+ import fs from 'fs/promises';
16
+ import tar from 'tar';
17
+ import getStream from 'get-stream';
18
+ import Fastly from '@adobe/fastly-native-promises';
19
+ import BaseDeployer from './BaseDeployer.js';
20
+ import ComputeAtEdgeConfig from './ComputeAtEdgeConfig.js';
21
+
22
+ // eslint-disable-next-line no-underscore-dangle
23
+ const __dirname = path.resolve(fileURLToPath(import.meta.url), '..');
20
24
 
21
25
  /**
22
26
  * The class ComputeAtEdgeDeployer deploys to Fastly's Compute(at)Edge (WASM) runtime.
@@ -24,7 +28,7 @@ const ComputeAtEdgeConfig = require('./ComputeAtEdgeConfig');
24
28
  * and not confused with the FastlyGateway (which only routes requests, but
25
29
  * does not handle them.)
26
30
  */
27
- class ComputeAtEdgeDeployer extends BaseDeployer {
31
+ export default class ComputeAtEdgeDeployer extends BaseDeployer {
28
32
  constructor(baseConfig, config) {
29
33
  super(baseConfig);
30
34
  Object.assign(this, {
@@ -187,4 +191,3 @@ service_id = ""
187
191
  }
188
192
 
189
193
  ComputeAtEdgeDeployer.Config = ComputeAtEdgeConfig;
190
- module.exports = ComputeAtEdgeDeployer;
@@ -9,7 +9,7 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- class GoogleConfig {
12
+ export default class GoogleConfig {
13
13
  constructor() {
14
14
  Object.assign(this, {
15
15
  appName: '',
@@ -69,5 +69,3 @@ class GoogleConfig {
69
69
  });
70
70
  }
71
71
  }
72
-
73
- module.exports = GoogleConfig;
@@ -9,17 +9,17 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- const { CloudFunctionsServiceClient } = require('@google-cloud/functions');
13
- const { SecretManagerServiceClient } = require('@google-cloud/secret-manager');
14
- const path = require('path');
15
- const fs = require('fs');
16
- const semver = require('semver');
17
- const chalk = require('chalk');
18
- const BaseDeployer = require('./BaseDeployer');
19
- const GoogleConfig = require('./GoogleConfig.js');
20
- const { filterActions } = require('../utils.js');
21
-
22
- class GoogleDeployer extends BaseDeployer {
12
+ import { CloudFunctionsServiceClient } from '@google-cloud/functions';
13
+ import { SecretManagerServiceClient } from '@google-cloud/secret-manager';
14
+ import path from 'path';
15
+ import fs from 'fs';
16
+ import semver from 'semver';
17
+ import chalk from 'chalk-template';
18
+ import BaseDeployer from './BaseDeployer.js';
19
+ import GoogleConfig from './GoogleConfig.js';
20
+ import { filterActions } from '../utils.js';
21
+
22
+ export default class GoogleDeployer extends BaseDeployer {
23
23
  constructor(baseConfig, config) {
24
24
  super(baseConfig);
25
25
  Object.assign(this, {
@@ -344,4 +344,3 @@ class GoogleDeployer extends BaseDeployer {
344
344
  }
345
345
 
346
346
  GoogleDeployer.Config = GoogleConfig;
347
- module.exports = GoogleDeployer;
@@ -14,7 +14,7 @@
14
14
  * @field {string} actionName Action as it would be deployed (package + name)
15
15
  * @field {boolean} packageShared If package is shared.
16
16
  */
17
- class OpenWhiskConfig {
17
+ export default class OpenWhiskConfig {
18
18
  constructor() {
19
19
  Object.assign(this, {
20
20
  namespace: '',
@@ -52,5 +52,3 @@ class OpenWhiskConfig {
52
52
  });
53
53
  }
54
54
  }
55
-
56
- module.exports = OpenWhiskConfig;
@@ -10,18 +10,16 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
  /* eslint-disable no-underscore-dangle */
13
+ import ow from 'openwhisk';
14
+ import os from 'os';
15
+ import fse from 'fs-extra';
16
+ import path from 'path';
17
+ import chalk from 'chalk-template';
18
+ import dotenv from 'dotenv';
19
+ import BaseDeployer from './BaseDeployer.js';
20
+ import OpenWhiskConfig from './OpenWhiskConfig.js';
13
21
 
14
- const ow = require('openwhisk');
15
- const os = require('os');
16
- const fse = require('fs-extra');
17
- const path = require('path');
18
- const chalk = require('chalk');
19
- const dotenv = require('dotenv');
20
-
21
- const BaseDeployer = require('./BaseDeployer');
22
- const OpenWhiskConfig = require('./OpenWhiskConfig.js');
23
-
24
- class OpenWhiskDeployer extends BaseDeployer {
22
+ export default class OpenWhiskDeployer extends BaseDeployer {
25
23
  constructor(baseConfig, config) {
26
24
  super(baseConfig);
27
25
 
@@ -88,7 +86,7 @@ class OpenWhiskDeployer extends BaseDeployer {
88
86
 
89
87
  getOpenwhiskClient() {
90
88
  if (!this._cfg.apiHost || !this._cfg.auth || !this._cfg.namespace) {
91
- throw Error(chalk`\nMissing OpenWhisk credentials. Make sure you have a {grey .wskprops} in your home directory.\nYou can also set {grey WSK_NAMESPACE}, {gray WSK_AUTH} and {gray WSK_API_HOST} environment variables.`);
89
+ throw Error(chalk`\nMissing OpenWhisk credentials. Make sure you have a {grey .wskprops} in your home directory.\nYou can also set {grey WSK_NAMESPACE}, {grey WSK_AUTH} and {grey WSK_API_HOST} environment variables.`);
92
90
  }
93
91
  return ow({
94
92
  apihost: this._cfg.apiHost,
@@ -117,7 +115,7 @@ class OpenWhiskDeployer extends BaseDeployer {
117
115
  });
118
116
  this.log.info(chalk`{green ok:} package created. ${res.namespace}/${res.name}`);
119
117
  } else {
120
- this.log.error(`${chalk.red('error: ')} ${e.message}`);
118
+ this.log.error(chalk`{red error:} ${e.message}`);
121
119
  }
122
120
  }
123
121
 
@@ -187,7 +185,7 @@ class OpenWhiskDeployer extends BaseDeployer {
187
185
  fn = openwhisk.packages.create.bind(openwhisk.packages);
188
186
  verb = 'created';
189
187
  } else {
190
- this.log.error(`${chalk.red('error: ')} ${e.message}`);
188
+ this.log.error(chalk`{red error:} ${e.message}`);
191
189
  }
192
190
  }
193
191
 
@@ -203,9 +201,9 @@ class OpenWhiskDeployer extends BaseDeployer {
203
201
  parameters,
204
202
  },
205
203
  });
206
- this.log.info(`${chalk.green('ok:')} ${verb} package ${chalk.whiteBright(`/${result.namespace}/${result.name}`)}`);
204
+ this.log.info(chalk`{green ok:} ${verb} package {whiteBright /${result.namespace}/${result.name}}`);
207
205
  } catch (e) {
208
- this.log.error(`${chalk.red('error: failed processing package: ')} ${e.stack}`);
206
+ this.log.error(chalk`{red error: failed processing package: } ${e.stack}`);
209
207
  throw Error('abort.');
210
208
  }
211
209
  }
@@ -270,10 +268,10 @@ class OpenWhiskDeployer extends BaseDeployer {
270
268
  try {
271
269
  this.log.debug(`creating sequence: ${options.name} -> ${options.action.exec.components[0]}`);
272
270
  const result = await openwhisk.actions.update(options);
273
- this.log.info(`${chalk.green('ok:')} created sequence ${chalk.whiteBright(`/${result.namespace}/${result.name}`)} -> ${chalk.whiteBright(fqn)}`);
271
+ this.log.info(chalk`{green ok:} created sequence {whiteBright /${result.namespace}/${result.name}} -> {whiteBright ${fqn}}`);
274
272
  } catch (e) {
275
273
  hasErrors = true;
276
- this.log.error(`${chalk.red('error:')} failed creating sequence: ${e.message}`);
274
+ this.log.error(chalk`{red error:} failed creating sequence: ${e.message}`);
277
275
  }
278
276
  }));
279
277
  if (hasErrors) {
@@ -283,4 +281,3 @@ class OpenWhiskDeployer extends BaseDeployer {
283
281
  }
284
282
 
285
283
  OpenWhiskDeployer.Config = OpenWhiskConfig;
286
- module.exports = OpenWhiskDeployer;
@@ -9,7 +9,7 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- class FastlyConfig {
12
+ export default class FastlyConfig {
13
13
  constructor() {
14
14
  Object.assign(this, {
15
15
  service: null,
@@ -94,5 +94,3 @@ class FastlyConfig {
94
94
  });
95
95
  }
96
96
  }
97
-
98
- module.exports = FastlyConfig;
@@ -9,15 +9,16 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- const Fastly = require('@adobe/fastly-native-promises');
13
- const chalk = require('chalk');
12
+ import Fastly from '@adobe/fastly-native-promises';
13
+ import chalk from 'chalk-template';
14
+ import FastlyConfig from './FastlyConfig.js';
15
+ import BaseDeployer from '../deploy/BaseDeployer.js';
16
+
14
17
  const {
15
18
  toString, vcl, time, req, res, str, concat,
16
- } = require('@adobe/fastly-native-promises').loghelpers;
17
- const FastlyConfig = require('./FastlyConfig.js');
18
- const BaseDeployer = require('../deploy/BaseDeployer.js');
19
+ } = Fastly.loghelpers;
19
20
 
20
- class FastlyGateway {
21
+ export default class FastlyGateway {
21
22
  constructor(baseConfig, config) {
22
23
  Object.assign(this, {
23
24
  cfg: baseConfig,
@@ -505,4 +506,3 @@ if (req.url ~ "^/([^/]+)/([^/@_]+)([@_]([^/@_?]+)+)?(.*$)") {
505
506
  }
506
507
 
507
508
  FastlyGateway.Config = FastlyConfig;
508
- module.exports = FastlyGateway;
package/src/index.js CHANGED
@@ -12,6 +12,6 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
- const CLI = require('./cli.js');
15
+ import CLI from './cli.js';
16
16
 
17
17
  new CLI().run(process.argv.slice(2));