@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,26 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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.createZipFileFromDirectory = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const adm_zip_1 = __importDefault(require("adm-zip"));
|
|
9
|
+
const utils_1 = require("../utils");
|
|
5
10
|
async function createZipFileFromDirectory(path) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
try {
|
|
12
|
+
const zip = new adm_zip_1.default();
|
|
13
|
+
zip.addLocalFolder(path);
|
|
14
|
+
console.log("");
|
|
15
|
+
console.log(` ----------------------------
|
|
11
16
|
|
|
12
|
-
${
|
|
17
|
+
${chalk_1.default.yellow('Done!')} Files from ${chalk_1.default.dim(path)} successfully zipped.
|
|
13
18
|
|
|
14
19
|
----------------------------`);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
console.log("");
|
|
21
|
+
return zip.toBuffer();
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
(0, utils_1.showCreationError)('zip file', err.message);
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
22
27
|
}
|
|
23
|
-
|
|
24
|
-
module.exports = {
|
|
25
|
-
createZipFileFromDirectory,
|
|
26
|
-
};
|
|
28
|
+
exports.createZipFileFromDirectory = createZipFileFromDirectory;
|
|
@@ -1,47 +1,49 @@
|
|
|
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.getUploadSettingsArgs = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const ora_1 = __importDefault(require("ora"));
|
|
9
|
+
const get_app_info_1 = require("../get-app-info");
|
|
10
|
+
const validate_arguments_1 = require("../validate-arguments");
|
|
11
|
+
const utils_1 = require("../utils");
|
|
7
12
|
const requiredOptions = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
definitionId: '--definition-id',
|
|
14
|
+
organizationId: '--organization-id',
|
|
15
|
+
bundleDir: '--bundle-dir',
|
|
16
|
+
token: '--token',
|
|
12
17
|
};
|
|
13
|
-
|
|
14
18
|
async function getUploadSettingsArgs(options) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
${
|
|
19
|
+
const validateSpinner = (0, ora_1.default)('Validating your input...').start();
|
|
20
|
+
const actionsManifest = (0, utils_1.getEntityFromManifest)('actions');
|
|
21
|
+
const deliveryFnManifest = (0, utils_1.getEntityFromManifest)('deliveryFunctions');
|
|
22
|
+
const { bundleDir, comment, skipActivation, host, userAgentApplication } = options;
|
|
23
|
+
try {
|
|
24
|
+
(0, validate_arguments_1.validateArguments)(requiredOptions, options, 'upload');
|
|
25
|
+
const appInfo = await (0, get_app_info_1.getAppInfo)(options);
|
|
26
|
+
return {
|
|
27
|
+
...appInfo,
|
|
28
|
+
bundleDirectory: bundleDir,
|
|
29
|
+
skipActivation,
|
|
30
|
+
comment,
|
|
31
|
+
host,
|
|
32
|
+
userAgentApplication,
|
|
33
|
+
actions: actionsManifest,
|
|
34
|
+
deliveryFunctions: deliveryFnManifest,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
console.log(`
|
|
39
|
+
${chalk_1.default.red('Validation failed!')}
|
|
36
40
|
${err.message}
|
|
37
41
|
`);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
// eslint-disable-next-line no-process-exit
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
validateSpinner.stop();
|
|
47
|
+
}
|
|
43
48
|
}
|
|
44
|
-
|
|
45
|
-
module.exports = {
|
|
46
|
-
getUploadSettingsArgs,
|
|
47
|
-
};
|
|
49
|
+
exports.getUploadSettingsArgs = getUploadSettingsArgs;
|
package/lib/upload/index.js
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.upload = void 0;
|
|
4
|
+
const activate_bundle_1 = require("../activate/activate-bundle");
|
|
5
|
+
const get_upload_settings_args_1 = require("./get-upload-settings-args");
|
|
6
|
+
const create_app_bundle_1 = require("./create-app-bundle");
|
|
7
|
+
const build_upload_settings_1 = require("./build-upload-settings");
|
|
7
8
|
async function uploadAndActivate(settings) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const bundle = await (0, create_app_bundle_1.createAppBundleFromSettings)(settings);
|
|
10
|
+
if (!settings.skipActivation && bundle) {
|
|
11
|
+
await (0, activate_bundle_1.activateBundle)({ ...settings, bundleId: bundle.sys.id });
|
|
12
|
+
}
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
async interactive(options) {
|
|
16
|
-
const settings = await buildAppUploadSettings(options);
|
|
14
|
+
const interactive = async (options) => {
|
|
15
|
+
const settings = await (0, build_upload_settings_1.buildAppUploadSettings)(options);
|
|
17
16
|
await uploadAndActivate(settings);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const settings = await getUploadSettingsArgs(options);
|
|
17
|
+
};
|
|
18
|
+
const nonInteractive = async (options) => {
|
|
19
|
+
const settings = await (0, get_upload_settings_args_1.getUploadSettingsArgs)(options);
|
|
21
20
|
await uploadAndActivate(settings);
|
|
22
|
-
|
|
21
|
+
};
|
|
22
|
+
exports.upload = {
|
|
23
|
+
interactive,
|
|
24
|
+
nonInteractive,
|
|
23
25
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const validateBundle: (path: string) => void;
|
|
@@ -1,37 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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.validateBundle = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
5
10
|
const ACCEPTED_ENTRY_FILES = ['index.html'];
|
|
6
|
-
const getEntryFile = files => files.find(file => ACCEPTED_ENTRY_FILES.includes(file));
|
|
7
|
-
|
|
11
|
+
const getEntryFile = (files) => files.find(file => ACCEPTED_ENTRY_FILES.includes(file));
|
|
8
12
|
const ABSOLUTE_PATH_REG_EXP = /(src|href)="\/([^/])([^"]*)+"/g;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return [...fileContent.matchAll(ABSOLUTE_PATH_REG_EXP)].length > 0;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const validateBundle = path => {
|
|
15
|
-
const buildFolder = Path.join('./', path);
|
|
16
|
-
const files = fs.readdirSync(buildFolder);
|
|
17
|
-
const entry = getEntryFile(files);
|
|
18
|
-
if (!entry) {
|
|
19
|
-
throw new Error('Make sure your bundle includes a valid index.html file in its root folder.');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const entryFile = fs.readFileSync(Path.join(buildFolder, entry), { encoding: 'utf8' });
|
|
23
|
-
|
|
24
|
-
if (fileContainsAbsolutePath(entryFile)) {
|
|
25
|
-
console.log('----------------------------');
|
|
26
|
-
console.warn(
|
|
27
|
-
`${chalk.red(
|
|
28
|
-
'Warning:'
|
|
29
|
-
)} This bundle uses absolute paths. Please use relative paths instead for correct rendering. See more details here https://www.contentful.com/developers/docs/extensibility/app-framework/app-bundle/#limitations`
|
|
30
|
-
);
|
|
31
|
-
console.log('----------------------------');
|
|
32
|
-
}
|
|
13
|
+
const fileContainsAbsolutePath = (fileContent) => {
|
|
14
|
+
return [...fileContent.matchAll(ABSOLUTE_PATH_REG_EXP)].length > 0;
|
|
33
15
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
16
|
+
const validateBundle = (path) => {
|
|
17
|
+
const buildFolder = path_1.default.join('./', path);
|
|
18
|
+
const files = fs_1.default.readdirSync(buildFolder);
|
|
19
|
+
const entry = getEntryFile(files);
|
|
20
|
+
if (!entry) {
|
|
21
|
+
throw new Error('Make sure your bundle includes a valid index.html file in its root folder.');
|
|
22
|
+
}
|
|
23
|
+
const entryFile = fs_1.default.readFileSync(path_1.default.join(buildFolder, entry), { encoding: 'utf8' });
|
|
24
|
+
if (fileContainsAbsolutePath(entryFile)) {
|
|
25
|
+
console.log('----------------------------');
|
|
26
|
+
console.warn(`${chalk_1.default.red('Warning:')} This bundle uses absolute paths. Please use relative paths instead for correct rendering. See more details here https://www.contentful.com/developers/docs/extensibility/app-framework/app-bundle/#limitations`);
|
|
27
|
+
console.log('----------------------------');
|
|
28
|
+
}
|
|
37
29
|
};
|
|
30
|
+
exports.validateBundle = validateBundle;
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Definition } from './definition-api';
|
|
2
|
+
import { Organization } from './organization-api';
|
|
3
|
+
import { DeliveryFunction, FunctionAppAction } from './types';
|
|
4
|
+
export declare const throwValidationException: (subject: string, message?: string, details?: string) => never;
|
|
5
|
+
export declare const isValidNetwork: (address: string) => boolean;
|
|
6
|
+
export declare const stripProtocol: (url: string) => string;
|
|
7
|
+
export declare const showCreationError: (subject: string, message: string) => void;
|
|
8
|
+
export declare const throwError: (err: Error, message: string) => never;
|
|
9
|
+
export declare const selectFromList: <T extends Definition | Organization>(list: T[], message: string, cachedOptionEnvVar: string) => Promise<T>;
|
|
10
|
+
type Entities<Type> = Type extends 'actions' ? Omit<FunctionAppAction, 'entryFile'>[] : Omit<DeliveryFunction, 'entryFile'>[];
|
|
11
|
+
export declare function getEntityFromManifest<Type extends 'actions' | 'deliveryFunctions'>(type: Type): Entities<Type> | undefined;
|
|
12
|
+
export {};
|
package/lib/utils.js
CHANGED
|
@@ -1,150 +1,116 @@
|
|
|
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.getEntityFromManifest = exports.selectFromList = exports.throwError = exports.showCreationError = exports.stripProtocol = exports.isValidNetwork = exports.throwValidationException = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
10
|
+
const cache_credential_1 = require("./cache-credential");
|
|
6
11
|
const DEFAULT_MANIFEST_PATH = './contentful-app-manifest.json';
|
|
7
|
-
|
|
8
12
|
const throwValidationException = (subject, message, details) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
throw new TypeError(message);
|
|
13
|
+
console.log(`${chalk_1.default.red('Validation Error:')} Missing or invalid ${subject}.`);
|
|
14
|
+
message && console.log(message);
|
|
15
|
+
details && console.log(`${chalk_1.default.dim(details)}`);
|
|
16
|
+
throw new TypeError(message);
|
|
14
17
|
};
|
|
15
|
-
|
|
18
|
+
exports.throwValidationException = throwValidationException;
|
|
16
19
|
const isValidNetwork = (address) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return addressRegex.test(address);
|
|
20
|
+
const addressRegex = /^(?:localhost|(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|(\[(?:[A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}\]|(?:[A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}))(?::\d{1,5})?$/;
|
|
21
|
+
return addressRegex.test(address);
|
|
20
22
|
};
|
|
21
|
-
|
|
23
|
+
exports.isValidNetwork = isValidNetwork;
|
|
22
24
|
const stripProtocol = (url) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return protocolRemovedUrl.split('/')[0];
|
|
25
|
+
const protocolRemovedUrl = url.replace(/^https?:\/\//, '');
|
|
26
|
+
return protocolRemovedUrl.split('/')[0];
|
|
26
27
|
};
|
|
27
|
-
|
|
28
|
+
exports.stripProtocol = stripProtocol;
|
|
28
29
|
const showCreationError = (subject, message) => {
|
|
29
|
-
|
|
30
|
-
${
|
|
30
|
+
console.log(`
|
|
31
|
+
${chalk_1.default.red('Creation error:')}
|
|
31
32
|
|
|
32
|
-
Something went wrong while creating the ${
|
|
33
|
+
Something went wrong while creating the ${chalk_1.default.bold(subject)}.
|
|
33
34
|
|
|
34
|
-
Message: ${
|
|
35
|
+
Message: ${chalk_1.default.red(message)}
|
|
35
36
|
`);
|
|
36
37
|
};
|
|
37
|
-
|
|
38
|
+
exports.showCreationError = showCreationError;
|
|
38
39
|
const logProgress = (message) => {
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
console.log('');
|
|
41
|
+
console.log(` ----------------------------
|
|
41
42
|
${message}
|
|
42
43
|
----------------------------`);
|
|
43
|
-
|
|
44
|
+
console.log('');
|
|
44
45
|
};
|
|
45
|
-
|
|
46
46
|
const throwError = (err, message) => {
|
|
47
|
-
|
|
48
|
-
${
|
|
47
|
+
console.log(`
|
|
48
|
+
${chalk_1.default.red('Error:')} ${message}.
|
|
49
49
|
|
|
50
50
|
${err.message}
|
|
51
51
|
`);
|
|
52
|
-
|
|
53
|
-
throw err;
|
|
52
|
+
throw err;
|
|
54
53
|
};
|
|
55
|
-
|
|
54
|
+
exports.throwError = throwError;
|
|
56
55
|
const selectFromList = async (list, message, cachedOptionEnvVar) => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
56
|
+
const cachedEnvVar = process.env[cachedOptionEnvVar];
|
|
57
|
+
const cachedElement = list.find((item) => item.value === cachedEnvVar);
|
|
58
|
+
if (cachedElement) {
|
|
59
|
+
logProgress(`${message}
|
|
60
|
+
Using environment variable: ${cachedElement.name} (${chalk_1.default.blue(cachedElement.value)})`);
|
|
61
|
+
return cachedElement;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const { elementId } = await inquirer_1.default.prompt([
|
|
65
|
+
{
|
|
66
|
+
name: 'elementId',
|
|
67
|
+
message: message,
|
|
68
|
+
type: 'list',
|
|
69
|
+
choices: list,
|
|
70
|
+
},
|
|
71
|
+
]);
|
|
72
|
+
if (cachedOptionEnvVar) {
|
|
73
|
+
await (0, cache_credential_1.cacheEnvVars)({ [cachedOptionEnvVar]: elementId });
|
|
74
|
+
}
|
|
75
|
+
return list.find((el) => el.value === elementId);
|
|
76
76
|
}
|
|
77
|
-
|
|
78
|
-
return list.find((el) => el.value === elementId);
|
|
79
|
-
}
|
|
80
77
|
};
|
|
81
|
-
|
|
78
|
+
exports.selectFromList = selectFromList;
|
|
82
79
|
function getEntityFromManifest(type) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
const manifest = JSON.parse(fs.readFileSync(DEFAULT_MANIFEST_PATH, { encoding: 'utf8' }));
|
|
91
|
-
|
|
92
|
-
if (!Array.isArray(manifest[type]) || manifest[type].length === 0) {
|
|
93
|
-
return;
|
|
80
|
+
const isManifestExists = fs_1.default.existsSync(DEFAULT_MANIFEST_PATH);
|
|
81
|
+
if (!isManifestExists) {
|
|
82
|
+
return;
|
|
94
83
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
item
|
|
114
|
-
|
|
115
|
-
|
|
84
|
+
try {
|
|
85
|
+
const manifest = JSON.parse(fs_1.default.readFileSync(DEFAULT_MANIFEST_PATH, { encoding: 'utf8' }));
|
|
86
|
+
if (!Array.isArray(manifest[type]) || manifest[type].length === 0) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
logProgress(`${type === 'actions' ? 'App Actions' : 'Delivery functions'} found in ${chalk_1.default.bold(DEFAULT_MANIFEST_PATH)}.`);
|
|
90
|
+
const items = manifest[type].map((item) => {
|
|
91
|
+
const allowNetworks = Array.isArray(item.allowNetworks)
|
|
92
|
+
? item.allowNetworks.map(exports.stripProtocol)
|
|
93
|
+
: [];
|
|
94
|
+
const hasInvalidNetwork = allowNetworks.find((netWork) => !(0, exports.isValidNetwork)(netWork));
|
|
95
|
+
if (hasInvalidNetwork) {
|
|
96
|
+
console.log(`${chalk_1.default.red('Error:')} Invalid IP address ${hasInvalidNetwork} found in the allowNetworks array for ${type} "${item.name}".`);
|
|
97
|
+
// eslint-disable-next-line no-process-exit
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
// EntryFile is not used but we do want to strip it
|
|
101
|
+
// eslint-disable-next-line no-unused-vars
|
|
102
|
+
const { entryFile: _, ...itemWithoutEntryFile } = item;
|
|
103
|
+
return {
|
|
104
|
+
...itemWithoutEntryFile,
|
|
105
|
+
allowNetworks,
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
return items;
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
console.log(`${chalk_1.default.red('Error:')} Invalid JSON in manifest file at ${chalk_1.default.bold(DEFAULT_MANIFEST_PATH)}.`);
|
|
116
112
|
// eslint-disable-next-line no-process-exit
|
|
117
113
|
process.exit(1);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
// EntryFile is not used but we do want to strip it from action
|
|
121
|
-
// eslint-disable-next-line no-unused-vars
|
|
122
|
-
const { entryFile: _, ...itemWithoutEntryFile } = item;
|
|
123
|
-
|
|
124
|
-
return {
|
|
125
|
-
...itemWithoutEntryFile,
|
|
126
|
-
allowNetworks,
|
|
127
|
-
};
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
return items;
|
|
131
|
-
} catch {
|
|
132
|
-
console.log(
|
|
133
|
-
`${chalk.red('Error:')} Invalid JSON in manifest file at ${chalk.bold(
|
|
134
|
-
DEFAULT_MANIFEST_PATH,
|
|
135
|
-
)}.`,
|
|
136
|
-
);
|
|
137
|
-
// eslint-disable-next-line no-process-exit
|
|
138
|
-
process.exit(1);
|
|
139
|
-
}
|
|
114
|
+
}
|
|
140
115
|
}
|
|
141
|
-
|
|
142
|
-
module.exports = {
|
|
143
|
-
throwValidationException,
|
|
144
|
-
throwError,
|
|
145
|
-
selectFromList,
|
|
146
|
-
showCreationError,
|
|
147
|
-
getEntityFromManifest,
|
|
148
|
-
isValidNetwork,
|
|
149
|
-
stripProtocol,
|
|
150
|
-
};
|
|
116
|
+
exports.getEntityFromManifest = getEntityFromManifest;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function validateArguments(requiredOptions: Record<string, string>, options: Record<string, any>, command?: string): void;
|
|
@@ -1,17 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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.validateArguments = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
3
8
|
function validateArguments(requiredOptions, options, command) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
Object.entries(requiredOptions).forEach(([option, argument]) => {
|
|
10
|
+
if (!options[option]) {
|
|
11
|
+
console.log(`
|
|
12
|
+
${chalk_1.default.red('Invalid Arguments:')} the argument ${chalk_1.default.cyan(argument)} was not defined.
|
|
13
|
+
`);
|
|
14
|
+
if (command) {
|
|
15
|
+
console.log(`
|
|
16
|
+
Run ${chalk_1.default.dim(`npx @contentful/app-scripts ${command} --help`)} to see all required arguments
|
|
17
|
+
`);
|
|
18
|
+
}
|
|
19
|
+
throw new Error('Invalid Arguments');
|
|
20
|
+
}
|
|
21
|
+
});
|
|
15
22
|
}
|
|
16
|
-
|
|
17
23
|
exports.validateArguments = validateArguments;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/app-scripts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "A collection of scripts for building Contentful Apps",
|
|
5
5
|
"author": "Contentful GmbH",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"npm": ">=6"
|
|
15
15
|
},
|
|
16
16
|
"main": "lib/index.js",
|
|
17
|
+
"types": "lib/index.d.ts",
|
|
17
18
|
"lint-staged": {
|
|
18
19
|
"*.js": [
|
|
19
20
|
"eslint --fix",
|
|
@@ -21,28 +22,26 @@
|
|
|
21
22
|
]
|
|
22
23
|
},
|
|
23
24
|
"bin": {
|
|
24
|
-
"contentful-app-scripts": "bin
|
|
25
|
+
"contentful-app-scripts": "lib/bin.js"
|
|
25
26
|
},
|
|
26
27
|
"scripts": {
|
|
27
28
|
"prettier": "prettier **/*.js --write --ignore-path .gitignore",
|
|
28
|
-
"lint": "eslint ./
|
|
29
|
+
"lint": "eslint ./src",
|
|
29
30
|
"lint:fix": "npm run lint -- --fix",
|
|
30
31
|
"test": "mocha \"./{,!(node_modules)/**/}*.test.js\" --exit",
|
|
31
32
|
"test:watch": "npm t -- --watch",
|
|
32
|
-
"pre-commit": "lint-staged"
|
|
33
|
+
"pre-commit": "lint-staged",
|
|
34
|
+
"build": "tsc"
|
|
33
35
|
},
|
|
34
36
|
"bugs": {
|
|
35
37
|
"url": "https://github.com/contentful/create-contentful-app/issues"
|
|
36
38
|
},
|
|
37
39
|
"homepage": "https://github.com/contentful/create-contentful-app#readme",
|
|
38
40
|
"directories": {
|
|
39
|
-
"lib": "lib"
|
|
40
|
-
"bin": "bin"
|
|
41
|
+
"lib": "lib"
|
|
41
42
|
},
|
|
42
43
|
"files": [
|
|
43
|
-
"lib"
|
|
44
|
-
"bin",
|
|
45
|
-
"utils"
|
|
44
|
+
"lib"
|
|
46
45
|
],
|
|
47
46
|
"publishConfig": {
|
|
48
47
|
"access": "public"
|
|
@@ -53,7 +52,7 @@
|
|
|
53
52
|
"bottleneck": "2.19.5",
|
|
54
53
|
"chalk": "4.1.2",
|
|
55
54
|
"commander": "11.0.0",
|
|
56
|
-
"contentful-management": "10.40.
|
|
55
|
+
"contentful-management": "10.40.1",
|
|
57
56
|
"dotenv": "16.3.1",
|
|
58
57
|
"ignore": "5.2.4",
|
|
59
58
|
"inquirer": "8.2.6",
|
|
@@ -61,5 +60,18 @@
|
|
|
61
60
|
"open": "8.4.2",
|
|
62
61
|
"ora": "5.4.1"
|
|
63
62
|
},
|
|
64
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "5a27e22426802834834960e7b43090bd269de505",
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@tsconfig/node14": "14.1.0",
|
|
66
|
+
"@types/adm-zip": "0.5.0",
|
|
67
|
+
"@types/analytics-node": "3.1.11",
|
|
68
|
+
"@types/inquirer": "8.2.1",
|
|
69
|
+
"@types/lodash": "4.14.197",
|
|
70
|
+
"@types/mocha": "10.0.1",
|
|
71
|
+
"@types/proxyquire": "1.3.28",
|
|
72
|
+
"@types/sinon": "10.0.16",
|
|
73
|
+
"proxyquire": "2.1.3",
|
|
74
|
+
"sinon": "15.2.0",
|
|
75
|
+
"ts-node": "10.9.1"
|
|
76
|
+
}
|
|
65
77
|
}
|