@contentful/app-scripts 1.11.0 → 1.13.0

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.
Files changed (82) hide show
  1. package/README.md +4 -4
  2. package/lib/activate/activate-bundle.d.ts +2 -0
  3. package/lib/activate/activate-bundle.js +45 -58
  4. package/lib/activate/build-bundle-activate-settings.d.ts +2 -0
  5. package/lib/activate/build-bundle-activate-settings.js +32 -34
  6. package/lib/activate/get-activate-args.d.ts +2 -0
  7. package/lib/activate/get-activate-args.js +33 -30
  8. package/lib/activate/index.d.ts +5 -0
  9. package/lib/activate/index.js +17 -13
  10. package/lib/analytics.d.ts +11 -0
  11. package/lib/analytics.js +42 -0
  12. package/lib/bin.d.ts +2 -0
  13. package/lib/bin.js +69 -0
  14. package/lib/cache-credential/index.d.ts +1 -0
  15. package/lib/cache-credential/index.js +74 -0
  16. package/lib/clean-up/build-clean-up-settings.d.ts +2 -0
  17. package/lib/clean-up/build-clean-up-settings.js +32 -36
  18. package/lib/clean-up/clean-up-bundles.d.ts +2 -0
  19. package/lib/clean-up/clean-up-bundles.js +91 -118
  20. package/lib/clean-up/get-clean-up-settings.d.ts +2 -0
  21. package/lib/clean-up/get-clean-up-settings.js +34 -32
  22. package/lib/clean-up/index.d.ts +5 -0
  23. package/lib/clean-up/index.js +17 -13
  24. package/lib/constants.d.ts +8 -0
  25. package/lib/constants.js +11 -0
  26. package/lib/create-app-definition/build-app-definition-settings.d.ts +7 -0
  27. package/lib/create-app-definition/build-app-definition-settings.js +73 -77
  28. package/lib/create-app-definition/create-app-definition.d.ts +2 -0
  29. package/lib/create-app-definition/create-app-definition.js +80 -112
  30. package/lib/create-app-definition/index.d.ts +4 -0
  31. package/lib/create-app-definition/index.js +18 -15
  32. package/lib/definition-api.d.ts +7 -0
  33. package/lib/definition-api.js +37 -44
  34. package/lib/get-app-info.d.ts +10 -0
  35. package/lib/get-app-info.js +22 -27
  36. package/lib/get-management-token.d.ts +1 -0
  37. package/lib/get-management-token.js +53 -60
  38. package/lib/index.d.ts +6 -0
  39. package/lib/index.js +15 -15
  40. package/lib/open/index.d.ts +5 -0
  41. package/lib/open/index.js +12 -8
  42. package/lib/open/open-settings.d.ts +3 -0
  43. package/lib/open/open-settings.js +46 -46
  44. package/lib/organization-api.d.ts +7 -0
  45. package/lib/organization-api.js +39 -51
  46. package/lib/types.d.ts +73 -0
  47. package/lib/types.js +2 -0
  48. package/lib/upload/build-upload-settings.d.ts +2 -0
  49. package/lib/upload/build-upload-settings.js +53 -57
  50. package/lib/upload/create-app-bundle.d.ts +3 -0
  51. package/lib/upload/create-app-bundle.js +64 -70
  52. package/lib/upload/create-app-upload.d.ts +2 -0
  53. package/lib/upload/create-app-upload.js +31 -36
  54. package/lib/upload/create-zip-from-directory.d.ts +2 -0
  55. package/lib/upload/create-zip-from-directory.js +23 -21
  56. package/lib/upload/get-upload-settings-args.d.ts +2 -0
  57. package/lib/upload/get-upload-settings-args.js +43 -39
  58. package/lib/upload/index.d.ts +5 -0
  59. package/lib/upload/index.js +20 -18
  60. package/lib/upload/validate-bundle.d.ts +1 -0
  61. package/lib/upload/validate-bundle.js +26 -33
  62. package/lib/utils.d.ts +12 -0
  63. package/lib/utils.js +92 -120
  64. package/lib/validate-arguments.d.ts +1 -0
  65. package/lib/validate-arguments.js +20 -14
  66. package/package.json +24 -12
  67. package/bin/app-scripts +0 -78
  68. package/lib/activate/activate-bundle.test.js +0 -69
  69. package/lib/clean-up/clean-up-bundles.test.js +0 -118
  70. package/lib/create-app-definition/create-app-definition.test.js +0 -87
  71. package/lib/get-app-info.test.js +0 -57
  72. package/lib/get-management-token.test.js +0 -82
  73. package/lib/open/open-settings.test.js +0 -45
  74. package/lib/upload/create-app-bundle.test.js +0 -110
  75. package/lib/upload/create-app-upload.test.js +0 -50
  76. package/lib/upload/validate-bundle.test.js +0 -45
  77. package/lib/utils.test.js +0 -198
  78. package/lib/validate-arguments.test.js +0 -33
  79. package/utils/analytics.js +0 -36
  80. package/utils/cache-credential/index.js +0 -81
  81. package/utils/cache-credential/index.test.js +0 -73
  82. package/utils/constants.js +0 -21
