UNPKG

2.92 kBJavaScriptView Raw
1const ConfigFile = require('./abstract-config-file');
2
3// instance which stores the singleton
4let instance = null;
5
6module.exports = class Manifest extends ConfigFile {
7 /**
8 * Constructor for Manifest class
9 * @param {string} filePath
10 * @throws {Error}
11 */
12 constructor(filePath) {
13 if (instance && instance.path === filePath) {
14 return instance;
15 }
16 // init by calling super() if instance not exists
17 super(filePath);
18 instance = this;
19 }
20
21 static getInstance() {
22 return instance;
23 }
24
25 static dispose() {
26 instance = null;
27 }
28
29 /**
30 * Skill name is decided by en-US locale's name or the first locale's name if en-US doesn't exist
31 */
32 getSkillName() {
33 const publishingLocales = this.getPublishingLocales();
34 const finalLocale = publishingLocales['en-US'] ? 'en-US' : Object.keys(publishingLocales)[0];
35 return this.getProperty(['manifest', 'publishingInformation', 'locales', finalLocale, 'name']);
36 }
37
38 setSkillName(skillName) {
39 const publishingLocales = this.getPublishingLocales();
40 const finalLocale = publishingLocales['en-US'] ? 'en-US' : Object.keys(publishingLocales)[0];
41 this.setProperty(['manifest', 'publishingInformation', 'locales', finalLocale, 'name'], skillName);
42 }
43
44 // getter and setter
45
46 getPublishingLocales() {
47 return this.getProperty(['manifest', 'publishingInformation', 'locales']);
48 }
49
50 setPublishingLocales(localesObject) {
51 this.setProperty(['manifest', 'publishingInformation', 'locales'], localesObject);
52 }
53
54 getPublishingLocale(locale) {
55 return this.getProperty(['manifest', 'publishingInformation', 'locales', locale]);
56 }
57
58 setPublishingLocale(locale, localeObject) {
59 this.setProperty(['manifest', 'publishingInformation', 'locales', locale], localeObject);
60 }
61
62 getApis() {
63 return this.getProperty(['manifest', 'apis']);
64 }
65
66 setApis(apisObject) {
67 this.setProperty(['manifest', 'apis'], apisObject);
68 }
69
70 getApisDomain(domain) {
71 return this.getProperty(['manifest', 'apis', domain]);
72 }
73
74 setApisDomain(domain, domainObject) {
75 this.setProperty(['manifest', 'apis', domain], domainObject);
76 }
77
78 getApisEndpointByDomainRegion(domain, region) {
79 if (region === 'default') {
80 return this.getProperty(['manifest', 'apis', domain, 'endpoint']);
81 }
82 return this.getProperty(['manifest', 'apis', domain, 'regions', region, 'endpoint']);
83 }
84
85 setApisEndpointByDomainRegion(domain, region, endpointObj) {
86 if (region === 'default') {
87 this.setProperty(['manifest', 'apis', domain, 'endpoint'], endpointObj);
88 } else {
89 this.setProperty(['manifest', 'apis', domain, 'regions', region, 'endpoint'], endpointObj);
90 }
91 }
92};