@contentful/app-scripts 1.12.0 → 1.13.1
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 +38 -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 +25 -13
- 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,129 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
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.cleanUpBundles = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const ora_1 = __importDefault(require("ora"));
|
|
9
|
+
const bottleneck_1 = __importDefault(require("bottleneck"));
|
|
10
|
+
const constants_1 = require("../constants");
|
|
11
|
+
const utils_1 = require("../utils");
|
|
12
|
+
const contentful_management_1 = require("contentful-management");
|
|
11
13
|
async function deleteBundle(bundleId, index, maxIndex, client, settings) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
console.log(`${chalk.green('Done:')} ${index + 1}/${maxIndex} bundles deleted successfully`);
|
|
14
|
+
const deleteSpinner = (0, ora_1.default)(`Deleting ${index + 1} out of ${maxIndex} bundles...`).start();
|
|
15
|
+
await client.appBundle.delete({
|
|
16
|
+
appBundleId: bundleId,
|
|
17
|
+
appDefinitionId: settings.definition.value,
|
|
18
|
+
organizationId: settings.organization.value,
|
|
19
|
+
});
|
|
20
|
+
deleteSpinner.stop();
|
|
21
|
+
console.log(`${chalk_1.default.green('Done:')} ${index + 1}/${maxIndex} bundles deleted successfully`);
|
|
21
22
|
}
|
|
22
|
-
|
|
23
23
|
const scheduleBundleDeletion = async (bundlesToDelete, client, settings) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
bundlesToDelete.map((bundle, index) =>
|
|
27
|
-
limiter.schedule(() =>
|
|
28
|
-
deleteBundle(bundle.sys.id, index, bundlesToDelete.length, client, settings)
|
|
29
|
-
)
|
|
30
|
-
)
|
|
31
|
-
);
|
|
24
|
+
const limiter = new bottleneck_1.default({ maxConcurrent: constants_1.MAX_CONCURRENT_DELETION_CALLS });
|
|
25
|
+
await Promise.all(bundlesToDelete.map((bundle, index) => limiter.schedule(() => deleteBundle(bundle.sys.id, index, bundlesToDelete.length, client, settings))));
|
|
32
26
|
};
|
|
33
|
-
|
|
34
27
|
async function cleanUpBundles(settings) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
limit,
|
|
51
|
-
skip,
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const getAppBundles = async (requestedAmount = DEFAULT_BUNDLES_TO_FETCH) => {
|
|
57
|
-
if (requestedAmount < 1) {
|
|
58
|
-
throw new Error('Requested amount of bundles to fetch must be greater than 0');
|
|
59
|
-
}
|
|
60
|
-
const getBundles = async (limit, skip) => {
|
|
61
|
-
const result = await fetchAppBundles(limit, skip);
|
|
62
|
-
const currLength = skip + result.items.length;
|
|
63
|
-
|
|
64
|
-
if (result.total > currLength) {
|
|
65
|
-
return [...result.items, ...(await getBundles(result.items.length, currLength))];
|
|
66
|
-
} else {
|
|
67
|
-
return result.items;
|
|
68
|
-
}
|
|
28
|
+
let definition;
|
|
29
|
+
let bundlesToDelete;
|
|
30
|
+
const client = (0, contentful_management_1.createClient)({
|
|
31
|
+
host: settings.host,
|
|
32
|
+
accessToken: settings.accessToken,
|
|
33
|
+
}, { type: 'plain' });
|
|
34
|
+
const fetchAppBundles = async (limit = constants_1.DEFAULT_BUNDLES_TO_FETCH, skip = 0) => {
|
|
35
|
+
return await client.appBundle.getMany({
|
|
36
|
+
appDefinitionId: settings.definition.value,
|
|
37
|
+
organizationId: settings.organization.value,
|
|
38
|
+
query: {
|
|
39
|
+
limit,
|
|
40
|
+
skip,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
69
43
|
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
44
|
+
const getAppBundles = async (requestedAmount = constants_1.DEFAULT_BUNDLES_TO_FETCH) => {
|
|
45
|
+
if (requestedAmount < 1) {
|
|
46
|
+
throw new Error('Requested amount of bundles to fetch must be greater than 0');
|
|
47
|
+
}
|
|
48
|
+
const getBundles = async (limit, skip = 0) => {
|
|
49
|
+
const result = await fetchAppBundles(limit, skip);
|
|
50
|
+
const currLength = skip + result.items.length;
|
|
51
|
+
if (result.total > currLength) {
|
|
52
|
+
return [...result.items, ...(await getBundles(result.items.length, currLength))];
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return result.items;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const all = await getBundles(constants_1.DEFAULT_BUNDLES_TO_FETCH, 0);
|
|
59
|
+
return all.reverse().slice(0, requestedAmount);
|
|
60
|
+
};
|
|
61
|
+
const getAppBundleCount = async () => {
|
|
62
|
+
return await fetchAppBundles(1, 0);
|
|
63
|
+
};
|
|
64
|
+
const bundlesSpinner = (0, ora_1.default)(`Fetching all bundles...`).start();
|
|
65
|
+
try {
|
|
66
|
+
const { total } = await getAppBundleCount();
|
|
67
|
+
const amountToDelete = total - settings.keep;
|
|
68
|
+
if (amountToDelete < 1) {
|
|
69
|
+
console.log(`${chalk_1.default.yellow('Warning:')} There is nothing to delete`);
|
|
70
|
+
bundlesSpinner.stop();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
bundlesToDelete = await getAppBundles(amountToDelete);
|
|
74
|
+
definition = await client.appDefinition.get({
|
|
75
|
+
appDefinitionId: settings.definition.value,
|
|
76
|
+
organizationId: settings.organization.value,
|
|
77
|
+
});
|
|
87
78
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (definition.bundle) {
|
|
100
|
-
bundlesToDelete = bundlesToDelete.filter(
|
|
101
|
-
(bundle) => bundle.sys.id !== definition.bundle.sys.id
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (bundlesToDelete.length < 1) {
|
|
106
|
-
console.log(`${chalk.yellow('Warning:')} There is nothing to delete`);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
console.log(`
|
|
79
|
+
catch (e) {
|
|
80
|
+
return (0, utils_1.throwError)(e, 'Something went wrong fetching the bundles');
|
|
81
|
+
}
|
|
82
|
+
bundlesSpinner.stop();
|
|
83
|
+
if (definition.bundle) {
|
|
84
|
+
bundlesToDelete = bundlesToDelete.filter((bundle) => bundle.sys.id !== definition.bundle.sys.id);
|
|
85
|
+
}
|
|
86
|
+
if (bundlesToDelete.length < 1) {
|
|
87
|
+
console.log(`${chalk_1.default.yellow('Warning:')} There is nothing to delete`);
|
|
88
|
+
}
|
|
89
|
+
console.log(`
|
|
110
90
|
|
|
111
|
-
${
|
|
112
|
-
bundlesToDelete.length > 1 ? 's' : ''
|
|
113
|
-
} will be deleted
|
|
91
|
+
${chalk_1.default.cyan('Info:')} ${bundlesToDelete.length} bundle${bundlesToDelete.length > 1 ? 's' : ''} will be deleted
|
|
114
92
|
|
|
115
93
|
`);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
throwError(e, 'Something went wrong deleting the bundles');
|
|
124
|
-
}
|
|
94
|
+
try {
|
|
95
|
+
await scheduleBundleDeletion(bundlesToDelete, client, settings);
|
|
96
|
+
console.log(`${chalk_1.default.green('Success:')} All ${bundlesToDelete.length} bundles are deleted successfully`);
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
return (0, utils_1.throwError)(e, 'Something went wrong deleting the bundles');
|
|
100
|
+
}
|
|
125
101
|
}
|
|
126
|
-
|
|
127
|
-
module.exports = {
|
|
128
|
-
cleanUpBundles,
|
|
129
|
-
};
|
|
102
|
+
exports.cleanUpBundles = cleanUpBundles;
|
|
@@ -1,38 +1,40 @@
|
|
|
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.getCleanUpSettingsArgs = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const ora_1 = __importDefault(require("ora"));
|
|
9
|
+
const constants_1 = require("../constants");
|
|
10
|
+
const validate_arguments_1 = require("../validate-arguments");
|
|
11
|
+
const get_app_info_1 = require("../get-app-info");
|
|
7
12
|
const requiredOptions = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
definitionId: '--definition-id',
|
|
14
|
+
organizationId: '--organization-id',
|
|
15
|
+
token: '--token',
|
|
11
16
|
};
|
|
12
|
-
|
|
13
17
|
async function getCleanUpSettingsArgs(options) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
${
|
|
18
|
+
const validateSpinner = (0, ora_1.default)('Validating your input...').start();
|
|
19
|
+
try {
|
|
20
|
+
(0, validate_arguments_1.validateArguments)(requiredOptions, options, 'upload');
|
|
21
|
+
const appInfo = await (0, get_app_info_1.getAppInfo)(options);
|
|
22
|
+
return {
|
|
23
|
+
...appInfo,
|
|
24
|
+
keep: options.keep !== undefined ? +options.keep : constants_1.DEFAULT_BUNDLES_TO_KEEP,
|
|
25
|
+
host: options.host,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
console.log(`
|
|
30
|
+
${chalk_1.default.red('Validation failed!')}
|
|
27
31
|
${err.message}
|
|
28
32
|
`);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
// eslint-disable-next-line no-process-exit
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
validateSpinner.stop();
|
|
38
|
+
}
|
|
34
39
|
}
|
|
35
|
-
|
|
36
|
-
module.exports = {
|
|
37
|
-
getCleanUpSettingsArgs,
|
|
38
|
-
};
|
|
40
|
+
exports.getCleanUpSettingsArgs = getCleanUpSettingsArgs;
|
package/lib/clean-up/index.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
await
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
await
|
|
13
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cleanup = void 0;
|
|
4
|
+
const get_clean_up_settings_1 = require("./get-clean-up-settings");
|
|
5
|
+
const build_clean_up_settings_1 = require("./build-clean-up-settings");
|
|
6
|
+
const clean_up_bundles_1 = require("./clean-up-bundles");
|
|
7
|
+
const interactive = async (options) => {
|
|
8
|
+
const settings = await (0, build_clean_up_settings_1.buildCleanUpSettings)(options);
|
|
9
|
+
await (0, clean_up_bundles_1.cleanUpBundles)(settings);
|
|
10
|
+
};
|
|
11
|
+
const nonInteractive = async (options) => {
|
|
12
|
+
const settings = await (0, get_clean_up_settings_1.getCleanUpSettingsArgs)(options);
|
|
13
|
+
await (0, clean_up_bundles_1.cleanUpBundles)(settings);
|
|
14
|
+
};
|
|
15
|
+
exports.cleanup = {
|
|
16
|
+
interactive,
|
|
17
|
+
nonInteractive,
|
|
14
18
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const DOTENV_FILE = ".env";
|
|
2
|
+
export declare const ACCESS_TOKEN_ENV_KEY = "CONTENTFUL_ACCESS_TOKEN";
|
|
3
|
+
export declare const ORG_ID_ENV_KEY = "CONTENTFUL_ORG_ID";
|
|
4
|
+
export declare const APP_DEF_ENV_KEY = "CONTENTFUL_APP_DEF_ID";
|
|
5
|
+
export declare const DEFAULT_BUNDLES_TO_KEEP = 50;
|
|
6
|
+
export declare const DEFAULT_BUNDLES_TO_FETCH = 1000;
|
|
7
|
+
export declare const MAX_CONCURRENT_DELETION_CALLS = 5;
|
|
8
|
+
export declare const DEFAULT_CONTENTFUL_API_HOST = "api.contentful.com";
|
package/lib/constants.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_CONTENTFUL_API_HOST = exports.MAX_CONCURRENT_DELETION_CALLS = exports.DEFAULT_BUNDLES_TO_FETCH = exports.DEFAULT_BUNDLES_TO_KEEP = exports.APP_DEF_ENV_KEY = exports.ORG_ID_ENV_KEY = exports.ACCESS_TOKEN_ENV_KEY = exports.DOTENV_FILE = void 0;
|
|
4
|
+
exports.DOTENV_FILE = '.env';
|
|
5
|
+
exports.ACCESS_TOKEN_ENV_KEY = 'CONTENTFUL_ACCESS_TOKEN';
|
|
6
|
+
exports.ORG_ID_ENV_KEY = 'CONTENTFUL_ORG_ID';
|
|
7
|
+
exports.APP_DEF_ENV_KEY = 'CONTENTFUL_APP_DEF_ID';
|
|
8
|
+
exports.DEFAULT_BUNDLES_TO_KEEP = 50;
|
|
9
|
+
exports.DEFAULT_BUNDLES_TO_FETCH = 1000;
|
|
10
|
+
exports.MAX_CONCURRENT_DELETION_CALLS = 5;
|
|
11
|
+
exports.DEFAULT_CONTENTFUL_API_HOST = 'api.contentful.com';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AppLocation, FieldType } from 'contentful-management';
|
|
2
|
+
export interface AppDefinitionSettings {
|
|
3
|
+
name: string;
|
|
4
|
+
locations: AppLocation['location'][];
|
|
5
|
+
fields?: FieldType[];
|
|
6
|
+
}
|
|
7
|
+
export declare function buildAppDefinitionSettings(): Promise<AppDefinitionSettings>;
|
|
@@ -1,84 +1,80 @@
|
|
|
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.buildAppDefinitionSettings = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
6
10
|
async function buildAppDefinitionSettings() {
|
|
7
|
-
|
|
8
|
-
chalk.dim(`
|
|
11
|
+
console.log(chalk_1.default.dim(`
|
|
9
12
|
NOTE: This will create an app definition in your Contentful organization.
|
|
10
|
-
- Read more about app definitions: ${
|
|
11
|
-
- Read more about app locations: ${
|
|
12
|
-
`)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const appDefinitionSettings = await inquirer.prompt([
|
|
16
|
-
{
|
|
17
|
-
name: 'name',
|
|
18
|
-
message: `App name (${path.basename(process.cwd())}):`,
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
name: 'locations',
|
|
22
|
-
message: `Select where your app can be rendered:`,
|
|
23
|
-
type: 'checkbox',
|
|
24
|
-
choices: [
|
|
25
|
-
{ name: 'App configuration screen ', value: 'app-config' },
|
|
26
|
-
{ name: 'Entry field', value: 'entry-field' },
|
|
27
|
-
{ name: 'Entry sidebar', value: 'entry-sidebar' },
|
|
28
|
-
{ name: 'Entry editor', value: 'entry-editor' },
|
|
29
|
-
{ name: 'Page', value: 'page' },
|
|
30
|
-
{ name: 'Home', value: 'home' },
|
|
31
|
-
],
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
name: 'fields',
|
|
35
|
-
message: 'Select the field types the app can be rendered:',
|
|
36
|
-
type: 'checkbox',
|
|
37
|
-
choices: [
|
|
38
|
-
{ name: 'Short text', value: { type: 'Symbol' } },
|
|
39
|
-
{ name: 'Short text, list', value: { type: 'Array', items: { type: 'Symbol' } } },
|
|
40
|
-
{ name: 'Long text', value: { type: 'Text' } },
|
|
41
|
-
{ name: 'Rich text', value: { type: 'RichText' } },
|
|
42
|
-
{ name: 'Number, integer', value: { type: 'Integer' } },
|
|
43
|
-
{ name: 'Number, decimal', value: { type: 'Number' } },
|
|
44
|
-
{ name: 'Date and time', value: { type: 'Date' } },
|
|
45
|
-
{ name: 'Location', value: { type: 'Location' } },
|
|
46
|
-
{ name: 'Boolean', value: { type: 'Boolean' } },
|
|
47
|
-
{ name: 'JSON object', value: { type: 'Object' } },
|
|
48
|
-
{ name: 'Entry reference', value: { type: 'Link', linkType: 'Entry' } },
|
|
13
|
+
- Read more about app definitions: ${chalk_1.default.underline('https://ctfl.io/app-definitions')}
|
|
14
|
+
- Read more about app locations: ${chalk_1.default.underline('https://ctfl.io/app-locations')}
|
|
15
|
+
`));
|
|
16
|
+
const appDefinitionSettings = await inquirer_1.default.prompt([
|
|
49
17
|
{
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
type: 'Array',
|
|
53
|
-
items: {
|
|
54
|
-
type: 'Link',
|
|
55
|
-
linkType: 'Entry',
|
|
56
|
-
},
|
|
57
|
-
},
|
|
18
|
+
name: 'name',
|
|
19
|
+
message: `App name (${path_1.default.basename(process.cwd())}):`,
|
|
58
20
|
},
|
|
59
|
-
{ name: 'Media reference', value: { type: 'Link', linkType: 'Asset' } },
|
|
60
21
|
{
|
|
61
|
-
|
|
62
|
-
|
|
22
|
+
name: 'locations',
|
|
23
|
+
message: `Select where your app can be rendered:`,
|
|
24
|
+
type: 'checkbox',
|
|
25
|
+
choices: [
|
|
26
|
+
{ name: 'App configuration screen ', value: 'app-config' },
|
|
27
|
+
{ name: 'Entry field', value: 'entry-field' },
|
|
28
|
+
{ name: 'Entry sidebar', value: 'entry-sidebar' },
|
|
29
|
+
{ name: 'Entry editor', value: 'entry-editor' },
|
|
30
|
+
{ name: 'Page', value: 'page' },
|
|
31
|
+
{ name: 'Home', value: 'home' },
|
|
32
|
+
],
|
|
63
33
|
},
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
34
|
+
{
|
|
35
|
+
name: 'fields',
|
|
36
|
+
message: 'Select the field types the app can be rendered:',
|
|
37
|
+
type: 'checkbox',
|
|
38
|
+
choices: [
|
|
39
|
+
{ name: 'Short text', value: { type: 'Symbol' } },
|
|
40
|
+
{ name: 'Short text, list', value: { type: 'Array', items: { type: 'Symbol' } } },
|
|
41
|
+
{ name: 'Long text', value: { type: 'Text' } },
|
|
42
|
+
{ name: 'Rich text', value: { type: 'RichText' } },
|
|
43
|
+
{ name: 'Number, integer', value: { type: 'Integer' } },
|
|
44
|
+
{ name: 'Number, decimal', value: { type: 'Number' } },
|
|
45
|
+
{ name: 'Date and time', value: { type: 'Date' } },
|
|
46
|
+
{ name: 'Location', value: { type: 'Location' } },
|
|
47
|
+
{ name: 'Boolean', value: { type: 'Boolean' } },
|
|
48
|
+
{ name: 'JSON object', value: { type: 'Object' } },
|
|
49
|
+
{ name: 'Entry reference', value: { type: 'Link', linkType: 'Entry' } },
|
|
50
|
+
{
|
|
51
|
+
name: 'Entry reference, list',
|
|
52
|
+
value: {
|
|
53
|
+
type: 'Array',
|
|
54
|
+
items: {
|
|
55
|
+
type: 'Link',
|
|
56
|
+
linkType: 'Entry',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
{ name: 'Media reference', value: { type: 'Link', linkType: 'Asset' } },
|
|
61
|
+
{
|
|
62
|
+
name: 'Media reference, list',
|
|
63
|
+
value: { type: 'Array', items: { type: 'Link', linkType: 'Asset' } },
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
when(answers) {
|
|
67
|
+
return answers.locations.includes('entry-field');
|
|
68
|
+
},
|
|
69
|
+
validate(answers) {
|
|
70
|
+
if (answers.length < 1) {
|
|
71
|
+
return 'You must choose at least one field type.';
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
]);
|
|
77
|
+
appDefinitionSettings.locations = ['dialog', ...appDefinitionSettings.locations];
|
|
78
|
+
return appDefinitionSettings;
|
|
80
79
|
}
|
|
81
|
-
|
|
82
|
-
module.exports = {
|
|
83
|
-
buildAppDefinitionSettings,
|
|
84
|
-
};
|
|
80
|
+
exports.buildAppDefinitionSettings = buildAppDefinitionSettings;
|