@@ -1,50 +1,50 @@
1
- const open = require('open');
2
- const chalk = require('chalk');
3
- const inquirer = require('inquirer');
4
- const { APP_DEF_ENV_KEY } = require('../../utils/constants');
5
-
6
- const REDIRECT_URL = 'https://app.contentful.com/deeplink?link=app-definition';
7
-
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.openSettings = exports.REDIRECT_URL = void 0;
7
+ const open_1 = __importDefault(require("open"));
8
+ const chalk_1 = __importDefault(require("chalk"));
9
+ const inquirer_1 = __importDefault(require("inquirer"));
10
+ const constants_1 = require("../constants");
11
+ exports.REDIRECT_URL = 'https://app.contentful.com/deeplink?link=app-definition';
8
12
  async function openSettings(options) {
9
- let definitionId;
10
- if (options.definitionId) {
11
- definitionId = options.definitionId;
12
- } else if (process.env[APP_DEF_ENV_KEY]) {
13
- definitionId = process.env[APP_DEF_ENV_KEY];
14
- } else {
15
- const prompts = await inquirer.prompt([
16
- {
17
- name: 'definitionId',
18
- message: `The id of the app:`,
19
- },
20
- ]);
21
- definitionId = prompts.definitionId;
22
- }
23
-
24
- console.log(definitionId, 'DEFID');
25
- console.log(options, 'options');
26
- console.log(process.env[APP_DEF_ENV_KEY], 'process.env[APP_DEF_ENV_KEY]');
13
+ let definitionId;
14
+ if (options.definitionId) {
15
+ definitionId = options.definitionId;
16
+ }
17
+ else if (process.env[constants_1.APP_DEF_ENV_KEY]) {
18
+ definitionId = process.env[constants_1.APP_DEF_ENV_KEY];
19
+ }
20
+ else {
21
+ const prompts = await inquirer_1.default.prompt([
22
+ {
23
+ name: 'definitionId',
24
+ message: `The id of the app:`,
25
+ },
26
+ ]);
27
+ definitionId = prompts.definitionId;
28
+ }
29
+ console.log(definitionId, 'DEFID');
30
+ console.log(options, 'options');
31
+ console.log(process.env[constants_1.APP_DEF_ENV_KEY], 'process.env[APP_DEF_ENV_KEY]');
32
+ if (!definitionId) {
33
+ console.log(`
34
+ ${chalk_1.default.red('Error:')} There was no app-definition defined.
27
35
 
28
- if (!definitionId) {
29
- console.log(`
30
- ${chalk.red('Error:')} There was no app-definition defined.
31
-
32
- Please add it with ${chalk.cyan('--definition-id=<app-definition-id>')}
33
- or set the environment variable ${chalk.cyan(`${APP_DEF_ENV_KEY} = <app-definition-id>`)}
36
+ Please add it with ${chalk_1.default.cyan('--definition-id=<app-definition-id>')}
37
+ or set the environment variable ${chalk_1.default.cyan(`${constants_1.APP_DEF_ENV_KEY} = <app-definition-id>`)}
34
38
  `);
35
- throw new Error('No app-definition-id');
36
- }
37
-
38
- try {
39
- open(`${REDIRECT_URL}&id=${definitionId}`);
40
- } catch (err) {
41
- console.log(`${chalk.red('Error:')} Failed to open browser`);
42
- console.log(err.message);
43
- throw err;
44
- }
39
+ throw new Error('No app-definition-id');
40
+ }
41
+ try {
42
+ (0, open_1.default)(`${exports.REDIRECT_URL}&id=${definitionId}`);
43
+ }
44
+ catch (err) {
45
+ console.log(`${chalk_1.default.red('Error:')} Failed to open browser`);
46
+ console.log(err.message);
47
+ throw err;
48
+ }
45
49
  }
46
-
47
- module.exports = {
48
- openSettings,
49
- REDIRECT_URL,
50
- };
50
+ exports.openSettings = openSettings;
@@ -0,0 +1,7 @@
1
+ import { ClientAPI } from 'contentful-management';
2
+ export interface Organization {
3
+ name: string;
4
+ value: string;
5
+ }
6
+ export declare function selectOrganization(client: ClientAPI): Promise<Organization>;
7
+ export declare function getOrganizationById(client: ClientAPI, orgId: string): Promise<Organization>;
@@ -1,57 +1,45 @@
1
- const ora = require('ora');
2
- const { selectFromList } = require('./utils');
3
- const { throwError } = require('./utils');
4
- const { ORG_ID_ENV_KEY } = require('../utils/constants');
5
-
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getOrganizationById = exports.selectOrganization = void 0;
7
+ const ora_1 = __importDefault(require("ora"));
8
+ const utils_1 = require("./utils");
9
+ const constants_1 = require("./constants");
6
10
  async function fetchOrganizations(client) {
7
- try {
8
- const orgs = await client.getOrganizations();
9
-
10
- return orgs.items.map((org) => ({
11
- name: org.name,
12
- value: org.sys.id,
13
- }));
14
- } catch (err) {
15
- throwError(
16
- err,
17
- 'Could not fetch your organizations. Make sure you provided a valid access token.'
18
- );
19
- }
11
+ try {
12
+ const orgs = await client.getOrganizations();
13
+ return orgs.items.map((org) => ({
14
+ name: org.name,
15
+ value: org.sys.id,
16
+ }));
17
+ }
18
+ catch (err) {
19
+ return (0, utils_1.throwError)(err, 'Could not fetch your organizations. Make sure you provided a valid access token.');
20
+ }
20
21
  }
21
-
22
22
  async function selectOrganization(client) {
23
- const orgSpinner = ora('Fetching your organizations...').start();
24
- let organizations = null;
25
-
26
- try {
27
- organizations = await fetchOrganizations(client);
28
- } finally {
29
- orgSpinner.stop();
30
- }
31
-
32
- if (!organizations) {
33
- return null;
34
- }
35
-
36
- return await selectFromList(organizations, 'Select an organization:', ORG_ID_ENV_KEY);
23
+ const orgSpinner = (0, ora_1.default)('Fetching your organizations...').start();
24
+ try {
25
+ const organizations = await fetchOrganizations(client);
26
+ return await (0, utils_1.selectFromList)(organizations, 'Select an organization:', constants_1.ORG_ID_ENV_KEY);
27
+ }
28
+ finally {
29
+ orgSpinner.stop();
30
+ }
37
31
  }
38
-
32
+ exports.selectOrganization = selectOrganization;
39
33
  async function getOrganizationById(client, orgId) {
40
- try {
41
- const org = await client.getOrganization(orgId);
42
- return {
43
- name: org.name,
44
- value: org.sys.id,
45
- };
46
- } catch (err) {
47
- throwError(
48
- err,
49
- 'Could not fetch your organization. Make sure you provided a valid access token.'
50
- );
51
- }
34
+ try {
35
+ const org = await client.getOrganization(orgId);
36
+ return {
37
+ name: org.name,
38
+ value: org.sys.id,
39
+ };
40
+ }
41
+ catch (err) {
42
+ return (0, utils_1.throwError)(err, 'Could not fetch your organization. Make sure you provided a valid access token.');
43
+ }
52
44
  }
53
-
54
- module.exports = {
55
- selectOrganization,
56
- getOrganizationById,
57
- };
45
+ exports.getOrganizationById = getOrganizationById;
package/lib/types.d.ts ADDED
@@ -0,0 +1,73 @@
1
+ import { Definition } from "./definition-api";
2
+ import { Organization } from "./organization-api";
3
+ export interface FunctionAppAction {
4
+ id: string;
5
+ name: string;
6
+ description: string;
7
+ category: 'Custom';
8
+ type: 'function';
9
+ path: string;
10
+ allowNetworks?: string[];
11
+ entryFile?: string;
12
+ }
13
+ export interface DeliveryFunction {
14
+ id: string;
15
+ name: string;
16
+ description: string;
17
+ path: string;
18
+ allowNetworks?: string[];
19
+ entryFile?: string;
20
+ }
21
+ export interface ActivateOptions {
22
+ bundleId: string;
23
+ organizationId?: string;
24
+ definitionId?: string;
25
+ token?: string;
26
+ host?: string;
27
+ }
28
+ export interface ActivateSettings {
29
+ bundleId: string;
30
+ organization: Organization;
31
+ definition: Definition;
32
+ accessToken: string;
33
+ host?: string;
34
+ }
35
+ export interface CleanupOptions {
36
+ organizationId?: string;
37
+ definitionId?: string;
38
+ token?: string;
39
+ host?: string;
40
+ keep?: string;
41
+ }
42
+ export interface CleanupSettings {
43
+ keep: number;
44
+ host?: string;
45
+ accessToken: string;
46
+ organization: Organization;
47
+ definition: Definition;
48
+ }
49
+ export interface OpenSettingsOptions {
50
+ definitionId?: string;
51
+ }
52
+ export interface UploadOptions {
53
+ organizationId?: string;
54
+ definitionId?: string;
55
+ token?: string;
56
+ bundleDir?: string;
57
+ comment?: string;
58
+ skipActivation?: boolean;
59
+ host?: string;
60
+ userAgentApplication?: string;
61
+ }
62
+ export interface UploadSettings {
63
+ organization: Organization;
64
+ definition: Definition;
65
+ accessToken: string;
66
+ comment?: string;
67
+ bundleDirectory: string;
68
+ skipActivation?: boolean;
69
+ userAgentApplication?: string;
70
+ host?: string;
71
+ actions?: FunctionAppAction[];
72
+ deliveryFunctions?: DeliveryFunction[];
73
+ }
package/lib/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import { UploadOptions, UploadSettings } from '../types';
2
+ export declare function buildAppUploadSettings(options: UploadOptions): Promise<UploadSettings>;
@@ -1,59 +1,55 @@
1
- // @ts-check
2
-
3
- const inquirer = require('inquirer');
4
- const { getAppInfo } = require('../get-app-info');
5
- const { getActionsManifest } = require('../utils');
6
- const { CONTENTFUL_API_HOST } = require('../../utils/constants');
7
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildAppUploadSettings = void 0;
4
+ const inquirer_1 = require("inquirer");
5
+ const get_app_info_1 = require("../get-app-info");
6
+ const utils_1 = require("../utils");
7
+ const constants_1 = require("../constants");
8
8
  async function buildAppUploadSettings(options) {
9
- const actionsManifest = getActionsManifest();
10
- const prompts = [];
11
- const { bundleDir, comment, skipActivation, host } = options;
12
- if (!bundleDir) {
13
- prompts.push({
14
- name: 'bundleDirectory',
15
- message: `Bundle directory, if not default:`,
16
- default: './build',
17
- });
18
- }
19
- if (!comment) {
20
- prompts.push({
21
- name: 'comment',
22
- message: `Add a comment to the created bundle:`,
23
- default: '',
24
- });
25
- }
26
- if (skipActivation === undefined) {
27
- prompts.push({
28
- type: 'confirm',
29
- name: 'activateBundle',
30
- message: `Do you want to activate the bundle after upload?`,
31
- default: true,
32
- });
33
- }
34
- if (!host) {
35
- prompts.push({
36
- name: 'host',
37
- message: `Contentful CMA endpoint URL:`,
38
- default: CONTENTFUL_API_HOST,
39
- });
40
- }
41
-
42
- const { activateBundle, ...appUploadSettings } = await inquirer.prompt(prompts);
43
-
44
- const appInfo = await getAppInfo(options);
45
- // Add app-config & dialog automatically
46
- return {
47
- bundleDirectory: bundleDir,
48
- skipActivation: skipActivation === undefined ? !activateBundle : skipActivation,
49
- comment,
50
- host,
51
- actions: actionsManifest,
52
- ...appUploadSettings,
53
- ...appInfo,
54
- };
9
+ const actionsManifest = (0, utils_1.getEntityFromManifest)('actions');
10
+ const deliveryFnManifest = (0, utils_1.getEntityFromManifest)('deliveryFunctions');
11
+ const prompts = [];
12
+ const { bundleDir, comment, skipActivation, host } = options;
13
+ if (!bundleDir) {
14
+ prompts.push({
15
+ name: 'bundleDirectory',
16
+ message: `Bundle directory, if not default:`,
17
+ default: './build',
18
+ });
19
+ }
20
+ if (!comment) {
21
+ prompts.push({
22
+ name: 'comment',
23
+ message: `Add a comment to the created bundle:`,
24
+ default: '',
25
+ });
26
+ }
27
+ if (skipActivation === undefined) {
28
+ prompts.push({
29
+ type: 'confirm',
30
+ name: 'activateBundle',
31
+ message: `Do you want to activate the bundle after upload?`,
32
+ default: true,
33
+ });
34
+ }
35
+ if (!host) {
36
+ prompts.push({
37
+ name: 'host',
38
+ message: `Contentful CMA endpoint URL:`,
39
+ default: constants_1.DEFAULT_CONTENTFUL_API_HOST,
40
+ });
41
+ }
42
+ const { activateBundle, ...appUploadSettings } = await (0, inquirer_1.prompt)(prompts);
43
+ const appInfo = await (0, get_app_info_1.getAppInfo)(options);
44
+ return {
45
+ bundleDirectory: bundleDir,
46
+ skipActivation: skipActivation === undefined ? !activateBundle : skipActivation,
47
+ comment,
48
+ host,
49
+ actions: actionsManifest,
50
+ deliveryFunctions: deliveryFnManifest,
51
+ ...appUploadSettings,
52
+ ...appInfo,
53
+ };
55
54
  }
56
-
57
- module.exports = {
58
- buildAppUploadSettings,
59
- };
55
+ exports.buildAppUploadSettings = buildAppUploadSettings;
@@ -0,0 +1,3 @@
1
+ import { UploadSettings } from '../types';
2
+ export declare function createAppBundleFromUpload(settings: UploadSettings, appUploadId: string): Promise<import("contentful-management").AppBundle | null>;
3
+ export declare function createAppBundleFromSettings(settings: UploadSettings): Promise<void | import("contentful-management").AppBundle>;
@@ -1,84 +1,78 @@
1
- const chalk = require('chalk');
2
- const ora = require('ora');
3
- const { showCreationError } = require('../utils');
4
- const { createClient } = require('contentful-management');
5
-
6
- const { createAppUpload } = require('./create-app-upload');
7
-
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createAppBundleFromSettings = exports.createAppBundleFromUpload = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const ora_1 = __importDefault(require("ora"));
9
+ const utils_1 = require("../utils");
10
+ const contentful_management_1 = require("contentful-management");
11
+ const create_app_upload_1 = require("./create-app-upload");
8
12
  async function createAppBundleFromUpload(settings, appUploadId) {
9
- const { accessToken, host, userAgentApplication, comment, actions } = settings;
10
- const clientSpinner = ora('Verifying your upload...').start();
11
- const client = createClient({
12
- accessToken,
13
- host,
14
- application: userAgentApplication ? userAgentApplication : 'contentful.app-scripts',
15
- });
16
- const organization = await client.getOrganization(settings.organization.value);
17
- const appDefinition = await organization.getAppDefinition(settings.definition.value);
18
- clientSpinner.stop();
19
-
20
- let appBundle = null;
21
- const bundleSpinner = ora('Creating the app bundle...').start();
22
- try {
23
- appBundle = await appDefinition.createAppBundle({
24
- appUploadId,
25
- comment: comment && comment.length > 0 ? comment : undefined,
26
- actions,
13
+ const { accessToken, host, userAgentApplication, comment, actions, deliveryFunctions } = settings;
14
+ const clientSpinner = (0, ora_1.default)('Verifying your upload...').start();
15
+ const client = (0, contentful_management_1.createClient)({
16
+ accessToken,
17
+ host,
18
+ application: userAgentApplication ? userAgentApplication : 'contentful.app-scripts',
27
19
  });
28
- } catch (err) {
29
- showCreationError('app upload', err.message);
30
- }
31
- bundleSpinner.stop();
32
- return appBundle;
20
+ const organization = await client.getOrganization(settings.organization.value);
21
+ const appDefinition = await organization.getAppDefinition(settings.definition.value);
22
+ clientSpinner.stop();
23
+ let appBundle = null;
24
+ const bundleSpinner = (0, ora_1.default)('Creating the app bundle...').start();
25
+ try {
26
+ appBundle = await appDefinition.createAppBundle({
27
+ appUploadId,
28
+ comment: comment && comment.length > 0 ? comment : undefined,
29
+ actions,
30
+ deliveryFunctions,
31
+ });
32
+ }
33
+ catch (err) {
34
+ (0, utils_1.showCreationError)('app upload', err.message);
35
+ }
36
+ bundleSpinner.stop();
37
+ return appBundle;
33
38
  }
34
-
39
+ exports.createAppBundleFromUpload = createAppBundleFromUpload;
35
40
  async function createAppBundleFromSettings(settings) {
36
- let appUpload = null;
37
- try {
38
- appUpload = await createAppUpload(settings);
41
+ let appUpload = null;
42
+ try {
43
+ appUpload = await (0, create_app_upload_1.createAppUpload)(settings);
44
+ if (!appUpload)
45
+ return;
46
+ console.log(`
47
+ ${chalk_1.default.yellow('Done!')} Your files were successfully uploaded and a new AppUpload (${chalk_1.default.dim(appUpload.sys.id)}) has been created.`);
48
+ }
49
+ catch (err) {
50
+ return (0, utils_1.showCreationError)('app upload', err.message);
51
+ }
52
+ console.log('');
53
+ console.log(` ----------------------------`);
54
+ const appBundle = await createAppBundleFromUpload(settings, appUpload.sys.id);
55
+ if (!appBundle)
56
+ return;
39
57
  console.log(`
40
- ${chalk.yellow('Done!')} Your files were successfully uploaded and a new AppUpload (${chalk.dim(
41
- appUpload.sys.id
42
- )}) has been created.`);
43
- } catch (err) {
44
- showCreationError('app upload', err.message);
45
- }
46
-
47
- if (!appUpload) return;
48
-
49
- console.log('');
50
- console.log(` ----------------------------`);
51
- const appBundle = await createAppBundleFromUpload(settings, appUpload.sys.id);
58
+ ${chalk_1.default.cyan('Success!')} Created a new app bundle for ${chalk_1.default.cyan(settings.definition.name)} in ${chalk_1.default.bold(settings.organization.name)}.
52
59
 
53
- if (!appBundle) return;
54
-
55
- console.log(`
56
- ${chalk.cyan('Success!')} Created a new app bundle for ${chalk.cyan(
57
- settings.definition.name
58
- )} in ${chalk.bold(settings.organization.name)}.
59
-
60
- Bundle Id: ${chalk.yellow(appBundle.sys.id)}
60
+ Bundle Id: ${chalk_1.default.yellow(appBundle.sys.id)}
61
61
  `);
62
+ if (settings.skipActivation) {
63
+ console.log(`
64
+ ${chalk_1.default.green(`NEXT STEPS:`)}
62
65
 
63
- if (settings.skipActivation) {
64
- console.log(`
65
- ${chalk.green(`NEXT STEPS:`)}
66
-
67
- ${chalk.bold('You can activate this app bundle in your apps settings:')}
66
+ ${chalk_1.default.bold('You can activate this app bundle in your apps settings:')}
68
67
 
69
- ${chalk.underline('https://app.contentful.com/deeplink?link=app-definition-list')}
68
+ ${chalk_1.default.underline('https://app.contentful.com/deeplink?link=app-definition-list')}
70
69
 
71
- ${chalk.bold('or by simply running the cli command:')}
70
+ ${chalk_1.default.bold('or by simply running the cli command:')}
72
71
 
73
- ${chalk.underline('npx @contentful/app-scripts activate')}
72
+ ${chalk_1.default.underline('npx @contentful/app-scripts activate')}
74
73
 
75
74
  `);
76
- }
77
-
78
- return appBundle;
75
+ }
76
+ return appBundle;
79
77
  }
80
-
81
- module.exports = {
82
- createAppBundleFromSettings,
83
- createAppBundleFromUpload,
84
- };
78
+ exports.createAppBundleFromSettings = createAppBundleFromSettings;
@@ -0,0 +1,2 @@
1
+ import { UploadSettings } from '../types';
2
+ export declare function createAppUpload(settings: UploadSettings): Promise<import("contentful-management").AppUpload | null | undefined>;
@@ -1,40 +1,35 @@
1
- const ora = require('ora');
2
- const { createZipFileFromDirectory } = require('./create-zip-from-directory');
3
- const { validateBundle } = require('./validate-bundle');
4
- const { showCreationError } = require('../utils');
5
- const { createClient } = require('contentful-management');
6
-
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createAppUpload = void 0;
7
+ const ora_1 = __importDefault(require("ora"));
8
+ const create_zip_from_directory_1 = require("./create-zip-from-directory");
9
+ const validate_bundle_1 = require("./validate-bundle");
10
+ const utils_1 = require("../utils");
11
+ const contentful_management_1 = require("contentful-management");
7
12
  async function createAppBundleFromFile(orgId, token, zip, host = '') {
8
- const client = await createClient({ accessToken: token, host, hostUpload: host.replace(/^api/i, 'upload') });
9
- const org = await client.getOrganization(orgId);
10
- return await org.createAppUpload(zip);
13
+ const client = (0, contentful_management_1.createClient)({ accessToken: token, host, hostUpload: host.replace(/^api/i, 'upload') });
14
+ const org = await client.getOrganization(orgId);
15
+ return await org.createAppUpload(zip);
11
16
  }
12
-
13
17
  async function createAppUpload(settings) {
14
- validateBundle(settings.bundleDirectory || '.');
15
- let appUpload = null;
16
- const zipFileSpinner = ora('Preparing your files for upload...').start();
17
- const zipFile = await createZipFileFromDirectory(settings.bundleDirectory || '.');
18
- zipFileSpinner.stop();
19
-
20
- if (!zipFile) return;
21
-
22
- const uploadSpinner = ora('Uploading your files...').start();
23
- try {
24
- appUpload = await createAppBundleFromFile(
25
- settings.organization.value,
26
- settings.accessToken,
27
- zipFile,
28
- settings.host
29
- );
30
- } catch (err) {
31
- showCreationError('app bundle', err.message);
32
- }
33
-
34
- uploadSpinner.stop();
35
- return appUpload;
18
+ (0, validate_bundle_1.validateBundle)(settings.bundleDirectory || '.');
19
+ let appUpload = null;
20
+ const zipFileSpinner = (0, ora_1.default)('Preparing your files for upload...').start();
21
+ const zipFile = await (0, create_zip_from_directory_1.createZipFileFromDirectory)(settings.bundleDirectory || '../types');
22
+ zipFileSpinner.stop();
23
+ if (!zipFile)
24
+ return;
25
+ const uploadSpinner = (0, ora_1.default)('Uploading your files...').start();
26
+ try {
27
+ appUpload = await createAppBundleFromFile(settings.organization.value, settings.accessToken, zipFile, settings.host);
28
+ }
29
+ catch (err) {
30
+ (0, utils_1.showCreationError)('app bundle', err.message);
31
+ }
32
+ uploadSpinner.stop();
33
+ return appUpload;
36
34
  }
37
-
38
- module.exports = {
39
- createAppUpload,
40
- };
35
+ exports.createAppUpload = createAppUpload;
@@ -0,0 +1,2 @@
1
+ /// <reference types="node" />
2
+ export declare function createZipFileFromDirectory(path: string): Promise<Buffer | null>;