@jungvonmatt/contentful-fakes 1.4.0 → 1.4.8

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/CHANGELOG.md CHANGED
@@ -3,6 +3,42 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.4.8](https://github.com/jungvonmatt/contentful-ssg/compare/v1.4.7...v1.4.8) (2022-02-09)
7
+
8
+ **Note:** Version bump only for package @jungvonmatt/contentful-fakes
9
+
10
+
11
+
12
+
13
+
14
+ ## [1.4.5](https://github.com/jungvonmatt/contentful-ssg/compare/v1.4.4...v1.4.5) (2022-01-31)
15
+
16
+ **Note:** Version bump only for package @jungvonmatt/contentful-fakes
17
+
18
+
19
+
20
+
21
+
22
+ ## [1.4.2](https://github.com/jungvonmatt/contentful-ssg/compare/v1.4.1...v1.4.2) (2022-01-20)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * 🐛 Don't ask for delivery & preview token ([10a9a74](https://github.com/jungvonmatt/contentful-ssg/commit/10a9a74f24fecca9d8866d39e2ca9095e9a4d638))
28
+ * 🐛 lint ([22c8b38](https://github.com/jungvonmatt/contentful-ssg/commit/22c8b38fbe1f62e20a597545808181fc488d04c6))
29
+
30
+
31
+
32
+
33
+
34
+ ## [1.4.1](https://github.com/jungvonmatt/contentful-ssg/compare/v1.4.0...v1.4.1) (2022-01-20)
35
+
36
+ **Note:** Version bump only for package @jungvonmatt/contentful-fakes
37
+
38
+
39
+
40
+
41
+
6
42
  # [1.4.0](https://github.com/jungvonmatt/contentful-ssg/compare/v1.3.2...v1.4.0) (2022-01-19)
7
43
 
8
44
 
package/dist/cli.js CHANGED
@@ -1,22 +1,17 @@
1
1
  #!/usr/bin/env node
2
- import path from 'path';
3
- import { existsSync } from 'fs';
4
- import { outputFile } from 'fs-extra';
2
+ import { stringify } from '@jungvonmatt/contentful-ssg/converter';
3
+ import { forEachAsync } from '@jungvonmatt/contentful-ssg/lib/array';
4
+ import { confirm, logError } from '@jungvonmatt/contentful-ssg/lib/ui';
5
+ import chalk from 'chalk';
5
6
  import { Command } from 'commander';
6
7
  import dotenv from 'dotenv';
7
8
  import dotenvExpand from 'dotenv-expand';
8
- import { getConfig } from '@jungvonmatt/contentful-ssg/lib/config';
9
- import { forEachAsync } from '@jungvonmatt/contentful-ssg/lib/array';
10
- import { stringify } from '@jungvonmatt/contentful-ssg/converter';
11
- import { logError, askMissing, confirm } from '@jungvonmatt/contentful-ssg/lib/ui';
9
+ import { existsSync } from 'fs';
10
+ import { outputFile } from 'fs-extra';
11
+ import path from 'path';
12
12
  import { createFakes } from './index.js';
13
13
  const env = dotenv.config();
14
14
  dotenvExpand(env);
15
- const parseArgs = (cmd) => ({
16
- environment: cmd.env,
17
- verbose: Boolean(cmd.verbose),
18
- contentTypes: cmd.contentType,
19
- });
20
15
  const errorHandler = (error, silence) => {
21
16
  if (!silence) {
22
17
  const { errors } = error;
@@ -35,29 +30,32 @@ program
35
30
  .option('-c, --content-type <content-type...>', 'Specify content-types')
36
31
  .option('-e, --extension <extension>', 'Specify output format', 'yaml')
37
32
  .option('-o, --output-directory <directory>', 'Specify output directory', 'data')
38
- .option('-f, --force', 'Overwrite')
33
+ .option('--yes', 'Overwrite')
34
+ .option('--no', 'Skip')
39
35
  .action(actionRunner(async (cmd) => {
40
36
  const contentTypes = cmd?.contentType ?? [];
41
- const force = cmd?.force ?? false;
37
+ const yes = cmd?.yes ?? false;
38
+ const no = cmd?.no ?? false;
42
39
  const format = cmd?.extension ?? '';
43
40
  const outputDirectory = cmd?.outputDirectory ?? '';
44
- const config = await getConfig(parseArgs(cmd));
45
- const verified = await askMissing(config);
46
- const fakes = await createFakes(verified, contentTypes);
41
+ const fakes = await createFakes(contentTypes);
42
+ console.log();
43
+ if (!Object.keys(fakes).length) {
44
+ console.log('No files generated.');
45
+ console.log(`No content models found for: ${chalk.cyan(contentTypes.join(chalk.white(', ')))}`);
46
+ }
47
47
  await forEachAsync(Object.entries(fakes), async ([contentTypeId, fakeData]) => {
48
- const [defaultData, minData] = fakeData;
48
+ const [defaultData] = fakeData;
49
49
  const dir = path.join(outputDirectory, contentTypeId);
50
50
  const filenameDefault = path.join(dir, `default.${format}`);
51
- const filenameMin = path.join(dir, `min.${format}`);
52
- if (!existsSync(filenameDefault) ||
53
- force ||
51
+ if (existsSync(filenameDefault) && no) {
52
+ console.log(chalk.yellow(` skipped: ${filenameDefault}`));
53
+ }
54
+ else if (!existsSync(filenameDefault) ||
55
+ yes ||
54
56
  (await confirm(`Overwrite file: ${filenameDefault}`))) {
55
57
  await outputFile(filenameDefault, stringify(defaultData, format));
56
- }
57
- if (!existsSync(filenameMin) ||
58
- force ||
59
- (await confirm(`Overwrite file: ${filenameMin}`))) {
60
- await outputFile(filenameMin, stringify(minData, format));
58
+ console.log(chalk.green(` added: ${filenameDefault}`));
61
59
  }
62
60
  });
63
61
  }));
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { ContentfulConfig, KeyValueMap } from '@jungvonmatt/contentful-ssg';
2
- export declare function createFakes(config: ContentfulConfig, contentTypeIds: string[]): Promise<Record<string, KeyValueMap[]>>;
1
+ import { KeyValueMap } from '@jungvonmatt/contentful-ssg';
2
+ export declare function createFakes(contentTypeIds: string[]): Promise<Record<string, KeyValueMap[]>>;
package/dist/index.js CHANGED
@@ -1,7 +1,13 @@
1
1
  import { getEnvironment } from '@jungvonmatt/contentful-ssg/lib/contentful';
2
+ import { getConfig } from '@jungvonmatt/contentful-ssg/lib/config';
3
+ import { askMissing } from '@jungvonmatt/contentful-ssg/lib/ui';
2
4
  import { getMockData } from './lib/faker.js';
3
- export async function createFakes(config, contentTypeIds) {
4
- const environment = await getEnvironment(config);
5
+ export async function createFakes(contentTypeIds) {
6
+ const contentfulConfig = (await askMissing(await getConfig({
7
+ previewAccessToken: '-',
8
+ accessToken: '-',
9
+ })));
10
+ const environment = await getEnvironment(contentfulConfig);
5
11
  const { items: contentTypes } = await environment.getContentTypes();
6
12
  const { items } = await environment.getEditorInterfaces();
7
13
  const interfaces = Object.fromEntries(items
package/dist/lib/faker.js CHANGED
@@ -280,9 +280,9 @@ const getRichtextFake = async (field) => {
280
280
  const getArrayFake = async (field) => {
281
281
  const { validations } = field.settings;
282
282
  const { size } = validations.find((validation) => Boolean(validation?.size)) || {};
283
- let count = randomInt(0, 10);
283
+ let count = randomInt(0, 5);
284
284
  if (size) {
285
- count = randomInt(size?.min ?? 0, size?.max ?? (size?.min ?? 0) + 10);
285
+ count = randomInt(size?.min ?? 0, size?.max ?? (size?.min ?? 0) + 5);
286
286
  }
287
287
  if (field.settings.items.type === FIELD_TYPE_SYMBOL) {
288
288
  return Promise.all(Array(count)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jungvonmatt/contentful-fakes",
3
- "version": "1.4.0",
3
+ "version": "1.4.8",
4
4
  "description": "Create fake data based on contentful data models",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
@@ -35,8 +35,9 @@
35
35
  },
36
36
  "homepage": "https://github.com/jungvonmatt/contentful-ssg#readme",
37
37
  "dependencies": {
38
- "@jungvonmatt/contentful-ssg": "^1.4.0",
38
+ "@jungvonmatt/contentful-ssg": "^1.4.8",
39
39
  "casual": "^1.6.2",
40
+ "chalk": "^5.0.0",
40
41
  "faker": "^5.5.3",
41
42
  "fs-extra": "^10.0.0",
42
43
  "randexp": "^0.5.3"
@@ -45,5 +46,5 @@
45
46
  "@types/chance": "^1.1.3",
46
47
  "@types/faker": "^6.6.9"
47
48
  },
48
- "gitHead": "0d323f9884ae8fa48049e25bcd127954ee7988b8"
49
+ "gitHead": "28da6d98d1ba37a9bbaf6f1b22157c226be6d477"
49
50
  }
package/src/cli.ts CHANGED
@@ -1,17 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  /* eslint-env node */
4
- import path from 'path';
5
- import { existsSync } from 'fs';
6
- import { outputFile } from 'fs-extra';
4
+ import { stringify } from '@jungvonmatt/contentful-ssg/converter';
5
+ import { forEachAsync } from '@jungvonmatt/contentful-ssg/lib/array';
6
+ import { confirm, logError } from '@jungvonmatt/contentful-ssg/lib/ui';
7
+ import chalk from 'chalk';
7
8
  import { Command } from 'commander';
8
9
  import dotenv from 'dotenv';
9
10
  import dotenvExpand from 'dotenv-expand';
10
- import { ContentfulConfig } from '@jungvonmatt/contentful-ssg';
11
- import { getConfig } from '@jungvonmatt/contentful-ssg/lib/config';
12
- import { forEachAsync } from '@jungvonmatt/contentful-ssg/lib/array';
13
- import { stringify } from '@jungvonmatt/contentful-ssg/converter';
14
- import { logError, askMissing, confirm } from '@jungvonmatt/contentful-ssg/lib/ui';
11
+ import { existsSync } from 'fs';
12
+ import { outputFile } from 'fs-extra';
13
+ import path from 'path';
15
14
  import { createFakes } from './index.js';
16
15
 
17
16
  const env = dotenv.config();
@@ -23,15 +22,10 @@ type CommandArgs = {
23
22
  contentType: string[];
24
23
  env: string;
25
24
  verbose: boolean;
26
- force: boolean;
25
+ yes: boolean;
26
+ no: boolean;
27
27
  };
28
28
 
29
- const parseArgs = (cmd: CommandArgs) => ({
30
- environment: cmd.env,
31
- verbose: Boolean(cmd.verbose),
32
- contentTypes: cmd.contentType,
33
- });
34
-
35
29
  type CommandError = Error & {
36
30
  errors?: Error[];
37
31
  };
@@ -60,35 +54,37 @@ program
60
54
  .option('-c, --content-type <content-type...>', 'Specify content-types')
61
55
  .option('-e, --extension <extension>', 'Specify output format', 'yaml')
62
56
  .option('-o, --output-directory <directory>', 'Specify output directory', 'data')
63
- .option('-f, --force', 'Overwrite')
57
+ .option('--yes', 'Overwrite')
58
+ .option('--no', 'Skip')
64
59
  .action(
65
60
  actionRunner(async (cmd: CommandArgs) => {
66
61
  const contentTypes: string[] = cmd?.contentType ?? [];
67
- const force: boolean = cmd?.force ?? false;
62
+ const yes: boolean = cmd?.yes ?? false;
63
+ const no: boolean = cmd?.no ?? false;
68
64
  const format: string = cmd?.extension ?? '';
69
65
  const outputDirectory: string = cmd?.outputDirectory ?? '';
70
- const config = await getConfig(parseArgs(cmd));
71
- const verified = await askMissing(config);
72
- const fakes = await createFakes(verified as ContentfulConfig, contentTypes);
66
+ const fakes = await createFakes(contentTypes);
67
+ console.log();
68
+ if (!Object.keys(fakes).length) {
69
+ console.log('No files generated.');
70
+ console.log(
71
+ `No content models found for: ${chalk.cyan(contentTypes.join(chalk.white(', ')))}`
72
+ );
73
+ }
74
+
73
75
  await forEachAsync(Object.entries(fakes), async ([contentTypeId, fakeData]) => {
74
- const [defaultData, minData] = fakeData;
76
+ const [defaultData] = fakeData;
75
77
  const dir = path.join(outputDirectory, contentTypeId);
76
78
  const filenameDefault = path.join(dir, `default.${format}`);
77
- const filenameMin = path.join(dir, `min.${format}`);
78
- if (
79
+ if (existsSync(filenameDefault) && no) {
80
+ console.log(chalk.yellow(` skipped: ${filenameDefault}`));
81
+ } else if (
79
82
  !existsSync(filenameDefault) ||
80
- force ||
83
+ yes ||
81
84
  (await confirm(`Overwrite file: ${filenameDefault}`))
82
85
  ) {
83
86
  await outputFile(filenameDefault, stringify(defaultData, format));
84
- }
85
-
86
- if (
87
- !existsSync(filenameMin) ||
88
- force ||
89
- (await confirm(`Overwrite file: ${filenameMin}`))
90
- ) {
91
- await outputFile(filenameMin, stringify(minData, format));
87
+ console.log(chalk.green(` added: ${filenameDefault}`));
92
88
  }
93
89
  });
94
90
  })
package/src/index.ts CHANGED
@@ -1,12 +1,19 @@
1
1
  import { ContentfulConfig, KeyValueMap } from '@jungvonmatt/contentful-ssg';
2
2
  import { getEnvironment } from '@jungvonmatt/contentful-ssg/lib/contentful';
3
+ import { getConfig } from '@jungvonmatt/contentful-ssg/lib/config';
4
+ import { askMissing } from '@jungvonmatt/contentful-ssg/lib/ui';
3
5
  import { getMockData, ContentTypes } from './lib/faker.js';
4
6
 
5
7
  export async function createFakes(
6
- config: ContentfulConfig,
7
8
  contentTypeIds: string[]
8
9
  ): Promise<Record<string, KeyValueMap[]>> {
9
- const environment = await getEnvironment(config);
10
+ const contentfulConfig = (await askMissing(
11
+ await getConfig({
12
+ previewAccessToken: '-',
13
+ accessToken: '-',
14
+ })
15
+ )) as ContentfulConfig;
16
+ const environment = await getEnvironment(contentfulConfig);
10
17
  const { items: contentTypes } = await environment.getContentTypes();
11
18
  const { items } = await environment.getEditorInterfaces();
12
19
 
package/src/lib/faker.ts CHANGED
@@ -391,9 +391,9 @@ const getRichtextFake = async (field: FieldInfo): Promise<KeyValueMap> => {
391
391
  const getArrayFake = async (field: FieldInfo): Promise<unknown[]> => {
392
392
  const { validations } = field.settings;
393
393
  const { size } = validations.find((validation) => Boolean(validation?.size)) || {};
394
- let count = randomInt(0, 10);
394
+ let count = randomInt(0, 5);
395
395
  if (size) {
396
- count = randomInt(size?.min ?? 0, size?.max ?? (size?.min ?? 0) + 10);
396
+ count = randomInt(size?.min ?? 0, size?.max ?? (size?.min ?? 0) + 5);
397
397
  }
398
398
 
399
399
  if (field.settings.items.type === FIELD_TYPE_SYMBOL) {