UNPKG

6.61 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.makeCompanionManifest = exports.makeDeviceManifest = void 0;
4const tslib_1 = require("tslib");
5const stream_1 = require("stream");
6const lodash_1 = tslib_1.__importDefault(require("lodash"));
7const plugin_error_1 = tslib_1.__importDefault(require("plugin-error"));
8const vinyl_1 = tslib_1.__importDefault(require("vinyl"));
9const capabilities_1 = require("./capabilities");
10const componentTargets_1 = require("./componentTargets");
11const pathUtils_1 = require("./pathUtils");
12const ProjectConfiguration_1 = require("./ProjectConfiguration");
13const resources = tslib_1.__importStar(require("./resources"));
14const sdkVersion_1 = require("./sdkVersion");
15const PLUGIN_NAME = 'componentManifest';
16const manifestPath = 'manifest.json';
17function makeCommonManifest({ projectConfig, buildId, apiVersion, }) {
18 return {
19 apiVersion,
20 buildId,
21 bundleDate: new Date().toISOString(),
22 uuid: projectConfig.appUUID,
23 name: projectConfig.appDisplayName,
24 requestedPermissions: projectConfig.requestedPermissions,
25 };
26}
27function makeDeviceManifest({ projectConfig, buildId, targetDevice, }) {
28 const locales = projectConfig.i18n;
29 let entryPoint;
30 return new stream_1.Transform({
31 objectMode: true,
32 transform(file, _, next) {
33 const lang = file.translationLanguage;
34 if (lang) {
35 if (locales[lang] === undefined)
36 locales[lang] = {};
37 locales[lang].resources = pathUtils_1.normalizeToPOSIX(file.relative);
38 }
39 if (file.isEntryPoint) {
40 if (file.componentType === componentTargets_1.ComponentType.DEVICE) {
41 if (entryPoint) {
42 return next(new plugin_error_1.default(PLUGIN_NAME, 'Multiple entry points were generated for device, only one is allowed'));
43 }
44 entryPoint = pathUtils_1.normalizeToPOSIX(file.relative);
45 }
46 else {
47 return next(new plugin_error_1.default(PLUGIN_NAME, `Entry point for unrecognised component found: ${file.componentType}`));
48 }
49 }
50 next(undefined, file);
51 },
52 flush(done) {
53 const _a = locales, _b = projectConfig.defaultLanguage, defaultLanguage = _a[_b], otherLocales = tslib_1.__rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
54 if (!entryPoint) {
55 return done(new plugin_error_1.default(PLUGIN_NAME, 'No entry point was generated for device component'));
56 }
57 const { deviceApi } = sdkVersion_1.apiVersions(projectConfig);
58 const supports = capabilities_1.SupportedDeviceCapabilities.create(targetDevice);
59 const manifest = Object.assign(Object.assign(Object.assign(Object.assign({ appManifestVersion: 1, main: entryPoint, svgMain: resources.svgMain, svgWidgets: resources.svgWidgets, appType: projectConfig.appType }, makeCommonManifest({
60 projectConfig,
61 buildId,
62 apiVersion: deviceApi,
63 })), (supports && { supports })), { i18n: lodash_1.default.mapKeys(Object.assign({ [projectConfig.defaultLanguage]: defaultLanguage }, otherLocales), (_, locale) => locale.toLowerCase()) }), (projectConfig.appType !== ProjectConfiguration_1.AppType.CLOCKFACE && {
64 iconFile: projectConfig.iconFile,
65 wipeColor: projectConfig.wipeColor,
66 }));
67 done(undefined, new vinyl_1.default({
68 cwd: '',
69 base: undefined,
70 path: manifestPath,
71 contents: Buffer.from(JSON.stringify(manifest)),
72 }));
73 },
74 });
75}
76exports.makeDeviceManifest = makeDeviceManifest;
77function makeCompanionManifest({ projectConfig, hasSettings, buildId, }) {
78 let companionEntryPoint;
79 let settingsEntryPoint;
80 return new stream_1.Transform({
81 objectMode: true,
82 transform(file, _, next) {
83 const isEntryPoint = file.isEntryPoint;
84 if (isEntryPoint) {
85 if (file.componentType === componentTargets_1.ComponentType.COMPANION) {
86 if (companionEntryPoint) {
87 return next(new plugin_error_1.default(PLUGIN_NAME, 'Multiple entry points were generated for companion, only one is allowed'));
88 }
89 companionEntryPoint = pathUtils_1.normalizeToPOSIX(file.relative);
90 }
91 else if (file.componentType === componentTargets_1.ComponentType.SETTINGS) {
92 if (settingsEntryPoint) {
93 return next(new plugin_error_1.default(PLUGIN_NAME, 'Multiple entry points were generated for settings, only one is allowed'));
94 }
95 settingsEntryPoint = pathUtils_1.normalizeToPOSIX(file.relative);
96 }
97 else {
98 return next(new plugin_error_1.default(PLUGIN_NAME, `Entry point for unrecognised component found: ${file.componentType}`));
99 }
100 }
101 next(undefined, file);
102 },
103 flush(done) {
104 if (!companionEntryPoint) {
105 return done(new plugin_error_1.default(PLUGIN_NAME, 'No entry point was generated for companion component'));
106 }
107 const manifest = Object.assign({ manifestVersion: 2, companion: { main: companionEntryPoint } }, makeCommonManifest({
108 projectConfig,
109 buildId,
110 apiVersion: sdkVersion_1.apiVersions(projectConfig).companionApi,
111 }));
112 if (hasSettings) {
113 if (!settingsEntryPoint) {
114 return done(new plugin_error_1.default(PLUGIN_NAME, 'No entry point was generated for settings component'));
115 }
116 manifest.settings = { main: settingsEntryPoint };
117 }
118 if (projectConfig.appClusterID) {
119 manifest.appClusters = [projectConfig.appClusterID];
120 }
121 if (projectConfig.developerID) {
122 manifest.developerProfileId = projectConfig.developerID;
123 }
124 done(undefined, new vinyl_1.default({
125 cwd: '',
126 base: undefined,
127 path: manifestPath,
128 contents: Buffer.from(JSON.stringify(manifest)),
129 }));
130 },
131 });
132}
133exports.makeCompanionManifest = makeCompanionManifest;