@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
package/README.md CHANGED
@@ -109,7 +109,7 @@ When passing the `--ci` argument the command will fail when the required variabl
109
109
  | Argument | Description | Default value |
110
110
  | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | - |
111
111
  | `--bundle-dir` | The directory of your build folder (e.g.: `./build`) | |
112
- | `--organization-id` | The ID of your organisation | |
112
+ | `--organization-id` | The ID of your organization | |
113
113
  | `--definition-id` | The ID of the app to which to add the bundle | |
114
114
  | `--token` | A personal [access token](https://www.contentful.com/developers/docs/references/content-management-api/#/reference/personal-access-tokens) | |
115
115
  | `--skip-activation` | (optional) Boolean flag to skip the automatic activation of the `AppBundle` | `false` |
@@ -152,7 +152,7 @@ When passing the `--ci` argument adding all variables as arguments is required.
152
152
  | Argument | Description | Default value |
153
153
  | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | --- |
154
154
  | `--bundle-id` | The ID of the AppBundle you want to activate | |
155
- | `--organization-id` | The ID of your organisation | |
155
+ | `--organization-id` | The ID of your organization | |
156
156
  | `--definition-id` | The ID of the app to which to add the bundle | |
157
157
  | `--token` | A personal [access token](https://www.contentful.com/developers/docs/references/content-management-api/#/reference/personal-access-tokens) | |
158
158
  | `--host` | (optional) Contentful CMA-endpoint to use | `api.contentful.com` |
@@ -212,9 +212,9 @@ When passing the `--ci` argument adding all variables as arguments is required
212
212
 
213
213
  | Argument | Description | Default value |
214
214
  | ------------------- | -------------------------------------------- | -------------------- |
215
- | `--bundle-id` | The ID of the AppBundle you want to activate | |
216
- | `--organization-id` | The ID of your organisation | |
215
+ | `--organization-id` | The ID of your organization | |
217
216
  | `--definition-id` | The ID of the app to which to add the bundle | |
217
+ | `--token` | A personal [access token](https://www.contentful.com/developers/docs/references/content-management-api/#/reference/personal-access-tokens) | |
218
218
  | `--keep` | (optional) The amount of bundles to keep | `50` |
219
219
  | `--host` | (optional) Contentful CMA-endpoint to use | `api.contentful.com` |
220
220
 
@@ -0,0 +1,2 @@
1
+ import { ActivateSettings } from '../types';
2
+ export declare function activateBundle({ accessToken, organization, definition, bundleId, host, }: ActivateSettings): Promise<void>;
@@ -1,63 +1,50 @@
1
- const ora = require('ora');
2
- const chalk = require('chalk');
3
- const { throwError } = require('../utils');
4
- const { createClient } = require('contentful-management');
5
-
6
- async function activateBundle({ accessToken, organization, definition, bundleId, host }) {
7
- const activationSpinner = ora('Activating your bundle').start();
8
- const plainClient = createClient({ accessToken, host }, { type: 'plain' });
9
- const defaultLocations = [{ location: 'dialog' }];
10
-
11
- const currentDefinition = await plainClient.appDefinition.get({
12
- appDefinitionId: definition.value,
13
- organizationId: organization.value,
14
- });
15
-
16
- currentDefinition.bundle = {
17
- sys: {
18
- id: bundleId,
19
- linkType: 'AppBundle',
20
- type: 'Link',
21
- },
22
- };
23
- if (!currentDefinition.locations.length) {
24
- currentDefinition.locations = defaultLocations;
25
- }
26
- delete currentDefinition.src;
27
-
28
- try {
29
- await plainClient.appDefinition.update(
30
- {
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.activateBundle = void 0;
7
+ const ora_1 = __importDefault(require("ora"));
8
+ const chalk_1 = require("chalk");
9
+ const utils_1 = require("../utils");
10
+ const contentful_management_1 = require("contentful-management");
11
+ async function activateBundle({ accessToken, organization, definition, bundleId, host, }) {
12
+ const activationSpinner = (0, ora_1.default)('Activating your bundle').start();
13
+ const plainClient = (0, contentful_management_1.createClient)({ accessToken, host }, { type: 'plain' });
14
+ const defaultLocations = [{ location: 'dialog' }];
15
+ const currentDefinition = await plainClient.appDefinition.get({
31
16
  appDefinitionId: definition.value,
32
17
  organizationId: organization.value,
33
- },
34
- currentDefinition
35
- );
36
- } catch (err) {
37
- throwError(
38
- err,
39
- 'Something went wrong activating your bundle. Make sure you used the correct definition-id.'
40
- );
41
- } finally {
42
- activationSpinner.stop();
43
- }
44
-
45
- console.log(`
46
- ${chalk.cyan('Success!')} Your app bundle was activated for ${chalk.cyan(
47
- definition.name
48
- )} in ${chalk.bold(organization.name)}.
49
-
50
- Bundle Id: ${chalk.yellow(bundleId)}`);
51
- console.log(`
18
+ });
19
+ currentDefinition.bundle = {
20
+ sys: {
21
+ id: bundleId,
22
+ linkType: 'AppBundle',
23
+ type: 'Link',
24
+ },
25
+ };
26
+ if (!currentDefinition.locations?.length) {
27
+ currentDefinition.locations = defaultLocations;
28
+ }
29
+ delete currentDefinition.src;
30
+ try {
31
+ await plainClient.appDefinition.update({
32
+ appDefinitionId: definition.value,
33
+ organizationId: organization.value,
34
+ }, currentDefinition);
35
+ }
36
+ catch (err) {
37
+ (0, utils_1.throwError)(err, 'Something went wrong activating your bundle. Make sure you used the correct definition-id.');
38
+ }
39
+ finally {
40
+ activationSpinner.stop();
41
+ }
42
+ console.log(`
43
+ ${(0, chalk_1.cyan)('Success!')} Your app bundle was activated for ${(0, chalk_1.cyan)(definition.name)} in ${(0, chalk_1.bold)(organization.name)}.
44
+ Bundle Id: ${(0, chalk_1.yellow)(bundleId)}`);
45
+ console.log(`
52
46
  ----------------------------
53
-
54
- Ready to share your app with the world? Submit it to the Developer Showcase (${chalk.cyan(
55
- 'https://ctfl.io/dev-showcase'
56
- )}) or our Marketplace (${chalk.cyan('https://ctfl.io/submit-app')}).
57
-
47
+ Ready to share your app with the world? Submit it to the Developer Showcase (${(0, chalk_1.cyan)('https://ctfl.io/dev-showcase')}) or our Marketplace (${(0, chalk_1.cyan)('https://ctfl.io/submit-app')}).
58
48
  `);
59
49
  }
60
-
61
- module.exports = {
62
- activateBundle,
63
- };
50
+ exports.activateBundle = activateBundle;
@@ -0,0 +1,2 @@
1
+ import { ActivateOptions, ActivateSettings } from '../types';
2
+ export declare function buildBundleActivateSettings(options: ActivateOptions): Promise<ActivateSettings>;
@@ -1,37 +1,35 @@
1
- // @ts-check
2
-
3
- const inquirer = require('inquirer');
4
- const { getAppInfo } = require('../get-app-info');
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.buildBundleActivateSettings = void 0;
7
+ const inquirer_1 = __importDefault(require("inquirer"));
8
+ const get_app_info_1 = require("../get-app-info");
6
9
  async function buildBundleActivateSettings(options) {
7
- const { bundleId, host } = options;
8
- const prompts = [];
9
-
10
- if (!bundleId) {
11
- prompts.push({
12
- name: 'bundleId',
13
- message: `The id of the bundle you want to activate (required):`,
14
- validate: (input) => input.length > 0,
15
- });
16
- }
17
- if (!host) {
18
- prompts.push({
19
- name: 'host',
20
- message: `Contentful CMA endpoint URL:`,
21
- default: 'api.contentful.com',
22
- });
23
- }
24
-
25
- const appActivateSettings = await inquirer.prompt(prompts);
26
- const appInfo = await getAppInfo(options);
27
-
28
- // Add app-config & dialog automatically
29
- return {
30
- bundleId,
31
- host,
32
- ...appActivateSettings,
33
- ...appInfo,
34
- };
10
+ const { bundleId, host } = options;
11
+ const prompts = [];
12
+ if (!bundleId) {
13
+ prompts.push({
14
+ name: 'bundleId',
15
+ message: `The id of the bundle you want to activate (required):`,
16
+ validate: (input) => input.length > 0,
17
+ });
18
+ }
19
+ if (!host) {
20
+ prompts.push({
21
+ name: 'host',
22
+ message: `Contentful CMA endpoint URL:`,
23
+ default: 'api.contentful.com',
24
+ });
25
+ }
26
+ const appActivateSettings = await inquirer_1.default.prompt(prompts);
27
+ const appInfo = await (0, get_app_info_1.getAppInfo)(options);
28
+ return {
29
+ bundleId,
30
+ host,
31
+ ...appActivateSettings,
32
+ ...appInfo,
33
+ };
35
34
  }
36
-
37
35
  exports.buildBundleActivateSettings = buildBundleActivateSettings;
@@ -0,0 +1,2 @@
1
+ import { ActivateOptions, ActivateSettings } from '../types';
2
+ export declare function getActivateSettingsArgs(options: ActivateOptions): Promise<ActivateSettings>;
@@ -1,37 +1,40 @@
1
- const chalk = require('chalk');
2
- const ora = require('ora');
3
- const { getAppInfo } = require('../get-app-info');
4
- const { validateArguments } = require('../validate-arguments');
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.getActivateSettingsArgs = 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");
6
11
  const requiredOptions = {
7
- definitionId: '--definition-id',
8
- organizationId: '--organization-id',
9
- bundleId: '--bundle-id',
10
- token: '--token',
12
+ organizationId: '--organization-id',
13
+ definitionId: '--definition-id',
14
+ bundleId: '--bundle-id',
15
+ token: '--token',
11
16
  };
12
-
13
17
  async function getActivateSettingsArgs(options) {
14
- const validateSpinner = ora('Validating your input').start();
15
-
16
- try {
17
- validateArguments(requiredOptions, options, 'activate');
18
- const appInfo = await getAppInfo(options);
19
- return {
20
- ...appInfo,
21
- bundleId: options.bundleId,
22
- comment: options.comment,
23
- host: options.host,
24
- };
25
- } catch (err) {
26
- console.log(`
27
- ${chalk.red('Validation failed')}
18
+ const validateSpinner = (0, ora_1.default)('Validating your input').start();
19
+ try {
20
+ (0, validate_arguments_1.validateArguments)(requiredOptions, options, 'activate');
21
+ const appInfo = await (0, get_app_info_1.getAppInfo)(options);
22
+ return {
23
+ ...appInfo,
24
+ bundleId: options.bundleId,
25
+ host: options.host,
26
+ };
27
+ }
28
+ catch (err) {
29
+ console.log(`
30
+ ${chalk_1.default.red('Validation failed')}
28
31
  ${err.message}
29
32
  `);
30
- // eslint-disable-next-line no-process-exit
31
- process.exit(1);
32
- } finally {
33
- validateSpinner.stop();
34
- }
33
+ // eslint-disable-next-line no-process-exit
34
+ process.exit(1);
35
+ }
36
+ finally {
37
+ validateSpinner.stop();
38
+ }
35
39
  }
36
-
37
40
  exports.getActivateSettingsArgs = getActivateSettingsArgs;
@@ -0,0 +1,5 @@
1
+ import { ActivateOptions } from '../types';
2
+ export declare const activate: {
3
+ interactive: (options: ActivateOptions) => Promise<void>;
4
+ nonInteractive: (options: ActivateOptions) => Promise<void>;
5
+ };
@@ -1,14 +1,18 @@
1
- const { activateBundle } = require('./activate-bundle');
2
- const { getActivateSettingsArgs } = require('./get-activate-args');
3
- const { buildBundleActivateSettings } = require('./build-bundle-activate-settings');
4
-
5
- module.exports = {
6
- async interactive(options) {
7
- const settings = await buildBundleActivateSettings(options);
8
- await activateBundle(settings);
9
- },
10
- async nonInteractive(options) {
11
- const settings = await getActivateSettingsArgs(options);
12
- await activateBundle(settings);
13
- },
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.activate = void 0;
4
+ const activate_bundle_1 = require("./activate-bundle");
5
+ const get_activate_args_1 = require("./get-activate-args");
6
+ const build_bundle_activate_settings_1 = require("./build-bundle-activate-settings");
7
+ const interactive = async (options) => {
8
+ const settings = await (0, build_bundle_activate_settings_1.buildBundleActivateSettings)(options);
9
+ await (0, activate_bundle_1.activateBundle)(settings);
10
+ };
11
+ const nonInteractive = async (options) => {
12
+ const settings = await (0, get_activate_args_1.getActivateSettingsArgs)(options);
13
+ await (0, activate_bundle_1.activateBundle)(settings);
14
+ };
15
+ exports.activate = {
16
+ interactive,
17
+ nonInteractive,
14
18
  };
@@ -0,0 +1,11 @@
1
+ /**
2
+ *
3
+ * @param {object} properties tracking properties
4
+ * @param {string} properties.command triggered command e.g create-app-definition, upload, etc.
5
+ * @param {boolean} properties.ci value if --ci flag has been set
6
+ * @returns
7
+ */
8
+ export declare function track({ command, ci }: {
9
+ command: string;
10
+ ci: boolean;
11
+ }): void;
@@ -0,0 +1,42 @@
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.track = void 0;
7
+ const analytics_node_1 = __importDefault(require("analytics-node"));
8
+ // Public write key scoped to data source
9
+ const SEGMENT_WRITE_KEY = 'IzCq3j4dQlTAgLdMykRW9oBHQKUy1xMm';
10
+ /**
11
+ *
12
+ * @param {object} properties tracking properties
13
+ * @param {string} properties.command triggered command e.g create-app-definition, upload, etc.
14
+ * @param {boolean} properties.ci value if --ci flag has been set
15
+ * @returns
16
+ */
17
+ function track({ command, ci }) {
18
+ if (process.env.DISABLE_ANALYTICS) {
19
+ return;
20
+ }
21
+ try {
22
+ const client = new analytics_node_1.default(SEGMENT_WRITE_KEY, {
23
+ errorHandler: () => {
24
+ // noop
25
+ },
26
+ });
27
+ client.track({
28
+ event: 'app-cli-app-scripts',
29
+ properties: {
30
+ command,
31
+ ci: String(ci),
32
+ },
33
+ anonymousId: Date.now(),
34
+ timestamp: new Date(),
35
+ });
36
+ // eslint-disable-next-line no-empty
37
+ }
38
+ catch (e) {
39
+ // ignore any error, to not block the call
40
+ }
41
+ }
42
+ exports.track = track;
package/lib/bin.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/lib/bin.js ADDED
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const commander_1 = require("commander");
5
+ const index_1 = require("./index");
6
+ async function runCommand(command, options) {
7
+ const { ci } = commander_1.program.opts();
8
+ return ci ? await command.nonInteractive(options) : await command.interactive(options);
9
+ }
10
+ (async function main() {
11
+ const version = process.env.npm_package_version ?? '';
12
+ commander_1.program.version(version).option('--ci', 'Execute in non-interactive mode', false);
13
+ commander_1.program
14
+ .command('create-app-definition')
15
+ .description('Create a new AppDefinition for an App')
16
+ .action(async () => {
17
+ await runCommand(index_1.createAppDefinition);
18
+ });
19
+ commander_1.program
20
+ .command('upload')
21
+ .description('Upload your build folder and create an AppBundle')
22
+ .option('--bundle-dir [directory]', 'The directory of your build folder')
23
+ .option('--organization-id [orgId]', 'The id of your organization')
24
+ .option('--definition-id [defId]', 'The id of your apps definition')
25
+ .option('--token [accessToken]', 'Your content management access token')
26
+ .option('--comment [comment]', 'Optional comment for the created bundle')
27
+ .option('--skip-activation', 'A Boolean flag to skip automatic activation')
28
+ .option('--host [host]', 'Contentful domain to use')
29
+ .action(async (options) => {
30
+ await runCommand(index_1.upload, options);
31
+ });
32
+ commander_1.program
33
+ .command('activate')
34
+ .description('Mark an AppBundle as "active" for a given AppDefinition')
35
+ .option('--bundle-id [bundleId]', 'The id of your bundle')
36
+ .option('--organization-id [orgId]', 'The id of your organization')
37
+ .option('--definition-id [defId]', 'The id of your apps definition')
38
+ .option('--token [accessToken]', 'Your content management access token')
39
+ .option('--host [host]', 'Contentful domain to use')
40
+ .action(async (options) => {
41
+ await runCommand(index_1.activate, options);
42
+ });
43
+ commander_1.program
44
+ .command('open-settings')
45
+ .description('Opens the app editor for a given AppDefinition')
46
+ .option('--definition-id [defId]', 'The id of your apps definition')
47
+ .action(async (options) => {
48
+ await runCommand(index_1.open, options);
49
+ });
50
+ commander_1.program
51
+ .command('bundle-cleanup')
52
+ .description('Removes old, non-active bundles, only keeps the 50 most recent ones')
53
+ .option('--organization-id [orgId]', 'The id of your organization')
54
+ .option('--definition-id [defId]', 'The id of your apps definition')
55
+ .option('--token [accessToken]', 'Your content management access token')
56
+ .option('--keep [keepAmount]', 'The amount of bundles that should remain')
57
+ .option('--host [host]', 'Contentful domain to use')
58
+ .action(async (options) => {
59
+ await runCommand(index_1.cleanup, options);
60
+ });
61
+ commander_1.program.hook('preAction', (thisCommand) => {
62
+ (0, index_1.track)({ command: thisCommand.args[0], ci: thisCommand.opts().ci });
63
+ });
64
+ await commander_1.program.parseAsync(process.argv);
65
+ })().catch((e) => {
66
+ console.error(e);
67
+ // eslint-disable-next-line no-process-exit
68
+ process.exit(1);
69
+ });
@@ -0,0 +1 @@
1
+ export declare function cacheEnvVars(envObj: Record<string, string>): Promise<void>;
@@ -0,0 +1,74 @@
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.cacheEnvVars = void 0;
7
+ const dotenv_1 = __importDefault(require("dotenv"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const os_1 = require("os");
10
+ const ignore_1 = __importDefault(require("ignore"));
11
+ const chalk_1 = __importDefault(require("chalk"));
12
+ const constants_1 = require("../constants");
13
+ const ig = (0, ignore_1.default)();
14
+ const fsPromises = fs_1.default.promises;
15
+ const fsConstants = fs_1.default.constants;
16
+ // Always export set env vars by default
17
+ dotenv_1.default.config();
18
+ async function removeOldEnv(envKey) {
19
+ const envFileData = await fsPromises.readFile(constants_1.DOTENV_FILE, { encoding: 'utf-8', });
20
+ const envVarsData = dotenv_1.default.parse(envFileData);
21
+ if (envVarsData[envKey]) {
22
+ delete envVarsData[envKey];
23
+ const stringifiedEnvData = Object.keys(envVarsData).map(key => `${key}=${envVarsData[key]}`).join(os_1.EOL);
24
+ await fsPromises.writeFile(constants_1.DOTENV_FILE, stringifiedEnvData, {
25
+ encoding: 'utf-8'
26
+ });
27
+ }
28
+ }
29
+ function addEnvFileToGitIgnore() {
30
+ try {
31
+ if (!ig.ignores(constants_1.DOTENV_FILE)) {
32
+ ig.add(constants_1.DOTENV_FILE);
33
+ }
34
+ }
35
+ catch (err) {
36
+ console.log(`${chalk_1.default.yellow('Warning: could not add .env file to .gitignore. Please don\'t forget to add it manually.')}`);
37
+ }
38
+ }
39
+ async function checkFileEnvExists() {
40
+ try {
41
+ await fsPromises.access(constants_1.DOTENV_FILE, fsConstants.F_OK);
42
+ return true;
43
+ }
44
+ catch (_) {
45
+ return false;
46
+ }
47
+ }
48
+ async function cacheEnvVars(envObj) {
49
+ try {
50
+ let envVars = '';
51
+ const envFileExists = await checkFileEnvExists();
52
+ for (const [key, val] of Object.entries(envObj)) {
53
+ if (envFileExists) {
54
+ await removeOldEnv(key);
55
+ }
56
+ envVars += `${os_1.EOL}${key}=${val}`;
57
+ }
58
+ await fsPromises.writeFile(constants_1.DOTENV_FILE, envVars, {
59
+ encoding: 'utf-8',
60
+ flag: 'a'
61
+ });
62
+ addEnvFileToGitIgnore();
63
+ console.log(`
64
+ Saved new Environment variable(s) locally: ${chalk_1.default.cyan(Object.keys(envObj).join(", "))}.
65
+ `);
66
+ }
67
+ catch (err) {
68
+ console.log(`
69
+ ${chalk_1.default.red('Couldn\'t save environment variables locally.')}
70
+ ${err.message}
71
+ `);
72
+ }
73
+ }
74
+ exports.cacheEnvVars = cacheEnvVars;
@@ -0,0 +1,2 @@
1
+ import { CleanupOptions, CleanupSettings } from '../types';
2
+ export declare function buildCleanUpSettings(options: CleanupOptions): Promise<CleanupSettings>;
@@ -1,38 +1,34 @@
1
- const inquirer = require('inquirer');
2
- const { DEFAULT_BUNDLES_TO_KEEP, CONTENTFUL_API_HOST } = require('../../utils/constants');
3
- const { getAppInfo } = require('../get-app-info');
4
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildCleanUpSettings = void 0;
4
+ const inquirer_1 = require("inquirer");
5
+ const constants_1 = require("../constants");
6
+ const get_app_info_1 = require("../get-app-info");
5
7
  async function buildCleanUpSettings(options) {
6
- const { keep, host } = options;
7
- const prompts = [];
8
-
9
- if (!keep) {
10
- prompts.push({
11
- type: 'number',
12
- name: 'keep',
13
- message: `The amount of newest bundles to keep:`,
14
- default: DEFAULT_BUNDLES_TO_KEEP,
15
- });
16
- }
17
- if (!host) {
18
- prompts.push({
19
- name: 'host',
20
- message: `Contentful CMA endpoint URL:`,
21
- default: CONTENTFUL_API_HOST,
22
- });
23
- }
24
-
25
- const appCleanUpSettings = await inquirer.prompt(prompts);
26
- const appInfo = await getAppInfo(options);
27
-
28
- return {
29
- keep: +keep,
30
- host,
31
- ...appCleanUpSettings,
32
- ...appInfo,
33
- };
8
+ const { keep, host } = options;
9
+ const prompts = [];
10
+ if (keep === undefined) {
11
+ prompts.push({
12
+ type: 'number',
13
+ name: 'keep',
14
+ message: `The amount of newest bundles to keep:`,
15
+ default: constants_1.DEFAULT_BUNDLES_TO_KEEP,
16
+ });
17
+ }
18
+ if (!host) {
19
+ prompts.push({
20
+ name: 'host',
21
+ message: `Contentful CMA endpoint URL:`,
22
+ default: constants_1.DEFAULT_CONTENTFUL_API_HOST,
23
+ });
24
+ }
25
+ const appCleanUpSettings = await (0, inquirer_1.prompt)(prompts);
26
+ const appInfo = await (0, get_app_info_1.getAppInfo)(options);
27
+ return {
28
+ keep: keep === undefined ? +appCleanUpSettings.keep : +keep,
29
+ host,
30
+ ...appCleanUpSettings,
31
+ ...appInfo,
32
+ };
34
33
  }
35
-
36
- module.exports = {
37
- buildCleanUpSettings,
38
- };
34
+ exports.buildCleanUpSettings = buildCleanUpSettings;
@@ -0,0 +1,2 @@
1
+ import { CleanupSettings } from '../types';
2
+ export declare function cleanUpBundles(settings: CleanupSettings): Promise<undefined>;