@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.
@@ -1,34 +1,25 @@
1
1
  import {
2
2
  FilterEntry,
3
3
  JsonValidationSet,
4
- Mode,
5
4
  ObjectEntry,
6
5
  SchemaDefinition,
7
6
  TagEntry,
8
- ThemeDocset,
9
- Translations,
7
+ PlatformOSDocset,
10
8
  } from '@platformos/platformos-check-common';
11
9
  import fs from 'node:fs/promises';
12
10
  import path from 'node:path';
13
11
  import {
14
- Manifests,
15
12
  Resource,
16
- ThemeCustomSchemas,
17
- ThemeLiquidDocsRoot,
18
- ThemeLiquidDocsRootFallback,
19
13
  downloadResource,
20
- downloadThemeLiquidDocs,
14
+ downloadPlatformOSLiquidDocs,
21
15
  exists,
22
16
  graphQLPath,
23
17
  resourcePath,
24
18
  root,
25
- schemaPath,
26
- } from './themeLiquidDocsDownloader';
27
- import { Logger, identity, memo, memoize, noop, tap } from './utils';
19
+ } from './platformOSLiquidDocsDownloader';
20
+ import { Logger, memo, noop, tap } from './utils';
28
21
 
29
- type JSONSchemaManifest = { schemas: { uri: string; fileMatch?: string[] }[] };
30
-
31
- export class ThemeLiquidDocsManager implements ThemeDocset, JsonValidationSet {
22
+ export class PlatformOSLiquidDocsManager implements PlatformOSDocset, JsonValidationSet {
32
23
  constructor(private log: Logger = noop) {}
33
24
 
34
25
  filters = memo(async (): Promise<FilterEntry[]> => {
@@ -48,54 +39,15 @@ export class ThemeLiquidDocsManager implements ThemeDocset, JsonValidationSet {
48
39
  });
49
40
 
50
41
  graphQL = memo(async (): Promise<string | null> => {
51
- return findSuitableResource(this.graphQLLoaders(), (x: string) => x, null, this.log);
42
+ return findSuitableResource(this.graphqlLoaders(), (x: string) => x, null, this.log);
52
43
  });
53
44
 
54
- systemTranslations = memo(async (): Promise<Translations> => {
55
- return findSuitableResource(
56
- this.loaders('shopify_system_translations'),
57
- JSON.parse,
58
- {},
59
- this.log,
60
- );
61
- });
62
-
63
- schemas = memoize(
64
- (mode: Mode) =>
65
- findSuitableResource<JSONSchemaManifest>(
66
- this.loaders(Manifests[mode]),
67
- JSON.parse,
68
- {
69
- schemas: [],
70
- },
71
- this.log,
72
- ).then((manifest) => {
73
- return Promise.all(
74
- manifest.schemas.map(async (schemaDefinition): Promise<SchemaDefinition> => {
75
- let schemaRoot = `${ThemeLiquidDocsRootFallback}/schemas`;
76
-
77
- if (ThemeCustomSchemas.includes(schemaDefinition.uri)) {
78
- schemaRoot = ThemeLiquidDocsRoot;
79
- }
80
- return {
81
- uri: `${schemaRoot}/${schemaDefinition.uri}`,
82
- fileMatch: schemaDefinition.fileMatch,
83
- schema: await findSuitableResource(
84
- this.schemaLoaders(schemaDefinition.uri),
85
- identity,
86
- '',
87
- this.log,
88
- ),
89
- };
90
- }),
91
- );
92
- }),
93
- identity<Mode>,
94
- );
45
+ // platformOS does not use JSON schemas for sections/blocks/settings.
46
+ schemas = memo(async (): Promise<SchemaDefinition[]> => []);
95
47
 
96
48
  /**
97
49
  * The setup method checks that the latest revision matches the one from
98
- * Shopify/theme-liquid-docs. If there's a diff in revision, it means
50
+ * the platformOS liquid docs. If there's a diff in revision, it means
99
51
  * that the documentations that you have locally are out of date.
100
52
  *
101
53
  * The setup method then downloads the other files.
@@ -110,7 +62,7 @@ export class ThemeLiquidDocsManager implements ThemeDocset, JsonValidationSet {
110
62
  await downloadResource('latest', root, this.log);
111
63
  const remote = await this.latestRevision();
112
64
  if (local !== remote) {
113
- await downloadThemeLiquidDocs(root, this.log);
65
+ await downloadPlatformOSLiquidDocs(root, this.log);
114
66
  }
115
67
  } catch (error) {
116
68
  if (error instanceof Error) {
@@ -141,12 +93,6 @@ export class ThemeLiquidDocsManager implements ThemeDocset, JsonValidationSet {
141
93
  return fs.readFile(resourcePath(name), 'utf8');
142
94
  }
143
95
 
144
- private async loadSchema(relativeUri: string) {
145
- return fs
146
- .readFile(schemaPath(relativeUri), 'utf8')
147
- .then(tap(() => this.log(`Loaded schema from ${schemaPath(relativeUri)}`)));
148
- }
149
-
150
96
  private async loadGraphQL() {
151
97
  return fs.readFile(graphQLPath(), 'utf8').then(tap(() => this.log(`Loaded graphQL`)));
152
98
  }
@@ -158,14 +104,7 @@ export class ThemeLiquidDocsManager implements ThemeDocset, JsonValidationSet {
158
104
  ];
159
105
  }
160
106
 
161
- private schemaLoaders(relativeUri: string): Loader<string>[] {
162
- return [
163
- loader(() => this.loadSchema(relativeUri), `loadSchema(${relativeUri})`),
164
- loader(() => fallbackSchema(relativeUri, this.log), `fallbackSchema(${relativeUri})`),
165
- ];
166
- }
167
-
168
- private graphQLLoaders(): Loader<string>[] {
107
+ private graphqlLoaders(): Loader<string>[] {
169
108
  return [
170
109
  loader(() => this.loadGraphQL(), `loadGraphQL()`),
171
110
  loader(() => fallbackGraphQL(this.log), `fallbackSchema()`),
@@ -235,18 +174,6 @@ async function fallbackResource(name: Resource, log: Logger): Promise<string> {
235
174
  .then(tap(() => log(`Loaded fallback resource\n\t${name} from\n\t${sourcePath}`)));
236
175
  }
237
176
 
238
- /** Returns the at-build-time path to the fallback schema file. */
239
- async function fallbackSchema(
240
- /** e.g. themes/section.json */
241
- relativeUri: string,
242
- log: Logger,
243
- ): Promise<string> {
244
- const sourcePath = path.resolve(dataRoot(), path.basename(relativeUri));
245
- return fs
246
- .readFile(sourcePath, 'utf8')
247
- .then(tap(() => log(`Loaded fallback schema\n\t${relativeUri} from\n\t${sourcePath}`)));
248
- }
249
-
250
177
  async function fallbackGraphQL(log: Logger): Promise<string> {
251
178
  const sourcePath = path.resolve(dataRoot(), `graphql.graphql`);
252
179
  return fs