@jungvonmatt/contentful-fakes 1.4.0 → 1.4.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/CHANGELOG.md +8 -0
- package/dist/cli.js +29 -21
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -2
- package/package.json +3 -2
- package/src/cli.ts +32 -24
- package/src/index.ts +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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.1](https://github.com/jungvonmatt/contentful-ssg/compare/v1.4.0...v1.4.1) (2022-01-20)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @jungvonmatt/contentful-fakes
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [1.4.0](https://github.com/jungvonmatt/contentful-ssg/compare/v1.3.2...v1.4.0) (2022-01-19)
|
|
7
15
|
|
|
8
16
|
|
package/dist/cli.js
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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 {
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
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,42 @@ 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('
|
|
33
|
+
.option('--yes', 'Overwrite')
|
|
34
|
+
.option('--no', 'Skip')
|
|
39
35
|
.action(actionRunner(async (cmd) => {
|
|
40
36
|
const contentTypes = cmd?.contentType ?? [];
|
|
41
|
-
const
|
|
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
|
|
45
|
-
|
|
46
|
-
|
|
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
48
|
const [defaultData, minData] = fakeData;
|
|
49
49
|
const dir = path.join(outputDirectory, contentTypeId);
|
|
50
50
|
const filenameDefault = path.join(dir, `default.${format}`);
|
|
51
51
|
const filenameMin = path.join(dir, `min.${format}`);
|
|
52
|
-
if (
|
|
53
|
-
|
|
52
|
+
if (existsSync(filenameDefault) && no) {
|
|
53
|
+
console.log(chalk.yellow(` skipped: ${filenameDefault}`));
|
|
54
|
+
}
|
|
55
|
+
else if (!existsSync(filenameDefault) ||
|
|
56
|
+
yes ||
|
|
54
57
|
(await confirm(`Overwrite file: ${filenameDefault}`))) {
|
|
55
58
|
await outputFile(filenameDefault, stringify(defaultData, format));
|
|
59
|
+
console.log(chalk.green(` added: ${filenameDefault}`));
|
|
60
|
+
}
|
|
61
|
+
if (existsSync(filenameMin) && no) {
|
|
62
|
+
console.log(chalk.yellow(` skipped: ${filenameMin}`));
|
|
56
63
|
}
|
|
57
|
-
if (!existsSync(filenameMin) ||
|
|
58
|
-
|
|
64
|
+
else if (!existsSync(filenameMin) ||
|
|
65
|
+
yes ||
|
|
59
66
|
(await confirm(`Overwrite file: ${filenameMin}`))) {
|
|
60
67
|
await outputFile(filenameMin, stringify(minData, format));
|
|
68
|
+
console.log(chalk.green(` added: ${filenameMin}`));
|
|
61
69
|
}
|
|
62
70
|
});
|
|
63
71
|
}));
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function createFakes(
|
|
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,10 @@
|
|
|
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(
|
|
4
|
-
const
|
|
5
|
+
export async function createFakes(contentTypeIds) {
|
|
6
|
+
const contentfulConfig = (await askMissing(await getConfig({})));
|
|
7
|
+
const environment = await getEnvironment(contentfulConfig);
|
|
5
8
|
const { items: contentTypes } = await environment.getContentTypes();
|
|
6
9
|
const { items } = await environment.getEditorInterfaces();
|
|
7
10
|
const interfaces = Object.fromEntries(items
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jungvonmatt/contentful-fakes",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Create fake data based on contentful data models",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@jungvonmatt/contentful-ssg": "^1.4.0",
|
|
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": "
|
|
49
|
+
"gitHead": "22c8b38fbe1f62e20a597545808181fc488d04c6"
|
|
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
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
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 {
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
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
|
-
|
|
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,49 @@ 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('
|
|
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
|
|
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
|
|
71
|
-
|
|
72
|
-
|
|
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
76
|
const [defaultData, minData] = fakeData;
|
|
75
77
|
const dir = path.join(outputDirectory, contentTypeId);
|
|
76
78
|
const filenameDefault = path.join(dir, `default.${format}`);
|
|
77
79
|
const filenameMin = path.join(dir, `min.${format}`);
|
|
78
|
-
if (
|
|
80
|
+
if (existsSync(filenameDefault) && no) {
|
|
81
|
+
console.log(chalk.yellow(` skipped: ${filenameDefault}`));
|
|
82
|
+
} else if (
|
|
79
83
|
!existsSync(filenameDefault) ||
|
|
80
|
-
|
|
84
|
+
yes ||
|
|
81
85
|
(await confirm(`Overwrite file: ${filenameDefault}`))
|
|
82
86
|
) {
|
|
83
87
|
await outputFile(filenameDefault, stringify(defaultData, format));
|
|
88
|
+
console.log(chalk.green(` added: ${filenameDefault}`));
|
|
84
89
|
}
|
|
85
90
|
|
|
86
|
-
if (
|
|
91
|
+
if (existsSync(filenameMin) && no) {
|
|
92
|
+
console.log(chalk.yellow(` skipped: ${filenameMin}`));
|
|
93
|
+
} else if (
|
|
87
94
|
!existsSync(filenameMin) ||
|
|
88
|
-
|
|
95
|
+
yes ||
|
|
89
96
|
(await confirm(`Overwrite file: ${filenameMin}`))
|
|
90
97
|
) {
|
|
91
98
|
await outputFile(filenameMin, stringify(minData, format));
|
|
99
|
+
console.log(chalk.green(` added: ${filenameMin}`));
|
|
92
100
|
}
|
|
93
101
|
});
|
|
94
102
|
})
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
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
|
|
10
|
+
const contentfulConfig = (await askMissing(await getConfig({}))) as ContentfulConfig;
|
|
11
|
+
const environment = await getEnvironment(contentfulConfig);
|
|
10
12
|
const { items: contentTypes } = await environment.getContentTypes();
|
|
11
13
|
const { items } = await environment.getEditorInterfaces();
|
|
12
14
|
|