1 | 'use strict';
|
2 |
|
3 | const Fotno = require('fotno');
|
4 |
|
5 | Fotno.FotnoCommand.addFileNameToSkipForSetControllerCallsites('/fontoxml-development-tools/src/FdtCommand.js');
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | class FdtCommand extends Fotno.FotnoCommand {
|
13 | |
14 |
|
15 |
|
16 |
|
17 |
|
18 | constructor (name, controller) {
|
19 | super(name, controller);
|
20 |
|
21 | this.setNewChildClass(FdtCommand);
|
22 |
|
23 | this.requiredProductLicenses = [];
|
24 | this.requiresEditorRepository = false;
|
25 | this.requiresToValidateLicenseFile = false;
|
26 |
|
27 | this.addPreController(this._preController.bind(this));
|
28 | }
|
29 |
|
30 | |
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | _preController (req, res) {
|
39 | let preControllerPromise = Promise.resolve();
|
40 |
|
41 | if (this.requiresEditorRepository) {
|
42 | preControllerPromise = preControllerPromise.then(() => {
|
43 | req.fdt.editorRepository.throwIfNotInsideEditorRepository();
|
44 | });
|
45 | }
|
46 |
|
47 | if (this.requiresToValidateLicenseFile) {
|
48 | preControllerPromise = preControllerPromise.then(() => {
|
49 | const destroySpinner = res.spinner('Validating license...');
|
50 |
|
51 | return req.fdt.license.validateAndUpdateLicenseFile()
|
52 | .then(result => {
|
53 | destroySpinner();
|
54 | return result;
|
55 | })
|
56 | .catch(error => {
|
57 | destroySpinner();
|
58 | throw error;
|
59 | });
|
60 | });
|
61 | }
|
62 |
|
63 | if (this.requiredProductLicenses.length > 0) {
|
64 | preControllerPromise = preControllerPromise.then(() => {
|
65 | const destroySpinner = res.spinner('Checking required product licenses...');
|
66 |
|
67 | try {
|
68 | req.fdt.license.ensureProductLicenses(this.requiredProductLicenses);
|
69 | destroySpinner();
|
70 | }
|
71 | catch (error) {
|
72 | destroySpinner();
|
73 | throw error;
|
74 | }
|
75 |
|
76 | return true;
|
77 | });
|
78 | }
|
79 |
|
80 | return preControllerPromise;
|
81 | }
|
82 |
|
83 | |
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 | addRequiredProductLicenses (productIds) {
|
92 | this.requiredProductLicenses = this.requiredProductLicenses.concat(productIds);
|
93 |
|
94 | return this;
|
95 | }
|
96 |
|
97 | |
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | setRequiresLicenseValidation (validateLicense = true) {
|
106 | this.requiresToValidateLicenseFile = !!validateLicense;
|
107 |
|
108 | return this;
|
109 | }
|
110 |
|
111 | |
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 | setRequiresEditorRepository (value = true) {
|
120 | this.requiresEditorRepository = !!value;
|
121 |
|
122 | return this;
|
123 | }
|
124 | }
|
125 |
|
126 | module.exports = FdtCommand;
|