@bottlebooks/valid-values 10.28.3 → 10.29.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/CHANGELOG.md +6 -0
- package/package.json +4 -2
- package/scripts/exportValidValues.ts +104 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
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
|
+
# [10.29.0](https://github.com/bottlebooks/bottlebooks/compare/@bottlebooks/valid-values@10.28.3...@bottlebooks/valid-values@10.29.0) (2024-06-13)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- export ([2b33f1e](https://github.com/bottlebooks/bottlebooks/commit/2b33f1e099bc083d5226e558bc7bda9843458663))
|
|
11
|
+
|
|
6
12
|
## [10.28.3](https://github.com/bottlebooks/bottlebooks/compare/@bottlebooks/valid-values@10.28.2...@bottlebooks/valid-values@10.28.3) (2024-06-07)
|
|
7
13
|
|
|
8
14
|
### Bug Fixes
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@bottlebooks/valid-values",
|
|
3
3
|
"description": "The Bottlebooks lookup values, defined globally.",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "10.
|
|
5
|
+
"version": "10.29.0",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"prepare": "yarn build",
|
|
13
13
|
"prebuild": "npm run extract && npm run compile && yarn test run && tsc --build --clean",
|
|
14
14
|
"build-with-tsc": "tsc",
|
|
15
|
+
"exportValidValues": "ts-node --skipProject ./scripts/exportValidValues.ts",
|
|
15
16
|
"build": "tsc --emitDeclarationOnly && babel src --out-dir dist --extensions \".ts,.tsx\"",
|
|
16
17
|
"preview": "vite preview",
|
|
17
18
|
"extract": "NODE_ENV=test lingui extract",
|
|
@@ -27,6 +28,7 @@
|
|
|
27
28
|
"@typescript-eslint/parser": "^5.5.0",
|
|
28
29
|
"babel-plugin-macros": "^2.5.1",
|
|
29
30
|
"rollup-plugin-node-builtins": "^2.1.2",
|
|
31
|
+
"ts-node": "^10.9.1",
|
|
30
32
|
"typescript": "^4.9.5",
|
|
31
33
|
"vite": "^3.0.7",
|
|
32
34
|
"vite-plugin-babel-macros": "1.0.5"
|
|
@@ -34,5 +36,5 @@
|
|
|
34
36
|
"dependencies": {
|
|
35
37
|
"@lingui/core": "3.14.0"
|
|
36
38
|
},
|
|
37
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "63b19705db4efddac01c673be5345d2eeef8f445"
|
|
38
40
|
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import * as dotenv from 'dotenv';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import z from 'zod';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {{locale: string, property?: string}} param0
|
|
8
|
+
*/
|
|
9
|
+
async function exportValidValues({
|
|
10
|
+
locale,
|
|
11
|
+
property,
|
|
12
|
+
}: {
|
|
13
|
+
locale: string;
|
|
14
|
+
property: string;
|
|
15
|
+
}) {
|
|
16
|
+
const data = [...(await getStandardValueValues())];
|
|
17
|
+
|
|
18
|
+
const transposed = data[0].map((_, colIndex) =>
|
|
19
|
+
data.map((row) => row[colIndex])
|
|
20
|
+
);
|
|
21
|
+
const csv = transposed.map((row) => row.join('\t')).join('\n');
|
|
22
|
+
fs.writeFileSync(`./scripts/out/ingredients_${locale}_${property}.txt`, csv);
|
|
23
|
+
|
|
24
|
+
async function getStandardValueValues() {
|
|
25
|
+
dotenv.config({ path: './.env.development' });
|
|
26
|
+
const { default: fetch } = await import('node-fetch');
|
|
27
|
+
const response = await fetch('http://localhost:3000/graphql', {
|
|
28
|
+
method: 'POST',
|
|
29
|
+
body: JSON.stringify({
|
|
30
|
+
query: `{
|
|
31
|
+
# Prowein Workspace
|
|
32
|
+
workspace(workspaceId: "${process.env.WORKSPACE_ID}") {
|
|
33
|
+
eLabels {
|
|
34
|
+
validValues {
|
|
35
|
+
ingredient(includeDeprecatedValues: false, locale: ${locale}) {
|
|
36
|
+
key
|
|
37
|
+
label
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}`,
|
|
43
|
+
}),
|
|
44
|
+
headers: {
|
|
45
|
+
'Content-Type': 'application/json',
|
|
46
|
+
Authorization: 'Bearer ' + process.env.GRAPHQL_TOKEN,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
const result = await response.json();
|
|
50
|
+
const {
|
|
51
|
+
ingredient,
|
|
52
|
+
// designation,
|
|
53
|
+
// wineType,
|
|
54
|
+
// wineColor,
|
|
55
|
+
// varietyName,
|
|
56
|
+
// denomination,
|
|
57
|
+
// country,
|
|
58
|
+
} = schema.parse(result.data.workspace.eLabels.validValues);
|
|
59
|
+
|
|
60
|
+
const mapped = [
|
|
61
|
+
['Ingredients ' + locale.toUpperCase()].concat(
|
|
62
|
+
ingredient
|
|
63
|
+
.sort((a, b) => a.key.localeCompare(b.key))
|
|
64
|
+
.map(({ label, key }) => (property === 'label' ? label : key))
|
|
65
|
+
),
|
|
66
|
+
// ['Select variety name'].concat(
|
|
67
|
+
// varietyName.map(({ label }) => label).sort((a, b) => a.localeCompare(b))
|
|
68
|
+
// ),
|
|
69
|
+
// ['Select wine type'].concat(wineType.map(({ label }) => label)),
|
|
70
|
+
// ['Select wine style'].concat(designation.map(({ label }) => label)),
|
|
71
|
+
// ['Select country'].concat(
|
|
72
|
+
// country.map(({ label }) => label).sort((a, b) => a.localeCompare(b))
|
|
73
|
+
// ),
|
|
74
|
+
// ['Select denomination'].concat(denomination.map(({ label }) => label)),
|
|
75
|
+
// ['Select wine color'].concat(wineColor.map(({ label }) => label)),
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
return mapped;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
exportValidValues({ locale: 'en', property: 'key' });
|
|
83
|
+
exportValidValues({ locale: 'en', property: 'label' });
|
|
84
|
+
exportValidValues({ locale: 'es', property: 'label' });
|
|
85
|
+
exportValidValues({ locale: 'da', property: 'label' });
|
|
86
|
+
|
|
87
|
+
// Would be nice to get from GraphQL schema, but haven't set up codegen
|
|
88
|
+
const schema = z.object({
|
|
89
|
+
// denomination: z.array(
|
|
90
|
+
// z.object({
|
|
91
|
+
// key: z.string(),
|
|
92
|
+
// label: z.string(),
|
|
93
|
+
// countryCode: z.string(),
|
|
94
|
+
// regionCode: z.string().nullish(),
|
|
95
|
+
// subregionCode: z.string().nullish(),
|
|
96
|
+
// })
|
|
97
|
+
// ),
|
|
98
|
+
// wineType: z.array(z.object({ key: z.string(), label: z.string() })),
|
|
99
|
+
// wineColor: z.array(z.object({ key: z.string(), label: z.string() })),
|
|
100
|
+
// varietyName: z.array(z.object({ key: z.string(), label: z.string() })),
|
|
101
|
+
// country: z.array(z.object({ key: z.string(), label: z.string() })),
|
|
102
|
+
// designation: z.array(z.object({ key: z.string(), label: z.string() })),
|
|
103
|
+
ingredient: z.array(z.object({ key: z.string(), label: z.string() })),
|
|
104
|
+
});
|