@lwrjs/shared-utils 0.10.0-alpha.12 → 0.10.0-alpha.13
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/build/cjs/fs.cjs +33 -1
- package/build/cjs/import-metadata.cjs +3 -2
- package/build/cjs/index.cjs +0 -1
- package/build/es/fs.d.ts +3 -0
- package/build/es/fs.js +31 -0
- package/build/es/identity.d.ts +1 -1
- package/build/es/import-metadata.js +3 -2
- package/build/es/index.d.ts +0 -1
- package/build/es/index.js +0 -1
- package/build/es/logger.d.ts +2 -2
- package/package.json +5 -5
- package/build/cjs/site-metadata.cjs +0 -121
- package/build/es/site-metadata.d.ts +0 -27
- package/build/es/site-metadata.js +0 -111
package/build/cjs/fs.cjs
CHANGED
|
@@ -32,7 +32,9 @@ __export(exports, {
|
|
|
32
32
|
normalizeDirectory: () => normalizeDirectory,
|
|
33
33
|
normalizeResourcePath: () => normalizeResourcePath,
|
|
34
34
|
readFile: () => readFile,
|
|
35
|
-
resolveFileExtension: () => resolveFileExtension
|
|
35
|
+
resolveFileExtension: () => resolveFileExtension,
|
|
36
|
+
streamToString: () => streamToString,
|
|
37
|
+
stringToStream: () => stringToStream
|
|
36
38
|
});
|
|
37
39
|
var import_fs = __toModule(require("fs"));
|
|
38
40
|
var import_path = __toModule(require("path"));
|
|
@@ -40,6 +42,7 @@ var import_crypto = __toModule(require("crypto"));
|
|
|
40
42
|
var import_identity = __toModule(require("./identity.cjs"));
|
|
41
43
|
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
42
44
|
var import_mime_types = __toModule(require("mime-types"));
|
|
45
|
+
var import_stream = __toModule(require("stream"));
|
|
43
46
|
var import_logger = __toModule(require("./logger.cjs"));
|
|
44
47
|
var fileCount = 0;
|
|
45
48
|
var files = new Map();
|
|
@@ -150,3 +153,32 @@ function normalizeAssetSpecifier(assetId, assetPathMap, resourcePaths, basePath)
|
|
|
150
153
|
}
|
|
151
154
|
return specifier;
|
|
152
155
|
}
|
|
156
|
+
function streamToString(stream, encoding = "utf8") {
|
|
157
|
+
const chunks = [];
|
|
158
|
+
return new Promise((resolve, reject) => {
|
|
159
|
+
stream.on("data", (c) => chunks.push(c));
|
|
160
|
+
stream.on("error", reject);
|
|
161
|
+
stream.on("end", () => resolve(Buffer.concat(chunks).toString(encoding)));
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
function stringToStream(str) {
|
|
165
|
+
let index = 0;
|
|
166
|
+
const isBuffer = Buffer.isBuffer(str);
|
|
167
|
+
const readable = new import_stream.Readable({
|
|
168
|
+
read(size) {
|
|
169
|
+
if (index >= str.length) {
|
|
170
|
+
this.push(null);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
let chunk;
|
|
174
|
+
if (isBuffer) {
|
|
175
|
+
chunk = str.subarray(index, index + size);
|
|
176
|
+
} else {
|
|
177
|
+
chunk = str.slice(index, index + size);
|
|
178
|
+
}
|
|
179
|
+
index += size;
|
|
180
|
+
this.push(chunk);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
return readable;
|
|
184
|
+
}
|
|
@@ -39,7 +39,8 @@ async function getImportMetadata(compiledSource) {
|
|
|
39
39
|
const [moduleImportLocations] = await (0, import_es_module_lexer.parse)(compiledSource);
|
|
40
40
|
for (const moduleImportLocation of moduleImportLocations) {
|
|
41
41
|
let moduleSpecifier = compiledSource.substring(moduleImportLocation.s, moduleImportLocation.e);
|
|
42
|
-
const
|
|
42
|
+
const isStatic = moduleImportLocation.d === -1;
|
|
43
|
+
const isDynamic = moduleImportLocation.d > -1;
|
|
43
44
|
const location = {
|
|
44
45
|
startColumn: moduleImportLocation.s,
|
|
45
46
|
endColumn: moduleImportLocation.e
|
|
@@ -57,7 +58,7 @@ async function getImportMetadata(compiledSource) {
|
|
|
57
58
|
endColumn: moduleImportLocation.s
|
|
58
59
|
}
|
|
59
60
|
});
|
|
60
|
-
} else {
|
|
61
|
+
} else if (isStatic) {
|
|
61
62
|
imports.push({moduleSpecifier, location});
|
|
62
63
|
}
|
|
63
64
|
}
|
package/build/cjs/index.cjs
CHANGED
|
@@ -34,4 +34,3 @@ __exportStar(exports, __toModule(require("./urls.cjs")));
|
|
|
34
34
|
__exportStar(exports, __toModule(require("./env.cjs")));
|
|
35
35
|
__exportStar(exports, __toModule(require("./logger.cjs")));
|
|
36
36
|
__exportStar(exports, __toModule(require("./lwr-app-observer.cjs")));
|
|
37
|
-
__exportStar(exports, __toModule(require("./site-metadata.cjs")));
|
package/build/es/fs.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { AssetIdentifier, ResourcePaths, ViewSource } from '@lwrjs/types';
|
|
3
3
|
import { lookup } from 'mime-types';
|
|
4
|
+
import { Readable } from 'stream';
|
|
4
5
|
/**
|
|
5
6
|
* Create a hash string for a source
|
|
6
7
|
* @param source
|
|
@@ -36,4 +37,6 @@ export { lookup as mimeLookup };
|
|
|
36
37
|
* Tries to convert any URL or $aliased path into a canonical fs path
|
|
37
38
|
*/
|
|
38
39
|
export declare function normalizeAssetSpecifier(assetId: AssetIdentifier, assetPathMap: Map<string, string>, resourcePaths: ResourcePaths, basePath: string): string;
|
|
40
|
+
export declare function streamToString(stream: Readable, encoding?: BufferEncoding): Promise<string>;
|
|
41
|
+
export declare function stringToStream(str: string | Buffer): Readable;
|
|
39
42
|
//# sourceMappingURL=fs.d.ts.map
|
package/build/es/fs.js
CHANGED
|
@@ -4,6 +4,7 @@ import crypto from 'crypto';
|
|
|
4
4
|
import { slugify } from './identity.js';
|
|
5
5
|
import { LwrUnresolvableError, createSingleDiagnosticError, descriptions } from '@lwrjs/diagnostics';
|
|
6
6
|
import { lookup } from 'mime-types';
|
|
7
|
+
import { Readable } from 'stream';
|
|
7
8
|
import { DEBUG, logger, VERBOSE } from './logger.js';
|
|
8
9
|
let fileCount = 0;
|
|
9
10
|
const files = new Map();
|
|
@@ -163,4 +164,34 @@ export function normalizeAssetSpecifier(assetId, assetPathMap, resourcePaths, ba
|
|
|
163
164
|
}
|
|
164
165
|
return specifier;
|
|
165
166
|
}
|
|
167
|
+
export function streamToString(stream, encoding = 'utf8') {
|
|
168
|
+
const chunks = [];
|
|
169
|
+
return new Promise((resolve, reject) => {
|
|
170
|
+
stream.on('data', (c) => chunks.push(c));
|
|
171
|
+
stream.on('error', reject);
|
|
172
|
+
stream.on('end', () => resolve(Buffer.concat(chunks).toString(encoding)));
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
export function stringToStream(str) {
|
|
176
|
+
let index = 0;
|
|
177
|
+
const isBuffer = Buffer.isBuffer(str);
|
|
178
|
+
const readable = new Readable({
|
|
179
|
+
read(size) {
|
|
180
|
+
if (index >= str.length) {
|
|
181
|
+
this.push(null);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
let chunk;
|
|
185
|
+
if (isBuffer) {
|
|
186
|
+
chunk = str.subarray(index, index + size);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
chunk = str.slice(index, index + size);
|
|
190
|
+
}
|
|
191
|
+
index += size;
|
|
192
|
+
this.push(chunk);
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
return readable;
|
|
196
|
+
}
|
|
166
197
|
//# sourceMappingURL=fs.js.map
|
package/build/es/identity.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare const DEFAULT_LWR_LOCKER_CONFIG: {
|
|
|
15
15
|
trustedComponents: string[];
|
|
16
16
|
};
|
|
17
17
|
export declare const DEFAULT_LWR_BOOTSTRAP_CONFIG: NormalizedLwrAppBootstrapConfig;
|
|
18
|
-
type ModuleIdentifierPartial = Partial<AbstractModuleId>;
|
|
18
|
+
declare type ModuleIdentifierPartial = Partial<AbstractModuleId>;
|
|
19
19
|
/**
|
|
20
20
|
* Turn the dots in a version into underscores
|
|
21
21
|
* @param version
|
|
@@ -12,7 +12,8 @@ export async function getImportMetadata(compiledSource) {
|
|
|
12
12
|
for (const moduleImportLocation of moduleImportLocations) {
|
|
13
13
|
// This will give us the source specifier of the import (ex. import x from "bar" <= will get us bar)
|
|
14
14
|
let moduleSpecifier = compiledSource.substring(moduleImportLocation.s, moduleImportLocation.e);
|
|
15
|
-
const
|
|
15
|
+
const isStatic = moduleImportLocation.d === -1;
|
|
16
|
+
const isDynamic = moduleImportLocation.d > -1;
|
|
16
17
|
const location = {
|
|
17
18
|
startColumn: moduleImportLocation.s,
|
|
18
19
|
endColumn: moduleImportLocation.e,
|
|
@@ -31,7 +32,7 @@ export async function getImportMetadata(compiledSource) {
|
|
|
31
32
|
},
|
|
32
33
|
});
|
|
33
34
|
}
|
|
34
|
-
else {
|
|
35
|
+
else if (isStatic) {
|
|
35
36
|
imports.push({ moduleSpecifier, location });
|
|
36
37
|
}
|
|
37
38
|
}
|
package/build/es/index.d.ts
CHANGED
package/build/es/index.js
CHANGED
package/build/es/logger.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
type LEVEL = 'verbose' | 'debug' | 'info' | 'warn' | 'error';
|
|
1
|
+
declare type LEVEL = 'verbose' | 'debug' | 'info' | 'warn' | 'error';
|
|
2
2
|
export declare const VERBOSE: LEVEL;
|
|
3
3
|
export declare const DEBUG: LEVEL;
|
|
4
4
|
export declare const INFO: LEVEL;
|
|
5
5
|
export declare const WARN: LEVEL;
|
|
6
6
|
export declare const ERROR: LEVEL;
|
|
7
|
-
type LoggerOptions = {
|
|
7
|
+
declare type LoggerOptions = {
|
|
8
8
|
dedupe?: Set<string>;
|
|
9
9
|
};
|
|
10
10
|
declare function log(level: string, message: string, additionalInfo?: any): void;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.10.0-alpha.
|
|
7
|
+
"version": "0.10.0-alpha.13",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -56,19 +56,19 @@
|
|
|
56
56
|
"slugify": "^1.4.5"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@locker/compiler": "0.19.
|
|
59
|
+
"@locker/compiler": "0.19.5",
|
|
60
60
|
"chokidar": "^3.5.3",
|
|
61
61
|
"esbuild": "^0.9.7",
|
|
62
62
|
"rollup": "^2.78.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@lwrjs/diagnostics": "0.10.0-alpha.
|
|
66
|
-
"@lwrjs/types": "0.10.0-alpha.
|
|
65
|
+
"@lwrjs/diagnostics": "0.10.0-alpha.13",
|
|
66
|
+
"@lwrjs/types": "0.10.0-alpha.13",
|
|
67
67
|
"@types/mime-types": "2.1.1",
|
|
68
68
|
"@types/path-to-regexp": "^1.7.0"
|
|
69
69
|
},
|
|
70
70
|
"engines": {
|
|
71
71
|
"node": ">=16.0.0 <20"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "f6d142d5a027554cb1685389e0b173734149683d"
|
|
74
74
|
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, {get: all[name], enumerable: true});
|
|
11
|
-
};
|
|
12
|
-
var __exportStar = (target, module2, desc) => {
|
|
13
|
-
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(module2))
|
|
15
|
-
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
-
__defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
|
|
17
|
-
}
|
|
18
|
-
return target;
|
|
19
|
-
};
|
|
20
|
-
var __toModule = (module2) => {
|
|
21
|
-
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// packages/@lwrjs/shared-utils/src/site-metadata.ts
|
|
25
|
-
__markAsModule(exports);
|
|
26
|
-
__export(exports, {
|
|
27
|
-
SiteMetadataImpl: () => SiteMetadataImpl
|
|
28
|
-
});
|
|
29
|
-
var import_path = __toModule(require("path"));
|
|
30
|
-
var import_fs_extra = __toModule(require("fs-extra"));
|
|
31
|
-
var import_logger = __toModule(require("./logger.cjs"));
|
|
32
|
-
var SITE_METADATA_PATH = ".metadata";
|
|
33
|
-
var STATIC_BUNDLE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/bundle-metadata.json");
|
|
34
|
-
var STATIC_RESOURCE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/resource-metadata.json");
|
|
35
|
-
var STATIC_ASSET_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/asset-metadata.json");
|
|
36
|
-
var SiteMetadataImpl = class {
|
|
37
|
-
constructor(options) {
|
|
38
|
-
this.options = options;
|
|
39
|
-
this.siteBundles = this.readStaticBundleMetadata(options.rootDir);
|
|
40
|
-
this.siteResources = this.readStaticResourceMetadata(options.rootDir);
|
|
41
|
-
this.siteAssets = this.readStaticAssetsMetadata(options.rootDir);
|
|
42
|
-
}
|
|
43
|
-
getSiteRootDir() {
|
|
44
|
-
return this.options.rootDir;
|
|
45
|
-
}
|
|
46
|
-
getSiteBundles() {
|
|
47
|
-
return this.siteBundles;
|
|
48
|
-
}
|
|
49
|
-
getSiteResources() {
|
|
50
|
-
return this.siteResources;
|
|
51
|
-
}
|
|
52
|
-
getSiteAssets() {
|
|
53
|
-
return this.siteAssets;
|
|
54
|
-
}
|
|
55
|
-
async persistSiteMetadata() {
|
|
56
|
-
const siteMetadataPath = import_path.default.join(this.options.rootDir, SITE_METADATA_PATH);
|
|
57
|
-
try {
|
|
58
|
-
if (!await import_fs_extra.default.pathExists(siteMetadataPath)) {
|
|
59
|
-
await import_fs_extra.default.mkdir(siteMetadataPath, {recursive: true});
|
|
60
|
-
}
|
|
61
|
-
const bundleMetadataPath = import_path.default.join(this.options.rootDir, STATIC_BUNDLE_METADATA_PATH);
|
|
62
|
-
await import_fs_extra.default.writeJSON(bundleMetadataPath, this.siteBundles, {spaces: 2});
|
|
63
|
-
const resourceMetadataPath = import_path.default.join(this.options.rootDir, STATIC_RESOURCE_METADATA_PATH);
|
|
64
|
-
await import_fs_extra.default.writeJSON(resourceMetadataPath, this.siteResources, {spaces: 2});
|
|
65
|
-
const assetMetadataPath = import_path.default.join(this.options.rootDir, STATIC_ASSET_METADATA_PATH);
|
|
66
|
-
return import_fs_extra.default.writeJSON(assetMetadataPath, this.siteAssets, {spaces: 2});
|
|
67
|
-
} catch (err) {
|
|
68
|
-
console.error(`[SiteMetadata] Failed to save site metadata ${siteMetadataPath}`);
|
|
69
|
-
console.error(err);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
readStaticBundleMetadata(staticRoot) {
|
|
73
|
-
let bundleMetadataPath;
|
|
74
|
-
let siteBundles = {bundles: {}};
|
|
75
|
-
try {
|
|
76
|
-
bundleMetadataPath = import_path.default.join(staticRoot, STATIC_BUNDLE_METADATA_PATH);
|
|
77
|
-
const savedMetadata = import_fs_extra.default.readJSONSync(bundleMetadataPath);
|
|
78
|
-
siteBundles = savedMetadata;
|
|
79
|
-
} catch (error) {
|
|
80
|
-
if (error.code === "ENOENT") {
|
|
81
|
-
import_logger.logger.debug(`[SiteMetadata] Failed to load Static Bundle Metadata: ${bundleMetadataPath}`);
|
|
82
|
-
} else {
|
|
83
|
-
throw error;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return siteBundles;
|
|
87
|
-
}
|
|
88
|
-
readStaticResourceMetadata(staticRoot) {
|
|
89
|
-
let resourceMetadataPath;
|
|
90
|
-
let siteResources = {resources: {}};
|
|
91
|
-
try {
|
|
92
|
-
resourceMetadataPath = import_path.default.join(staticRoot, STATIC_RESOURCE_METADATA_PATH);
|
|
93
|
-
const savedMetadata = import_fs_extra.default.readJSONSync(resourceMetadataPath);
|
|
94
|
-
siteResources = savedMetadata;
|
|
95
|
-
} catch (error) {
|
|
96
|
-
if (error.code === "ENOENT") {
|
|
97
|
-
import_logger.logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${resourceMetadataPath}`);
|
|
98
|
-
} else {
|
|
99
|
-
throw error;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return siteResources;
|
|
103
|
-
}
|
|
104
|
-
readStaticAssetsMetadata(staticRoot) {
|
|
105
|
-
let assetMetadataPath;
|
|
106
|
-
let siteAssets = {
|
|
107
|
-
assets: {}
|
|
108
|
-
};
|
|
109
|
-
try {
|
|
110
|
-
assetMetadataPath = import_path.default.join(staticRoot, STATIC_ASSET_METADATA_PATH);
|
|
111
|
-
siteAssets = import_fs_extra.default.readJSONSync(assetMetadataPath);
|
|
112
|
-
} catch (error) {
|
|
113
|
-
if (error.code === "ENOENT") {
|
|
114
|
-
import_logger.logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${assetMetadataPath}`);
|
|
115
|
-
} else {
|
|
116
|
-
throw error;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return siteAssets;
|
|
120
|
-
}
|
|
121
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { SiteAssets, SiteBundles, SiteMetadata, SiteResources } from '@lwrjs/types';
|
|
2
|
-
type Options = {
|
|
3
|
-
rootDir: string;
|
|
4
|
-
};
|
|
5
|
-
export declare class SiteMetadataImpl implements SiteMetadata {
|
|
6
|
-
private options;
|
|
7
|
-
private siteBundles;
|
|
8
|
-
private siteResources;
|
|
9
|
-
private siteAssets;
|
|
10
|
-
constructor(options: Options);
|
|
11
|
-
getSiteRootDir(): string;
|
|
12
|
-
getSiteBundles(): SiteBundles;
|
|
13
|
-
getSiteResources(): SiteResources;
|
|
14
|
-
getSiteAssets(): SiteAssets;
|
|
15
|
-
persistSiteMetadata(): Promise<void>;
|
|
16
|
-
private readStaticBundleMetadata;
|
|
17
|
-
/**
|
|
18
|
-
* Read the metadata about the pre-built resources of the current site.
|
|
19
|
-
*/
|
|
20
|
-
private readStaticResourceMetadata;
|
|
21
|
-
/**
|
|
22
|
-
* Read the metadata about the pre-built assets of the current site.
|
|
23
|
-
*/
|
|
24
|
-
private readStaticAssetsMetadata;
|
|
25
|
-
}
|
|
26
|
-
export {};
|
|
27
|
-
//# sourceMappingURL=site-metadata.d.ts.map
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
|
-
import { logger } from './logger.js';
|
|
4
|
-
const SITE_METADATA_PATH = '.metadata';
|
|
5
|
-
const STATIC_BUNDLE_METADATA_PATH = path.join(SITE_METADATA_PATH, '/bundle-metadata.json');
|
|
6
|
-
const STATIC_RESOURCE_METADATA_PATH = path.join(SITE_METADATA_PATH, '/resource-metadata.json');
|
|
7
|
-
const STATIC_ASSET_METADATA_PATH = path.join(SITE_METADATA_PATH, '/asset-metadata.json');
|
|
8
|
-
export class SiteMetadataImpl {
|
|
9
|
-
constructor(options) {
|
|
10
|
-
this.options = options;
|
|
11
|
-
this.siteBundles = this.readStaticBundleMetadata(options.rootDir);
|
|
12
|
-
this.siteResources = this.readStaticResourceMetadata(options.rootDir);
|
|
13
|
-
this.siteAssets = this.readStaticAssetsMetadata(options.rootDir);
|
|
14
|
-
}
|
|
15
|
-
getSiteRootDir() {
|
|
16
|
-
return this.options.rootDir;
|
|
17
|
-
}
|
|
18
|
-
getSiteBundles() {
|
|
19
|
-
return this.siteBundles;
|
|
20
|
-
}
|
|
21
|
-
getSiteResources() {
|
|
22
|
-
return this.siteResources;
|
|
23
|
-
}
|
|
24
|
-
getSiteAssets() {
|
|
25
|
-
return this.siteAssets;
|
|
26
|
-
}
|
|
27
|
-
async persistSiteMetadata() {
|
|
28
|
-
// Create the metadata directory if if does not exist
|
|
29
|
-
const siteMetadataPath = path.join(this.options.rootDir, SITE_METADATA_PATH);
|
|
30
|
-
try {
|
|
31
|
-
if (!(await fs.pathExists(siteMetadataPath))) {
|
|
32
|
-
await fs.mkdir(siteMetadataPath, { recursive: true });
|
|
33
|
-
}
|
|
34
|
-
// Save Bundle Metadata
|
|
35
|
-
const bundleMetadataPath = path.join(this.options.rootDir, STATIC_BUNDLE_METADATA_PATH);
|
|
36
|
-
await fs.writeJSON(bundleMetadataPath, this.siteBundles, { spaces: 2 });
|
|
37
|
-
// Save Resource Metadata
|
|
38
|
-
const resourceMetadataPath = path.join(this.options.rootDir, STATIC_RESOURCE_METADATA_PATH);
|
|
39
|
-
await fs.writeJSON(resourceMetadataPath, this.siteResources, { spaces: 2 });
|
|
40
|
-
// Save Resource Metadata
|
|
41
|
-
const assetMetadataPath = path.join(this.options.rootDir, STATIC_ASSET_METADATA_PATH);
|
|
42
|
-
return fs.writeJSON(assetMetadataPath, this.siteAssets, { spaces: 2 });
|
|
43
|
-
}
|
|
44
|
-
catch (err) {
|
|
45
|
-
console.error(`[SiteMetadata] Failed to save site metadata ${siteMetadataPath}`);
|
|
46
|
-
console.error(err);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
readStaticBundleMetadata(staticRoot) {
|
|
50
|
-
let bundleMetadataPath;
|
|
51
|
-
let siteBundles = { bundles: {} };
|
|
52
|
-
try {
|
|
53
|
-
bundleMetadataPath = path.join(staticRoot, STATIC_BUNDLE_METADATA_PATH);
|
|
54
|
-
const savedMetadata = fs.readJSONSync(bundleMetadataPath);
|
|
55
|
-
siteBundles = savedMetadata;
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
if (error.code === 'ENOENT') {
|
|
59
|
-
logger.debug(`[SiteMetadata] Failed to load Static Bundle Metadata: ${bundleMetadataPath}`);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
throw error;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return siteBundles;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Read the metadata about the pre-built resources of the current site.
|
|
69
|
-
*/
|
|
70
|
-
readStaticResourceMetadata(staticRoot) {
|
|
71
|
-
let resourceMetadataPath;
|
|
72
|
-
let siteResources = { resources: {} };
|
|
73
|
-
try {
|
|
74
|
-
resourceMetadataPath = path.join(staticRoot, STATIC_RESOURCE_METADATA_PATH);
|
|
75
|
-
const savedMetadata = fs.readJSONSync(resourceMetadataPath);
|
|
76
|
-
siteResources = savedMetadata;
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
if (error.code === 'ENOENT') {
|
|
80
|
-
logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${resourceMetadataPath}`);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
throw error;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return siteResources;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Read the metadata about the pre-built assets of the current site.
|
|
90
|
-
*/
|
|
91
|
-
readStaticAssetsMetadata(staticRoot) {
|
|
92
|
-
let assetMetadataPath;
|
|
93
|
-
let siteAssets = {
|
|
94
|
-
assets: {},
|
|
95
|
-
};
|
|
96
|
-
try {
|
|
97
|
-
assetMetadataPath = path.join(staticRoot, STATIC_ASSET_METADATA_PATH);
|
|
98
|
-
siteAssets = fs.readJSONSync(assetMetadataPath);
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
if (error.code === 'ENOENT') {
|
|
102
|
-
logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${assetMetadataPath}`);
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
throw error;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return siteAssets;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
//# sourceMappingURL=site-metadata.js.map
|