@contentful/app-scripts 1.12.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.
- package/README.md +4 -4
- package/lib/activate/activate-bundle.d.ts +2 -0
- package/lib/activate/activate-bundle.js +45 -58
- package/lib/activate/build-bundle-activate-settings.d.ts +2 -0
- package/lib/activate/build-bundle-activate-settings.js +32 -34
- package/lib/activate/get-activate-args.d.ts +2 -0
- package/lib/activate/get-activate-args.js +33 -30
- package/lib/activate/index.d.ts +5 -0
- package/lib/activate/index.js +17 -13
- package/lib/analytics.d.ts +11 -0
- package/lib/analytics.js +42 -0
- package/lib/bin.d.ts +2 -0
- package/lib/bin.js +69 -0
- package/lib/cache-credential/index.d.ts +1 -0
- package/lib/cache-credential/index.js +74 -0
- package/lib/clean-up/build-clean-up-settings.d.ts +2 -0
- package/lib/clean-up/build-clean-up-settings.js +32 -36
- package/lib/clean-up/clean-up-bundles.d.ts +2 -0
- package/lib/clean-up/clean-up-bundles.js +91 -118
- package/lib/clean-up/get-clean-up-settings.d.ts +2 -0
- package/lib/clean-up/get-clean-up-settings.js +34 -32
- package/lib/clean-up/index.d.ts +5 -0
- package/lib/clean-up/index.js +17 -13
- package/lib/constants.d.ts +8 -0
- package/lib/constants.js +11 -0
- package/lib/create-app-definition/build-app-definition-settings.d.ts +7 -0
- package/lib/create-app-definition/build-app-definition-settings.js +73 -77
- package/lib/create-app-definition/create-app-definition.d.ts +2 -0
- package/lib/create-app-definition/create-app-definition.js +80 -112
- package/lib/create-app-definition/index.d.ts +4 -0
- package/lib/create-app-definition/index.js +18 -15
- package/lib/definition-api.d.ts +7 -0
- package/lib/definition-api.js +37 -44
- package/lib/get-app-info.d.ts +10 -0
- package/lib/get-app-info.js +22 -27
- package/lib/get-management-token.d.ts +1 -0
- package/lib/get-management-token.js +53 -60
- package/lib/index.d.ts +6 -0
- package/lib/index.js +15 -15
- package/lib/open/index.d.ts +5 -0
- package/lib/open/index.js +12 -8
- package/lib/open/open-settings.d.ts +3 -0
- package/lib/open/open-settings.js +46 -46
- package/lib/organization-api.d.ts +7 -0
- package/lib/organization-api.js +39 -51
- package/lib/types.d.ts +73 -0
- package/lib/types.js +2 -0
- package/lib/upload/build-upload-settings.d.ts +2 -0
- package/lib/upload/build-upload-settings.js +53 -60
- package/lib/upload/create-app-bundle.d.ts +3 -0
- package/lib/upload/create-app-bundle.js +64 -71
- package/lib/upload/create-app-upload.d.ts +2 -0
- package/lib/upload/create-app-upload.js +31 -36
- package/lib/upload/create-zip-from-directory.d.ts +2 -0
- package/lib/upload/create-zip-from-directory.js +23 -21
- package/lib/upload/get-upload-settings-args.d.ts +2 -0
- package/lib/upload/get-upload-settings-args.js +43 -41
- package/lib/upload/index.d.ts +5 -0
- package/lib/upload/index.js +20 -18
- package/lib/upload/validate-bundle.d.ts +1 -0
- package/lib/upload/validate-bundle.js +26 -33
- package/lib/utils.d.ts +12 -0
- package/lib/utils.js +87 -121
- package/lib/validate-arguments.d.ts +1 -0
- package/lib/validate-arguments.js +20 -14
- package/package.json +23 -11
- package/bin/app-scripts +0 -78
- package/lib/activate/activate-bundle.test.js +0 -69
- package/lib/clean-up/clean-up-bundles.test.js +0 -118
- package/lib/create-app-definition/create-app-definition.test.js +0 -87
- package/lib/get-app-info.test.js +0 -57
- package/lib/get-management-token.test.js +0 -82
- package/lib/open/open-settings.test.js +0 -45
- package/lib/upload/create-app-bundle.test.js +0 -110
- package/lib/upload/create-app-upload.test.js +0 -50
- package/lib/upload/validate-bundle.test.js +0 -45
- package/lib/utils.test.js +0 -323
- package/lib/validate-arguments.test.js +0 -33
- package/utils/analytics.js +0 -36
- package/utils/cache-credential/index.js +0 -81
- package/utils/cache-credential/index.test.js +0 -73
- package/utils/constants.js +0 -21
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
29
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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>;
|
package/lib/organization-api.js
CHANGED
|
@@ -1,57 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
@@ -1,62 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
deliveryFunctions: deliveryFnManifest,
|
|
55
|
-
...appUploadSettings,
|
|
56
|
-
...appInfo,
|
|
57
|
-
};
|
|
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
|
+
};
|
|
58
54
|
}
|
|
59
|
-
|
|
60
|
-
module.exports = {
|
|
61
|
-
buildAppUploadSettings,
|
|
62
|
-
};
|
|
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,85 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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,
|
|
27
|
-
deliveryFunctions,
|
|
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',
|
|
28
19
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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;
|
|
34
38
|
}
|
|
35
|
-
|
|
39
|
+
exports.createAppBundleFromUpload = createAppBundleFromUpload;
|
|
36
40
|
async function createAppBundleFromSettings(settings) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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;
|
|
40
57
|
console.log(`
|
|
41
|
-
${
|
|
42
|
-
appUpload.sys.id,
|
|
43
|
-
)}) has been created.`);
|
|
44
|
-
} catch (err) {
|
|
45
|
-
showCreationError('app upload', err.message);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (!appUpload) return;
|
|
49
|
-
|
|
50
|
-
console.log('');
|
|
51
|
-
console.log(` ----------------------------`);
|
|
52
|
-
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)}.
|
|
53
59
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
console.log(`
|
|
57
|
-
${chalk.cyan('Success!')} Created a new app bundle for ${chalk.cyan(
|
|
58
|
-
settings.definition.name,
|
|
59
|
-
)} in ${chalk.bold(settings.organization.name)}.
|
|
60
|
-
|
|
61
|
-
Bundle Id: ${chalk.yellow(appBundle.sys.id)}
|
|
60
|
+
Bundle Id: ${chalk_1.default.yellow(appBundle.sys.id)}
|
|
62
61
|
`);
|
|
62
|
+
if (settings.skipActivation) {
|
|
63
|
+
console.log(`
|
|
64
|
+
${chalk_1.default.green(`NEXT STEPS:`)}
|
|
63
65
|
|
|
64
|
-
|
|
65
|
-
console.log(`
|
|
66
|
-
${chalk.green(`NEXT STEPS:`)}
|
|
67
|
-
|
|
68
|
-
${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:')}
|
|
69
67
|
|
|
70
|
-
${
|
|
68
|
+
${chalk_1.default.underline('https://app.contentful.com/deeplink?link=app-definition-list')}
|
|
71
69
|
|
|
72
|
-
${
|
|
70
|
+
${chalk_1.default.bold('or by simply running the cli command:')}
|
|
73
71
|
|
|
74
|
-
${
|
|
72
|
+
${chalk_1.default.underline('npx @contentful/app-scripts activate')}
|
|
75
73
|
|
|
76
74
|
`);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return appBundle;
|
|
75
|
+
}
|
|
76
|
+
return appBundle;
|
|
80
77
|
}
|
|
81
|
-
|
|
82
|
-
module.exports = {
|
|
83
|
-
createAppBundleFromSettings,
|
|
84
|
-
createAppBundleFromUpload,
|
|
85
|
-
};
|
|
78
|
+
exports.createAppBundleFromSettings = createAppBundleFromSettings;
|
|
@@ -1,40 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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;
|