UNPKG

1.72 kBJavaScriptView Raw
1'use strict';
2
3const path = require('path');
4
5const getParentDirectoryContainingFileSync = require('./getParentDirectoryContainingFileSync');
6const { isNightly, isPre770Editor, isPre782Editor } = require('./editorVersions');
7
8class EditorRepository {
9 constructor(app) {
10 this._app = app;
11
12 this.path = getParentDirectoryContainingFileSync(process.cwd(), 'manifest.json');
13
14 this.config = null;
15 this.configSource = null;
16 this.isNightly = null;
17 this.isPre770 = null;
18 this.isPre782 = null;
19 this.name = null;
20 this.sdkVersion = null;
21
22 if (!this.path) {
23 return;
24 }
25
26 try {
27 Object.assign(this, require(path.join(this.path, 'manifest.json')));
28 } catch (_error) {
29 this._app.logger.notice(`Could not read manifest.json.`);
30 this._app.logger.notice("Please check and fix your editor's manifest.json file.");
31 this._app.logger.break();
32 }
33
34 this.isNightly = isNightly(this.sdkVersion);
35 this.isPre770 = isPre770Editor(this.sdkVersion);
36 this.isPre782 = isPre782Editor(this.sdkVersion);
37
38 try {
39 const configJsPath = path.join(this.path, 'config.js');
40 this.config = require(configJsPath)();
41 this.configSource = configJsPath;
42 } catch (_error) {
43 // No-op
44 }
45
46 if (!this.configSource) {
47 try {
48 const configJsonPath = path.join(this.path, 'config.json');
49 this.config = require(configJsonPath);
50 this.configSource = configJsonPath;
51 } catch (_error) {
52 // No-op
53 }
54 }
55 }
56
57 throwIfNotInsideEditorRepository() {
58 if (!this.path) {
59 throw new this._app.logger.InputError(
60 'Not running from inside a Fonto Editor repository.',
61 'This command requires to be run from inside a Fonto Editor repository.'
62 );
63 }
64 }
65}
66
67module.exports = EditorRepository;