@platformos/platformos-check-docs-updater 0.0.6 → 0.0.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 +16 -0
- package/data/manifest_platformos.json +5 -0
- package/data/platformos_system_translations.json +3 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/platformOSLiquidDocsDownloader.d.ts +14 -0
- package/dist/platformOSLiquidDocsDownloader.js +100 -0
- package/dist/platformOSLiquidDocsDownloader.js.map +1 -0
- package/dist/platformOSLiquidDocsManager.d.ts +26 -0
- package/dist/platformOSLiquidDocsManager.js +139 -0
- package/dist/platformOSLiquidDocsManager.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -6
- package/scripts/cli.js +2 -2
- package/src/index.ts +3 -3
- package/src/platformOSLiquidDocsDownloader.ts +118 -0
- package/src/{themeLiquidDocsManager.spec.ts → platformOSLiquidDocsManager.spec.ts} +11 -24
- package/src/{themeLiquidDocsManager.ts → platformOSLiquidDocsManager.ts} +11 -84
- package/data/shopify_system_translations.json +0 -2461
- package/src/themeLiquidDocsDownloader.ts +0 -192
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { Mode } from '@platformos/platformos-check-common';
|
|
2
|
-
import envPaths from 'env-paths';
|
|
3
|
-
import fetch from 'node-fetch';
|
|
4
|
-
import fs from 'node:fs/promises';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { Logger, noop, tap } from './utils';
|
|
7
|
-
import he from 'he';
|
|
8
|
-
const paths = envPaths('theme-liquid-docs');
|
|
9
|
-
export const root = paths.cache;
|
|
10
|
-
|
|
11
|
-
export const ThemeLiquidDocsRootFallback =
|
|
12
|
-
'https://raw.githubusercontent.com/Shopify/theme-liquid-docs/main';
|
|
13
|
-
export const ThemeLiquidDocsRoot = 'https://documentation.platformos.com/api/liquid';
|
|
14
|
-
export const ThemeCustomSchemas = ['tags', 'latest', 'objects', 'filters'];
|
|
15
|
-
export const ThemeGraphQLSchema = 'https://documentation.platformos.com/api/graphql/schema';
|
|
16
|
-
|
|
17
|
-
export type Resource = (typeof Resources)[number];
|
|
18
|
-
export const Resources = [
|
|
19
|
-
'filters',
|
|
20
|
-
'objects',
|
|
21
|
-
'tags',
|
|
22
|
-
'shopify_system_translations',
|
|
23
|
-
'manifest_theme',
|
|
24
|
-
'manifest_theme_app_extension',
|
|
25
|
-
] as const;
|
|
26
|
-
|
|
27
|
-
export const Manifests = {
|
|
28
|
-
app: 'manifest_theme_app_extension',
|
|
29
|
-
theme: 'manifest_theme',
|
|
30
|
-
} as const satisfies Record<Mode, Resource>;
|
|
31
|
-
|
|
32
|
-
const THEME_LIQUID_DOCS: Record<Resource | 'latest', string> = {
|
|
33
|
-
filters: 'filters.json',
|
|
34
|
-
objects: 'objects.json',
|
|
35
|
-
tags: 'tags.json',
|
|
36
|
-
latest: 'latest.json',
|
|
37
|
-
shopify_system_translations: 'data/shopify_system_translations.json',
|
|
38
|
-
manifest_theme: 'schemas/manifest_theme.json',
|
|
39
|
-
manifest_theme_app_extension: 'schemas/manifest_theme_app_extension.json',
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export async function downloadSchema(
|
|
43
|
-
relativeUri: string,
|
|
44
|
-
destination: string = root,
|
|
45
|
-
log: Logger = noop,
|
|
46
|
-
) {
|
|
47
|
-
const remotePath = schemaUrl(relativeUri);
|
|
48
|
-
const localPath = schemaPath(relativeUri, destination);
|
|
49
|
-
const text = await download(remotePath, log);
|
|
50
|
-
await fs.writeFile(localPath, text, 'utf8');
|
|
51
|
-
return text;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export async function downloadResource(
|
|
55
|
-
resource: Resource | 'latest',
|
|
56
|
-
destination: string = root,
|
|
57
|
-
log: Logger = noop,
|
|
58
|
-
) {
|
|
59
|
-
const remotePath = resourceUrl(resource);
|
|
60
|
-
const localPath = resourcePath(resource, destination);
|
|
61
|
-
const text = await download(remotePath, log);
|
|
62
|
-
await fs.writeFile(localPath, text, 'utf8');
|
|
63
|
-
return text;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export async function downloadGraphQLSchema(destination: string = root, log: Logger = noop) {
|
|
67
|
-
const localPath = graphQLPath(destination);
|
|
68
|
-
const text = await download(ThemeGraphQLSchema, log);
|
|
69
|
-
await fs.writeFile(localPath, he.decode(text), 'utf8');
|
|
70
|
-
return text;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function graphQLPath(destination: string = root) {
|
|
74
|
-
return path.join(destination, `graphql.graphql`);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export async function download(path: string, log: Logger) {
|
|
78
|
-
if (path.startsWith('file:')) {
|
|
79
|
-
return await fs
|
|
80
|
-
.readFile(path.replace(/^file:/, ''), 'utf8')
|
|
81
|
-
.then(tap(() => log(`Using local file: ${path}`)))
|
|
82
|
-
.catch((error) => {
|
|
83
|
-
log(`Failed to read local file: ${path}`);
|
|
84
|
-
throw error;
|
|
85
|
-
});
|
|
86
|
-
} else {
|
|
87
|
-
log(path);
|
|
88
|
-
const res = await fetch(path);
|
|
89
|
-
return res.text();
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function resourcePath(resource: Resource | 'latest', destination: string = root) {
|
|
94
|
-
return path.join(destination, `${resource}.json`);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function resourceUrl(resource: Resource | 'latest') {
|
|
98
|
-
let resourceRoot = `${ThemeLiquidDocsRootFallback}`;
|
|
99
|
-
|
|
100
|
-
if (ThemeCustomSchemas.includes(resource)) {
|
|
101
|
-
resourceRoot = ThemeLiquidDocsRoot;
|
|
102
|
-
}
|
|
103
|
-
const relativePath = THEME_LIQUID_DOCS[resource];
|
|
104
|
-
return `${resourceRoot}/${relativePath}`;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function schemaPath(relativeUri: string, destination: string = root) {
|
|
108
|
-
return path.resolve(destination, path.basename(relativeUri));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export function schemaUrl(relativeUri: string) {
|
|
112
|
-
const schemaRoot = process.env.SHOPIFY_TLD_ROOT
|
|
113
|
-
? `file:${process.env.SHOPIFY_TLD_ROOT}`
|
|
114
|
-
: ThemeLiquidDocsRootFallback;
|
|
115
|
-
return `${schemaRoot}/schemas/${relativeUri}`;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export async function exists(path: string) {
|
|
119
|
-
try {
|
|
120
|
-
await fs.stat(path);
|
|
121
|
-
return true;
|
|
122
|
-
} catch (e) {
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export async function downloadThemeLiquidDocs(destination: string, log: Logger) {
|
|
128
|
-
if (!(await exists(destination))) {
|
|
129
|
-
await fs.mkdir(destination);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const resources = ['latest'].concat(Resources) as (Resource | 'latest')[];
|
|
133
|
-
const resourceContents = await Promise.all(
|
|
134
|
-
resources.map((file) => {
|
|
135
|
-
return downloadResource(file, destination, log)
|
|
136
|
-
.then(
|
|
137
|
-
tap(() =>
|
|
138
|
-
log(
|
|
139
|
-
`Successfully downloaded latest resource:\n\t${resourceUrl(file)}\n\t> ${resourcePath(
|
|
140
|
-
file,
|
|
141
|
-
destination,
|
|
142
|
-
)}`,
|
|
143
|
-
),
|
|
144
|
-
),
|
|
145
|
-
)
|
|
146
|
-
.catch((error) => {
|
|
147
|
-
log(
|
|
148
|
-
`Failed to download latest resource:\n\t${resourceUrl(file)} to\n\t${resourcePath(
|
|
149
|
-
file,
|
|
150
|
-
destination,
|
|
151
|
-
)}\n${error}`,
|
|
152
|
-
);
|
|
153
|
-
throw error;
|
|
154
|
-
});
|
|
155
|
-
}),
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
const manifests = Object.values(Manifests)
|
|
159
|
-
.map((resource) => resources.indexOf(resource))
|
|
160
|
-
.map((index) => resourceContents[index])
|
|
161
|
-
.map((manifest) => JSON.parse(manifest));
|
|
162
|
-
|
|
163
|
-
const relativeUris = manifests.flatMap((manifest) =>
|
|
164
|
-
manifest.schemas.map((schema: { uri: string }) => schema.uri),
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
await Promise.all(
|
|
168
|
-
unique(relativeUris).map((uri) =>
|
|
169
|
-
downloadSchema(uri, destination, log)
|
|
170
|
-
.then(
|
|
171
|
-
tap(() =>
|
|
172
|
-
log(
|
|
173
|
-
`Successfully downloaded schema:\n\t${schemaUrl(uri)}\n\t> ${schemaPath(
|
|
174
|
-
uri,
|
|
175
|
-
destination,
|
|
176
|
-
)}`,
|
|
177
|
-
),
|
|
178
|
-
),
|
|
179
|
-
)
|
|
180
|
-
.catch((error) => {
|
|
181
|
-
log(`Failed to download schema: ${uri}, ${error}`);
|
|
182
|
-
throw error;
|
|
183
|
-
}),
|
|
184
|
-
),
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
await downloadGraphQLSchema(destination, log);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function unique<T>(array: T[]): T[] {
|
|
191
|
-
return [...new Set(array).values()];
|
|
192
|
-
}
|