@fgv/ts-res 5.0.0-21 → 5.0.0-23
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/README.md +794 -137
- package/dist/ts-res.d.ts +506 -33
- package/lib/packlets/common/convert.d.ts +10 -0
- package/lib/packlets/common/convert.js +11 -1
- package/lib/packlets/common/resources.d.ts +40 -1
- package/lib/packlets/common/validate/regularExpressions.d.ts +4 -0
- package/lib/packlets/common/validate/regularExpressions.js +5 -1
- package/lib/packlets/common/validate/resources.d.ts +35 -1
- package/lib/packlets/common/validate/resources.js +54 -0
- package/lib/packlets/config/convert.js +1 -1
- package/lib/packlets/config/json.d.ts +1 -1
- package/lib/packlets/qualifier-types/config/convert.d.ts +22 -1
- package/lib/packlets/qualifier-types/config/convert.js +67 -2
- package/lib/packlets/qualifier-types/config/json.d.ts +11 -2
- package/lib/packlets/qualifier-types/helpers.d.ts +1 -2
- package/lib/packlets/qualifier-types/languageQualifierType.d.ts +27 -1
- package/lib/packlets/qualifier-types/languageQualifierType.js +75 -0
- package/lib/packlets/qualifier-types/literalQualifierType.d.ts +30 -4
- package/lib/packlets/qualifier-types/literalQualifierType.js +77 -0
- package/lib/packlets/qualifier-types/literalValueHierarchy.d.ts +6 -10
- package/lib/packlets/qualifier-types/literalValueHierarchy.js +10 -0
- package/lib/packlets/qualifier-types/qualifierType.d.ts +28 -0
- package/lib/packlets/qualifier-types/territoryQualifierType.d.ts +28 -4
- package/lib/packlets/qualifier-types/territoryQualifierType.js +77 -0
- package/lib/packlets/resource-json/compiled/convert.js +2 -1
- package/lib/packlets/resource-json/compiled/json.d.ts +6 -2
- package/lib/packlets/resource-types/config/convert.js +3 -1
- package/lib/packlets/resource-types/config/json.d.ts +2 -0
- package/lib/packlets/resource-types/jsonResourceType.d.ts +10 -6
- package/lib/packlets/resource-types/jsonResourceType.js +7 -10
- package/lib/packlets/resource-types/resourceType.d.ts +20 -8
- package/lib/packlets/resource-types/resourceType.js +20 -16
- package/lib/packlets/resources/candidateValue.d.ts +92 -0
- package/lib/packlets/resources/candidateValue.js +128 -0
- package/lib/packlets/resources/candidateValueCollector.d.ts +55 -0
- package/lib/packlets/resources/candidateValueCollector.js +96 -0
- package/lib/packlets/resources/index.d.ts +2 -0
- package/lib/packlets/resources/index.js +2 -0
- package/lib/packlets/resources/resource.js +2 -2
- package/lib/packlets/resources/resourceBuilder.d.ts +6 -0
- package/lib/packlets/resources/resourceBuilder.js +3 -1
- package/lib/packlets/resources/resourceCandidate.d.ts +10 -1
- package/lib/packlets/resources/resourceCandidate.js +11 -5
- package/lib/packlets/resources/resourceManagerBuilder.d.ts +7 -0
- package/lib/packlets/resources/resourceManagerBuilder.js +13 -6
- package/lib/packlets/runtime/compiledResourceCollection.d.ts +20 -8
- package/lib/packlets/runtime/compiledResourceCollection.js +25 -4
- package/lib/packlets/runtime/resource-tree/common.d.ts +1 -1
- package/lib/packlets/runtime/resourceResolver.d.ts +39 -1
- package/lib/packlets/runtime/resourceResolver.js +45 -28
- package/lib/test/unit/qualifier-types/testQualifierType.d.ts +4 -0
- package/lib/test/unit/qualifier-types/testQualifierType.js +24 -0
- package/lib/test/unit/resource-types/derivedResourceType.test.d.ts +2 -0
- package/lib/test/unit/resource-types/testDerivedResourceType.d.ts +79 -0
- package/lib/test/unit/resource-types/testDerivedResourceType.js +113 -0
- package/lib/test/unit/resources/candidateValue.test.d.ts +2 -0
- package/lib/test/unit/resources/candidateValueCollector.test.d.ts +2 -0
- package/lib/test/unit/runtime/resourceResolver.coverage.test.d.ts +2 -0
- package/lib/test/unit/runtime/resourceResolver.newFeatures.test.d.ts +2 -0
- package/package.json +7 -7
- package/src/index.ts +0 -75
- package/src/packlets/bundle/bundleBuilder.ts +0 -159
- package/src/packlets/bundle/bundleLoader.ts +0 -157
- package/src/packlets/bundle/bundleNormalizer.ts +0 -173
- package/src/packlets/bundle/bundleUtils.ts +0 -142
- package/src/packlets/bundle/convert.ts +0 -87
- package/src/packlets/bundle/index.ts +0 -52
- package/src/packlets/bundle/model.ts +0 -138
- package/src/packlets/common/conditions.ts +0 -226
- package/src/packlets/common/convert.ts +0 -184
- package/src/packlets/common/helpers/conditions.ts +0 -84
- package/src/packlets/common/helpers/context.ts +0 -88
- package/src/packlets/common/helpers/index.ts +0 -26
- package/src/packlets/common/helpers/qualifierDefaultValues.ts +0 -91
- package/src/packlets/common/helpers/resources.ts +0 -96
- package/src/packlets/common/index.ts +0 -30
- package/src/packlets/common/resources.ts +0 -78
- package/src/packlets/common/validate/conditions.ts +0 -595
- package/src/packlets/common/validate/index.ts +0 -27
- package/src/packlets/common/validate/regularExpressions.ts +0 -92
- package/src/packlets/common/validate/resources.ts +0 -170
- package/src/packlets/conditions/condition.ts +0 -351
- package/src/packlets/conditions/conditionCollector.ts +0 -103
- package/src/packlets/conditions/conditionDecls.ts +0 -50
- package/src/packlets/conditions/conditionSet.ts +0 -318
- package/src/packlets/conditions/conditionSetCollector.ts +0 -127
- package/src/packlets/conditions/conditionSetDecls.ts +0 -41
- package/src/packlets/conditions/conditionToken.ts +0 -180
- package/src/packlets/conditions/convert/conditionSetDecls.ts +0 -72
- package/src/packlets/conditions/convert/decls.ts +0 -95
- package/src/packlets/conditions/convert/index.ts +0 -24
- package/src/packlets/conditions/index.ts +0 -33
- package/src/packlets/config/common.ts +0 -107
- package/src/packlets/config/configInitFactory.ts +0 -142
- package/src/packlets/config/convert.ts +0 -61
- package/src/packlets/config/index.ts +0 -30
- package/src/packlets/config/json.ts +0 -43
- package/src/packlets/config/predefined/default.ts +0 -150
- package/src/packlets/config/predefined/extended.ts +0 -198
- package/src/packlets/config/predefined/index.ts +0 -26
- package/src/packlets/config/systemConfiguration.ts +0 -217
- package/src/packlets/context/contextDecls.ts +0 -76
- package/src/packlets/context/contextToken.ts +0 -252
- package/src/packlets/context/convert/decls.ts +0 -126
- package/src/packlets/context/convert/index.ts +0 -23
- package/src/packlets/context/index.ts +0 -27
- package/src/packlets/decisions/abstractDecision.ts +0 -87
- package/src/packlets/decisions/abstractDecisionCollector.ts +0 -122
- package/src/packlets/decisions/candidate.ts +0 -101
- package/src/packlets/decisions/common.ts +0 -37
- package/src/packlets/decisions/concreteDecision.ts +0 -157
- package/src/packlets/decisions/decision.ts +0 -172
- package/src/packlets/decisions/index.ts +0 -28
- package/src/packlets/import/fsItem.ts +0 -212
- package/src/packlets/import/importContext.ts +0 -183
- package/src/packlets/import/importManager.ts +0 -187
- package/src/packlets/import/importable.ts +0 -107
- package/src/packlets/import/importers/collectionImporter.ts +0 -153
- package/src/packlets/import/importers/fsItemImporter.ts +0 -154
- package/src/packlets/import/importers/importer.ts +0 -58
- package/src/packlets/import/importers/index.ts +0 -27
- package/src/packlets/import/importers/jsonImporter.ts +0 -133
- package/src/packlets/import/importers/pathImporter.ts +0 -134
- package/src/packlets/import/index.ts +0 -29
- package/src/packlets/qualifier-types/config/convert.ts +0 -108
- package/src/packlets/qualifier-types/config/index.ts +0 -27
- package/src/packlets/qualifier-types/config/json.ts +0 -126
- package/src/packlets/qualifier-types/convert.ts +0 -77
- package/src/packlets/qualifier-types/helpers.ts +0 -94
- package/src/packlets/qualifier-types/index.ts +0 -34
- package/src/packlets/qualifier-types/languageQualifierType.ts +0 -143
- package/src/packlets/qualifier-types/literalQualifierType.ts +0 -244
- package/src/packlets/qualifier-types/literalValueHierarchy.ts +0 -332
- package/src/packlets/qualifier-types/qualifierType.ts +0 -360
- package/src/packlets/qualifier-types/qualifierTypeCollector.ts +0 -102
- package/src/packlets/qualifier-types/territoryQualifierType.ts +0 -255
- package/src/packlets/qualifiers/convert/decls.ts +0 -90
- package/src/packlets/qualifiers/convert/index.ts +0 -24
- package/src/packlets/qualifiers/convert/qualifier.ts +0 -55
- package/src/packlets/qualifiers/index.ts +0 -31
- package/src/packlets/qualifiers/qualifier.ts +0 -169
- package/src/packlets/qualifiers/qualifierCollector.ts +0 -194
- package/src/packlets/qualifiers/qualifierDecl.ts +0 -80
- package/src/packlets/qualifiers/qualifierDefaultValueDecls.ts +0 -57
- package/src/packlets/qualifiers/qualifierDefaultValueToken.ts +0 -230
- package/src/packlets/resource-json/compiled/common.ts +0 -35
- package/src/packlets/resource-json/compiled/convert.ts +0 -143
- package/src/packlets/resource-json/compiled/index.ts +0 -27
- package/src/packlets/resource-json/compiled/json.ts +0 -239
- package/src/packlets/resource-json/convert.ts +0 -236
- package/src/packlets/resource-json/helpers.ts +0 -284
- package/src/packlets/resource-json/index.ts +0 -33
- package/src/packlets/resource-json/json.ts +0 -295
- package/src/packlets/resource-json/normalized.ts +0 -211
- package/src/packlets/resource-json/resourceDeclCollection.ts +0 -117
- package/src/packlets/resource-json/resourceDeclContainer.ts +0 -48
- package/src/packlets/resource-json/resourceDeclTree.ts +0 -116
- package/src/packlets/resource-types/config/convert.ts +0 -36
- package/src/packlets/resource-types/config/index.ts +0 -27
- package/src/packlets/resource-types/config/json.ts +0 -30
- package/src/packlets/resource-types/helpers.ts +0 -44
- package/src/packlets/resource-types/index.ts +0 -30
- package/src/packlets/resource-types/jsonResourceType.ts +0 -104
- package/src/packlets/resource-types/resourceType.ts +0 -259
- package/src/packlets/resource-types/resourceTypeCollector.ts +0 -79
- package/src/packlets/resources/candidateReducer.ts +0 -331
- package/src/packlets/resources/common.ts +0 -114
- package/src/packlets/resources/index.ts +0 -28
- package/src/packlets/resources/resource.ts +0 -307
- package/src/packlets/resources/resourceBuilder.ts +0 -269
- package/src/packlets/resources/resourceCandidate.ts +0 -333
- package/src/packlets/resources/resourceManagerBuilder.ts +0 -1169
- package/src/packlets/runtime/cacheListener.ts +0 -113
- package/src/packlets/runtime/cacheMetrics.ts +0 -206
- package/src/packlets/runtime/compiledResourceCollection.ts +0 -607
- package/src/packlets/runtime/conditionSetResolutionResult.ts +0 -160
- package/src/packlets/runtime/context/contextQualifierProvider.ts +0 -117
- package/src/packlets/runtime/context/contextQualifierProviderValidator.ts +0 -281
- package/src/packlets/runtime/context/index.ts +0 -26
- package/src/packlets/runtime/context/simpleContextQualifierProvider.ts +0 -225
- package/src/packlets/runtime/context/validatingSimpleContextQualifierProvider.ts +0 -96
- package/src/packlets/runtime/iResourceManager.ts +0 -130
- package/src/packlets/runtime/index.ts +0 -35
- package/src/packlets/runtime/resource-tree/common.ts +0 -126
- package/src/packlets/runtime/resource-tree/index.ts +0 -26
- package/src/packlets/runtime/resource-tree/readOnlyResourceTree.ts +0 -342
- package/src/packlets/runtime/resource-tree/resourceTreeChildren.ts +0 -125
- package/src/packlets/runtime/resource-tree/resourceTreeChildrenValidator.ts +0 -187
- package/src/packlets/runtime/resourceResolver.ts +0 -626
- package/src/packlets/runtime/validate.ts +0 -63
- package/src/packlets/zip-archive/convert.ts +0 -121
- package/src/packlets/zip-archive/index.ts +0 -76
- package/src/packlets/zip-archive/json.ts +0 -91
- package/src/packlets/zip-archive/types.ts +0 -140
- package/src/packlets/zip-archive/zipArchiveCreator.ts +0 -229
- package/src/packlets/zip-archive/zipArchiveFormat.ts +0 -158
- package/src/packlets/zip-archive/zipArchiveLoader.ts +0 -370
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025 Erik Fortune
|
|
3
|
-
*
|
|
4
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
* in the Software without restriction, including without limitation the rights
|
|
7
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
* furnished to do so, subject to the following conditions:
|
|
10
|
-
*
|
|
11
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
-
* copies or substantial portions of the Software.
|
|
13
|
-
*
|
|
14
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
-
* SOFTWARE.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/* eslint-disable @rushstack/typedef-var */
|
|
24
|
-
|
|
25
|
-
import { Validator, Validators, Converter, Converters } from '@fgv/ts-utils';
|
|
26
|
-
import * as Json from './json';
|
|
27
|
-
import { Model as ConfigModel, Convert as ConfigConvert } from '../config';
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Validator for ZIP archive input type
|
|
31
|
-
* @public
|
|
32
|
-
*/
|
|
33
|
-
export const zipArchiveInputType: Validator<'file' | 'directory'> = Validators.enumeratedValue([
|
|
34
|
-
'file',
|
|
35
|
-
'directory'
|
|
36
|
-
] as const);
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Validator for ZIP archive config type
|
|
40
|
-
* @public
|
|
41
|
-
*/
|
|
42
|
-
export const zipArchiveConfigType: Validator<'file'> = Validators.enumeratedValue(['file'] as const);
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Validator for ZIP archive input information
|
|
46
|
-
* @public
|
|
47
|
-
*/
|
|
48
|
-
export const zipArchiveInputInfo: Validator<Json.IZipArchiveInputInfo> =
|
|
49
|
-
Validators.object<Json.IZipArchiveInputInfo>({
|
|
50
|
-
type: zipArchiveInputType,
|
|
51
|
-
originalPath: Validators.string,
|
|
52
|
-
archivePath: Validators.string
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Validator for ZIP archive config information
|
|
57
|
-
* @public
|
|
58
|
-
*/
|
|
59
|
-
export const zipArchiveConfigInfo: Validator<Json.IZipArchiveConfigInfo> =
|
|
60
|
-
Validators.object<Json.IZipArchiveConfigInfo>({
|
|
61
|
-
type: zipArchiveConfigType,
|
|
62
|
-
originalPath: Validators.string,
|
|
63
|
-
archivePath: Validators.string
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Validator for ZIP archive manifest
|
|
68
|
-
* Compatible with existing tools from ts-res-browser-cli
|
|
69
|
-
* @public
|
|
70
|
-
*/
|
|
71
|
-
export const zipArchiveManifest: Validator<Json.IZipArchiveManifest> =
|
|
72
|
-
Validators.object<Json.IZipArchiveManifest>({
|
|
73
|
-
timestamp: Validators.string,
|
|
74
|
-
input: zipArchiveInputInfo.optional(),
|
|
75
|
-
config: zipArchiveConfigInfo.optional()
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Validator for MIME type strings
|
|
80
|
-
* @public
|
|
81
|
-
*/
|
|
82
|
-
export const mimeType: Validator<string> = Validators.string;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Converter for imported file
|
|
86
|
-
* @public
|
|
87
|
-
*/
|
|
88
|
-
export const importedFile: Converter<Json.IImportedFile> = Converters.strictObject<Json.IImportedFile>({
|
|
89
|
-
name: Converters.string,
|
|
90
|
-
path: Converters.string,
|
|
91
|
-
content: Converters.string,
|
|
92
|
-
type: Converters.string // MIME type as string
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Converter for imported directory structure (recursive)
|
|
97
|
-
* Note: Uses Converter pattern because Validators don't support recursion with self parameter
|
|
98
|
-
* @public
|
|
99
|
-
*/
|
|
100
|
-
export const importedDirectory: Converter<Json.IImportedDirectory> = Converters.generic<
|
|
101
|
-
Json.IImportedDirectory,
|
|
102
|
-
unknown
|
|
103
|
-
>((from: unknown, self: Converter<Json.IImportedDirectory, unknown>, context?: unknown) => {
|
|
104
|
-
return Converters.strictObject<Json.IImportedDirectory>({
|
|
105
|
-
name: Converters.string,
|
|
106
|
-
files: Converters.arrayOf(importedFile),
|
|
107
|
-
subdirectories: Converters.arrayOf(self)
|
|
108
|
-
}).convert(from, context);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Validator for system configuration (delegates to config packlet)
|
|
113
|
-
* This validates that the parsed JSON conforms to the system configuration schema
|
|
114
|
-
* @public
|
|
115
|
-
*/
|
|
116
|
-
export const systemConfiguration: Validator<ConfigModel.ISystemConfiguration> = Validators.isA(
|
|
117
|
-
'system configuration',
|
|
118
|
-
(value: unknown): value is ConfigModel.ISystemConfiguration => {
|
|
119
|
-
return ConfigConvert.systemConfiguration.convert(value).isSuccess();
|
|
120
|
-
}
|
|
121
|
-
);
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025 Erik Fortune
|
|
3
|
-
*
|
|
4
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
* in the Software without restriction, including without limitation the rights
|
|
7
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
* furnished to do so, subject to the following conditions:
|
|
10
|
-
*
|
|
11
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
-
* copies or substantial portions of the Software.
|
|
13
|
-
*
|
|
14
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
-
* SOFTWARE.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* ZIP archive functionality for ts-res source file archives
|
|
25
|
-
*
|
|
26
|
-
* This packlet provides consolidated ZIP archive creation and loading functionality
|
|
27
|
-
* for source files, compatible with existing tools while using fflate for
|
|
28
|
-
* universal browser compatibility.
|
|
29
|
-
*
|
|
30
|
-
* @remarks
|
|
31
|
-
* ZIP archives contain source files for resource ingestion with directory
|
|
32
|
-
* structure preserved and optional validation but no processing or transformation.
|
|
33
|
-
* This is distinct from ZIP bundles which contain processed resource output.
|
|
34
|
-
*
|
|
35
|
-
* @packageDocumentation
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
import * as Json from './json';
|
|
39
|
-
import * as Convert from './convert';
|
|
40
|
-
|
|
41
|
-
// Namespaces
|
|
42
|
-
export { Json, Convert };
|
|
43
|
-
|
|
44
|
-
// Core classes
|
|
45
|
-
export { ZipArchiveCreator } from './zipArchiveCreator';
|
|
46
|
-
export { ZipArchiveLoader } from './zipArchiveLoader';
|
|
47
|
-
|
|
48
|
-
// Types and interfaces
|
|
49
|
-
export type {
|
|
50
|
-
IZipArchivePathOptions,
|
|
51
|
-
IZipArchiveFileTreeOptions,
|
|
52
|
-
ZipArchiveOptions,
|
|
53
|
-
IZipArchiveResult,
|
|
54
|
-
IZipArchiveManifest,
|
|
55
|
-
IZipArchiveLoadOptions,
|
|
56
|
-
IZipArchiveLoadResult,
|
|
57
|
-
IImportedFile,
|
|
58
|
-
IImportedDirectory,
|
|
59
|
-
ZipArchiveProgressCallback
|
|
60
|
-
} from './types';
|
|
61
|
-
|
|
62
|
-
// Format utilities
|
|
63
|
-
export {
|
|
64
|
-
createZipArchiveManifest,
|
|
65
|
-
parseZipArchiveManifest,
|
|
66
|
-
validateZipArchiveManifest,
|
|
67
|
-
parseZipArchiveConfiguration,
|
|
68
|
-
generateZipArchiveFilename,
|
|
69
|
-
normalizePath,
|
|
70
|
-
getDirectoryName,
|
|
71
|
-
sanitizeFilename,
|
|
72
|
-
isZipFile
|
|
73
|
-
} from './zipArchiveFormat';
|
|
74
|
-
|
|
75
|
-
// Constants
|
|
76
|
-
export { ZipArchiveConstants } from './types';
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025 Erik Fortune
|
|
3
|
-
*
|
|
4
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
* in the Software without restriction, including without limitation the rights
|
|
7
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
* furnished to do so, subject to the following conditions:
|
|
10
|
-
*
|
|
11
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
-
* copies or substantial portions of the Software.
|
|
13
|
-
*
|
|
14
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
-
* SOFTWARE.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* JSON representation of ZIP archive input information
|
|
25
|
-
* @public
|
|
26
|
-
*/
|
|
27
|
-
export interface IZipArchiveInputInfo {
|
|
28
|
-
/** Type of input (file or directory) */
|
|
29
|
-
type: 'file' | 'directory';
|
|
30
|
-
/** Original file/directory path */
|
|
31
|
-
originalPath: string;
|
|
32
|
-
/** Path within the archive (e.g., "input/mydir") */
|
|
33
|
-
archivePath: string;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* JSON representation of ZIP archive config information
|
|
38
|
-
* @public
|
|
39
|
-
*/
|
|
40
|
-
export interface IZipArchiveConfigInfo {
|
|
41
|
-
/** Type of config (always 'file') */
|
|
42
|
-
type: 'file';
|
|
43
|
-
/** Original config file path */
|
|
44
|
-
originalPath: string;
|
|
45
|
-
/** Path within the archive (e.g., "config.json") */
|
|
46
|
-
archivePath: string;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* JSON representation of a ZIP archive manifest
|
|
51
|
-
* Compatible with existing tools from ts-res-browser-cli
|
|
52
|
-
* @public
|
|
53
|
-
*/
|
|
54
|
-
export interface IZipArchiveManifest {
|
|
55
|
-
/** Archive creation timestamp */
|
|
56
|
-
timestamp: string;
|
|
57
|
-
|
|
58
|
-
/** Optional input source information */
|
|
59
|
-
input?: IZipArchiveInputInfo;
|
|
60
|
-
|
|
61
|
-
/** Optional configuration file information */
|
|
62
|
-
config?: IZipArchiveConfigInfo;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* JSON representation of an imported file
|
|
67
|
-
* @public
|
|
68
|
-
*/
|
|
69
|
-
export interface IImportedFile {
|
|
70
|
-
/** File name */
|
|
71
|
-
name: string;
|
|
72
|
-
/** Full path within archive */
|
|
73
|
-
path: string;
|
|
74
|
-
/** File content as string */
|
|
75
|
-
content: string;
|
|
76
|
-
/** MIME type */
|
|
77
|
-
type: string;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* JSON representation of an imported directory structure
|
|
82
|
-
* @public
|
|
83
|
-
*/
|
|
84
|
-
export interface IImportedDirectory {
|
|
85
|
-
/** Directory name */
|
|
86
|
-
name: string;
|
|
87
|
-
/** Files in this directory */
|
|
88
|
-
files: IImportedFile[];
|
|
89
|
-
/** Subdirectories */
|
|
90
|
-
subdirectories: IImportedDirectory[];
|
|
91
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025 Erik Fortune
|
|
3
|
-
*
|
|
4
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
* in the Software without restriction, including without limitation the rights
|
|
7
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
* furnished to do so, subject to the following conditions:
|
|
10
|
-
*
|
|
11
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
-
* copies or substantial portions of the Software.
|
|
13
|
-
*
|
|
14
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
-
* SOFTWARE.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import { Model as ConfigModel } from '../config';
|
|
24
|
-
import * as Json from './json';
|
|
25
|
-
import { FileTree } from '@fgv/ts-utils';
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Options for creating a ZIP archive buffer
|
|
29
|
-
* @public
|
|
30
|
-
*/
|
|
31
|
-
export interface IZipArchivePathOptions {
|
|
32
|
-
/** File or directory path to include in the archive */
|
|
33
|
-
inputPath?: string;
|
|
34
|
-
/** Optional configuration file path */
|
|
35
|
-
configPath?: string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Options for creating a ZIP archive buffer from a file tree
|
|
40
|
-
* @public
|
|
41
|
-
*/
|
|
42
|
-
export interface IZipArchiveFileTreeOptions {
|
|
43
|
-
/** Input file or directory */
|
|
44
|
-
inputItem?: FileTree.FileTreeItem;
|
|
45
|
-
/** Optional configuration file */
|
|
46
|
-
configItem?: FileTree.IFileTreeFileItem;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Options for creating a ZIP archive buffer
|
|
51
|
-
* @public
|
|
52
|
-
*/
|
|
53
|
-
export type ZipArchiveOptions = IZipArchivePathOptions | IZipArchiveFileTreeOptions;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Standardized ZIP archive manifest format (compatible with existing tools)
|
|
57
|
-
* @public
|
|
58
|
-
*/
|
|
59
|
-
export type IZipArchiveManifest = Json.IZipArchiveManifest;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Result of ZIP archive buffer creation
|
|
63
|
-
* @public
|
|
64
|
-
*/
|
|
65
|
-
export interface IZipArchiveResult {
|
|
66
|
-
/** Raw ZIP data buffer */
|
|
67
|
-
zipBuffer: Uint8Array;
|
|
68
|
-
/** Archive manifest with metadata */
|
|
69
|
-
manifest: IZipArchiveManifest;
|
|
70
|
-
/** Total ZIP size in bytes */
|
|
71
|
-
size: number;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Options for loading a ZIP archive
|
|
76
|
-
* @public
|
|
77
|
-
*/
|
|
78
|
-
export interface IZipArchiveLoadOptions {
|
|
79
|
-
/** Validate manifest strictly */
|
|
80
|
-
strictManifestValidation?: boolean;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Result of ZIP archive loading
|
|
85
|
-
* @public
|
|
86
|
-
*/
|
|
87
|
-
export interface IZipArchiveLoadResult {
|
|
88
|
-
/** Parsed archive manifest */
|
|
89
|
-
manifest: IZipArchiveManifest | undefined;
|
|
90
|
-
/** Loaded configuration */
|
|
91
|
-
config: ConfigModel.ISystemConfiguration | undefined;
|
|
92
|
-
/** All files extracted from the archive */
|
|
93
|
-
files: IImportedFile[];
|
|
94
|
-
/** Directory structure if available */
|
|
95
|
-
directory: IImportedDirectory | undefined;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Imported file representation
|
|
100
|
-
* @public
|
|
101
|
-
*/
|
|
102
|
-
export type IImportedFile = Json.IImportedFile;
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Imported directory structure
|
|
106
|
-
* @public
|
|
107
|
-
*/
|
|
108
|
-
export type IImportedDirectory = Json.IImportedDirectory;
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Progress callback for ZIP operations
|
|
112
|
-
* @public
|
|
113
|
-
*/
|
|
114
|
-
export type ZipArchiveProgressCallback = (
|
|
115
|
-
stage:
|
|
116
|
-
| 'reading-file'
|
|
117
|
-
| 'parsing-zip'
|
|
118
|
-
| 'loading-manifest'
|
|
119
|
-
| 'loading-config'
|
|
120
|
-
| 'extracting-files'
|
|
121
|
-
| 'processing-resources'
|
|
122
|
-
| 'creating-zip',
|
|
123
|
-
progress: number, // 0-100
|
|
124
|
-
details: string
|
|
125
|
-
) => void;
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Constants for ZIP archive structure
|
|
129
|
-
* @public
|
|
130
|
-
*/
|
|
131
|
-
export const ZipArchiveConstants = {
|
|
132
|
-
/** Manifest file name */
|
|
133
|
-
MANIFEST_FILE: 'manifest.json',
|
|
134
|
-
/** Configuration file name */
|
|
135
|
-
CONFIG_FILE: 'config.json',
|
|
136
|
-
/** Input files directory */
|
|
137
|
-
INPUT_DIR: 'input',
|
|
138
|
-
/** Configuration files directory */
|
|
139
|
-
CONFIG_DIR: 'config'
|
|
140
|
-
} as const;
|
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025 Erik Fortune
|
|
3
|
-
*
|
|
4
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
* in the Software without restriction, including without limitation the rights
|
|
7
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
* furnished to do so, subject to the following conditions:
|
|
10
|
-
*
|
|
11
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
-
* copies or substantial portions of the Software.
|
|
13
|
-
*
|
|
14
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
-
* SOFTWARE.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import { zipSync } from 'fflate';
|
|
24
|
-
import { Result, succeed, fail, FileTree } from '@fgv/ts-utils';
|
|
25
|
-
import type { IZipArchiveResult, ZipArchiveOptions, ZipArchiveProgressCallback } from './types';
|
|
26
|
-
import { normalizePath } from './zipArchiveFormat';
|
|
27
|
-
import * as Json from './json';
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* ZIP archive creator using fflate for universal compatibility
|
|
31
|
-
* @public
|
|
32
|
-
*/
|
|
33
|
-
export class ZipArchiveCreator {
|
|
34
|
-
/**
|
|
35
|
-
* Create a ZIP archive buffer from a supplied buffer
|
|
36
|
-
* @param options - Input paths and configuration
|
|
37
|
-
* @param onProgress - Optional progress callback
|
|
38
|
-
* @returns Result containing ZIP buffer and manifest
|
|
39
|
-
*/
|
|
40
|
-
public async createFromBuffer(
|
|
41
|
-
options: ZipArchiveOptions,
|
|
42
|
-
onProgress?: ZipArchiveProgressCallback
|
|
43
|
-
): Promise<Result<IZipArchiveResult>> {
|
|
44
|
-
try {
|
|
45
|
-
onProgress?.('creating-zip', 0, 'Starting ZIP archive creation');
|
|
46
|
-
|
|
47
|
-
const files: Record<string, Uint8Array> = {};
|
|
48
|
-
const manifest: Json.IZipArchiveManifest = {
|
|
49
|
-
timestamp: new Date().toISOString()
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const { value: inputItem, message: inputItemError } = this._getInputFileTreeItem(options);
|
|
53
|
-
if (inputItemError !== undefined) {
|
|
54
|
-
return fail(inputItemError);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (inputItem !== undefined) {
|
|
58
|
-
onProgress?.('reading-file', 10, `Processing input: ${inputItem.absolutePath}`);
|
|
59
|
-
|
|
60
|
-
if (inputItem.type === 'directory') {
|
|
61
|
-
// Add entire directory recursively, preserving structure
|
|
62
|
-
const archivePath = `input/${inputItem.name}`;
|
|
63
|
-
|
|
64
|
-
const addDirResult = await this._addDirectoryTreeToZip(files, inputItem, archivePath, onProgress);
|
|
65
|
-
/* c8 ignore next 3 - defense in depth against internal error */
|
|
66
|
-
if (addDirResult.isFailure()) {
|
|
67
|
-
return fail(addDirResult.message);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
manifest.input = {
|
|
71
|
-
type: 'directory',
|
|
72
|
-
originalPath: inputItem.absolutePath,
|
|
73
|
-
archivePath
|
|
74
|
-
};
|
|
75
|
-
} else if (inputItem.type === 'file') {
|
|
76
|
-
// Add single file
|
|
77
|
-
const archivePath = `input/${inputItem.name}`;
|
|
78
|
-
|
|
79
|
-
const addFileResult = await this._addFileTreeItemToZip(files, inputItem, archivePath);
|
|
80
|
-
/* c8 ignore next 3 - defense in depth against internal error */
|
|
81
|
-
if (addFileResult.isFailure()) {
|
|
82
|
-
return fail(addFileResult.message);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
manifest.input = {
|
|
86
|
-
type: 'file',
|
|
87
|
-
originalPath: inputItem.absolutePath,
|
|
88
|
-
archivePath
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const { value: configItem, message: configItemError } = this._getConfigFileTreeItem(options);
|
|
94
|
-
if (configItemError !== undefined) {
|
|
95
|
-
return fail(configItemError);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (configItem !== undefined) {
|
|
99
|
-
onProgress?.('reading-file', 40, `Processing config: ${configItem.absolutePath}`);
|
|
100
|
-
|
|
101
|
-
const archivePath = `config/${configItem.name}`;
|
|
102
|
-
|
|
103
|
-
const addConfigResult = await this._addFileTreeItemToZip(files, configItem, archivePath);
|
|
104
|
-
/* c8 ignore next 3 - defense in depth against internal error */
|
|
105
|
-
if (addConfigResult.isFailure()) {
|
|
106
|
-
return fail(addConfigResult.message);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Update manifest with config info
|
|
110
|
-
manifest.config = {
|
|
111
|
-
type: 'file',
|
|
112
|
-
originalPath: configItem.absolutePath,
|
|
113
|
-
archivePath
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Add manifest to ZIP
|
|
118
|
-
onProgress?.('creating-zip', 70, 'Adding manifest');
|
|
119
|
-
const manifestJson = JSON.stringify(manifest, null, 2);
|
|
120
|
-
files['manifest.json'] = new TextEncoder().encode(manifestJson);
|
|
121
|
-
|
|
122
|
-
// Create ZIP buffer using fflate
|
|
123
|
-
onProgress?.('creating-zip', 80, 'Compressing files');
|
|
124
|
-
const zipBuffer = zipSync(files, { level: 6 });
|
|
125
|
-
|
|
126
|
-
const result: IZipArchiveResult = {
|
|
127
|
-
zipBuffer,
|
|
128
|
-
manifest,
|
|
129
|
-
size: zipBuffer.length
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
onProgress?.('creating-zip', 100, 'ZIP archive buffer created');
|
|
133
|
-
|
|
134
|
-
return succeed(result);
|
|
135
|
-
/* c8 ignore next 3 - defense in depth against internal error */
|
|
136
|
-
} catch (error) {
|
|
137
|
-
return fail(`Failed to create ZIP archive: ${error instanceof Error ? error.message : String(error)}`);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Add a single FileTree item to the ZIP archive
|
|
143
|
-
* @param files - ZIP files collection
|
|
144
|
-
* @param fileItem - FileTree file item to add
|
|
145
|
-
* @param archivePath - Path within the archive
|
|
146
|
-
* @returns Result indicating success or failure
|
|
147
|
-
*/
|
|
148
|
-
private async _addFileTreeItemToZip(
|
|
149
|
-
files: Record<string, Uint8Array>,
|
|
150
|
-
fileItem: FileTree.IFileTreeFileItem,
|
|
151
|
-
archivePath: string
|
|
152
|
-
): Promise<Result<void>> {
|
|
153
|
-
return fileItem.getRawContents().onSuccess((content) => {
|
|
154
|
-
const contentBuffer = new TextEncoder().encode(content);
|
|
155
|
-
files[normalizePath(archivePath)] = contentBuffer;
|
|
156
|
-
return succeed(undefined);
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Add a directory recursively to the ZIP archive using FileTree
|
|
162
|
-
* @param files - ZIP files collection
|
|
163
|
-
* @param directoryItem - FileTree directory item to add
|
|
164
|
-
* @param archivePrefix - Prefix path within the archive
|
|
165
|
-
* @param onProgress - Optional progress callback
|
|
166
|
-
* @returns Result indicating success or failure
|
|
167
|
-
*/
|
|
168
|
-
private async _addDirectoryTreeToZip(
|
|
169
|
-
files: Record<string, Uint8Array>,
|
|
170
|
-
directoryItem: FileTree.IFileTreeDirectoryItem,
|
|
171
|
-
archivePrefix: string,
|
|
172
|
-
onProgress?: ZipArchiveProgressCallback
|
|
173
|
-
): Promise<Result<void>> {
|
|
174
|
-
const childrenResult = directoryItem.getChildren();
|
|
175
|
-
/* c8 ignore next 3 - defense in depth against internal error */
|
|
176
|
-
if (childrenResult.isFailure()) {
|
|
177
|
-
return fail(`Failed to read directory ${directoryItem.absolutePath}: ${childrenResult.message}`);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
for (const child of childrenResult.value) {
|
|
181
|
-
const itemArchivePath = normalizePath(`${archivePrefix}/${child.name}`);
|
|
182
|
-
|
|
183
|
-
if (child.type === 'directory') {
|
|
184
|
-
// Recursively add subdirectory
|
|
185
|
-
const addDirResult = await this._addDirectoryTreeToZip(files, child, itemArchivePath, onProgress);
|
|
186
|
-
/* c8 ignore next 3 - defense in depth against internal error */
|
|
187
|
-
if (addDirResult.isFailure()) {
|
|
188
|
-
return fail(addDirResult.message);
|
|
189
|
-
}
|
|
190
|
-
} else if (child.type === 'file') {
|
|
191
|
-
// Add file
|
|
192
|
-
const addFileResult = await this._addFileTreeItemToZip(files, child, itemArchivePath);
|
|
193
|
-
/* c8 ignore next 3 - defense in depth against internal error */
|
|
194
|
-
if (addFileResult.isFailure()) {
|
|
195
|
-
return fail(addFileResult.message);
|
|
196
|
-
}
|
|
197
|
-
onProgress?.('reading-file', 0, `Added file: ${itemArchivePath}`);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return succeed(undefined);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
private _getInputFileTreeItem(options: ZipArchiveOptions): Result<FileTree.FileTreeItem | undefined> {
|
|
205
|
-
if ('inputPath' in options && options.inputPath !== undefined) {
|
|
206
|
-
return FileTree.forFilesystem()
|
|
207
|
-
.withErrorFormat((msg) => `Failed to create file tree: ${msg}`)
|
|
208
|
-
.onSuccess((fileTree) =>
|
|
209
|
-
fileTree.getItem(options.inputPath!).withErrorFormat((msg) => `Failed to get item: ${msg}`)
|
|
210
|
-
);
|
|
211
|
-
} else if ('inputItem' in options) {
|
|
212
|
-
return succeed(options.inputItem);
|
|
213
|
-
}
|
|
214
|
-
return succeed(undefined);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
private _getConfigFileTreeItem(options: ZipArchiveOptions): Result<FileTree.IFileTreeFileItem | undefined> {
|
|
218
|
-
if ('configPath' in options && options.configPath !== undefined) {
|
|
219
|
-
return FileTree.forFilesystem()
|
|
220
|
-
.withErrorFormat((msg) => `Failed to create file tree: ${msg}`)
|
|
221
|
-
.onSuccess((fileTree) =>
|
|
222
|
-
fileTree.getFile(options.configPath!).withErrorFormat((msg) => `Failed to get config file: ${msg}`)
|
|
223
|
-
);
|
|
224
|
-
} else if ('configItem' in options && options.configItem !== undefined) {
|
|
225
|
-
return succeed(options.configItem);
|
|
226
|
-
}
|
|
227
|
-
return succeed(undefined);
|
|
228
|
-
}
|
|
229
|
-
}
|