@signageos/cli 2.5.0 → 2.6.0-rc.0
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/dist/Applet/Generate/appletGenerateCommand.js +1 -1
- package/dist/CustomScript/customScriptFacade.d.ts +5 -5
- package/dist/CustomScript/customScriptFacade.js +5 -4
- package/dist/Plugin/Generate/pluginGenerateCommand.d.ts +7 -0
- package/dist/Plugin/Generate/pluginGenerateCommand.js +38 -0
- package/dist/Plugin/Generate/pluginGenerateFacade.d.ts +12 -0
- package/dist/Plugin/Generate/pluginGenerateFacade.js +106 -0
- package/dist/Plugin/Upload/pluginUploadCommand.d.ts +25 -0
- package/dist/Plugin/Upload/pluginUploadCommand.js +70 -0
- package/dist/Plugin/pluginCommand.d.ts +27 -0
- package/dist/Plugin/pluginCommand.js +26 -0
- package/dist/Plugin/pluginFacade.d.ts +62 -0
- package/dist/Plugin/pluginFacade.js +251 -0
- package/dist/Runner/Generate/runnerGenerateCommand.d.ts +7 -0
- package/dist/Runner/Generate/runnerGenerateCommand.js +38 -0
- package/dist/Runner/Generate/runnerGenerateFacade.d.ts +12 -0
- package/dist/Runner/Generate/runnerGenerateFacade.js +107 -0
- package/dist/Runner/Upload/runnerUploadCommand.d.ts +25 -0
- package/dist/Runner/Upload/runnerUploadCommand.js +72 -0
- package/dist/Runner/runnerCommand.d.ts +27 -0
- package/dist/Runner/runnerCommand.js +26 -0
- package/dist/Runner/runnerFacede.d.ts +15 -0
- package/dist/Runner/runnerFacede.js +234 -0
- package/dist/index.js +3 -1
- package/docs/applet/index.md +10 -10
- package/docs/applet/test/index.md +4 -4
- package/docs/autocomplete/index.md +4 -4
- package/docs/custom-script/index.md +4 -4
- package/docs/device/index.md +6 -6
- package/docs/index.md +16 -14
- package/docs/organization/index.md +6 -6
- package/docs/plugin/generate/index.md +43 -0
- package/docs/plugin/index.md +72 -0
- package/docs/plugin/upload/index.md +50 -0
- package/docs/runner/generate/index.md +43 -0
- package/docs/runner/index.md +72 -0
- package/docs/runner/upload/index.md +50 -0
- package/docs/timing/index.md +2 -2
- package/package.json +2 -2
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.ConfigSchema = void 0;
|
|
49
|
+
exports.ensurePluginVersion = ensurePluginVersion;
|
|
50
|
+
exports.uploadCode = uploadCode;
|
|
51
|
+
exports.loadSchemas = loadSchemas;
|
|
52
|
+
const path = __importStar(require("path"));
|
|
53
|
+
const os = __importStar(require("os"));
|
|
54
|
+
const fs = __importStar(require("fs-extra"));
|
|
55
|
+
const zod_1 = __importDefault(require("zod"));
|
|
56
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
57
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
58
|
+
const log_1 = require("@signageos/sdk/dist/Console/log");
|
|
59
|
+
const archive_1 = require("../Lib/archive");
|
|
60
|
+
const fileSystem_1 = require("../Lib/fileSystem");
|
|
61
|
+
const runtimeFileSystem_1 = require("@signageos/sdk/dist/Development/runtimeFileSystem");
|
|
62
|
+
const customScriptFacade_1 = require("../CustomScript/customScriptFacade");
|
|
63
|
+
const PLUGIN_BUILDS_DIRNAME = 'plugin_builds';
|
|
64
|
+
function ensurePluginVersion(restApi, config, schema) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
const plugin = yield ensurePlugin(restApi, config);
|
|
67
|
+
const pluginVersion = yield restApi.plugin.version.get({
|
|
68
|
+
pluginUid: plugin.uid,
|
|
69
|
+
version: config.version,
|
|
70
|
+
});
|
|
71
|
+
if (pluginVersion) {
|
|
72
|
+
return pluginVersion;
|
|
73
|
+
}
|
|
74
|
+
const response = yield (0, prompts_1.default)({
|
|
75
|
+
type: 'confirm',
|
|
76
|
+
name: 'newVersion',
|
|
77
|
+
message: `Do you want to create new plugin version ${config.version}?`,
|
|
78
|
+
});
|
|
79
|
+
if (!response.newVersion) {
|
|
80
|
+
throw new Error('Plugin version creation was canceled.');
|
|
81
|
+
}
|
|
82
|
+
(0, log_1.log)('info', chalk_1.default.yellow(`Creating Plugin version ${config.version}`));
|
|
83
|
+
return yield restApi.plugin.version.create({
|
|
84
|
+
pluginUid: plugin.uid,
|
|
85
|
+
version: config.version,
|
|
86
|
+
description: 'testts',
|
|
87
|
+
schema: schema.schema,
|
|
88
|
+
configDefinition: config.configDefinition,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function ensurePlugin(restApi, config) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
if (config.uid) {
|
|
95
|
+
const plugin = yield restApi.plugin.get(config.uid);
|
|
96
|
+
if (plugin) {
|
|
97
|
+
yield restApi.plugin.update(plugin.uid, {
|
|
98
|
+
name: config.name,
|
|
99
|
+
title: config.name,
|
|
100
|
+
description: config.description,
|
|
101
|
+
});
|
|
102
|
+
return plugin;
|
|
103
|
+
}
|
|
104
|
+
throw new Error(`Plugin with uid "${config.uid}" not found`);
|
|
105
|
+
}
|
|
106
|
+
const response = yield (0, prompts_1.default)({
|
|
107
|
+
type: 'confirm',
|
|
108
|
+
name: 'create',
|
|
109
|
+
message: `Plugin "${config.name}" does not exist. Do you want to create it?`,
|
|
110
|
+
});
|
|
111
|
+
if (!response.create) {
|
|
112
|
+
throw new Error('Plugin upload was canceled.');
|
|
113
|
+
}
|
|
114
|
+
(0, log_1.log)('info', chalk_1.default.yellow(`Creating Plugin "${config.name}"`));
|
|
115
|
+
const createdPlugin = yield restApi.plugin.create({
|
|
116
|
+
name: config.name,
|
|
117
|
+
title: config.name,
|
|
118
|
+
description: config.description,
|
|
119
|
+
});
|
|
120
|
+
// TODO ask for permission or read from CLI arg
|
|
121
|
+
(0, log_1.log)('info', chalk_1.default.yellow('Adding Plugin uid to the config file'));
|
|
122
|
+
yield (0, customScriptFacade_1.addToConfigFile)(process.cwd(), { uid: createdPlugin.uid });
|
|
123
|
+
return createdPlugin;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function uploadCode(_a) {
|
|
127
|
+
return __awaiter(this, arguments, void 0, function* ({ restApi, workDir, platform, config, pluginVersion, }) {
|
|
128
|
+
const { mainFile, runtime } = config;
|
|
129
|
+
const codeArchive = yield generatePluginPlatformCodeArchive(workDir, config, pluginVersion, platform);
|
|
130
|
+
const pluginVersionPlatform = yield restApi.plugin.version.platform.get({
|
|
131
|
+
pluginUid: pluginVersion.pluginUid,
|
|
132
|
+
version: pluginVersion.version,
|
|
133
|
+
platform,
|
|
134
|
+
});
|
|
135
|
+
if ((pluginVersionPlatform === null || pluginVersionPlatform === void 0 ? void 0 : pluginVersionPlatform.md5Checksum) === codeArchive.md5Checksum) {
|
|
136
|
+
(0, log_1.log)('info', chalk_1.default.yellow(`Skipping upload for ${platform} - no changes detected`));
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
(0, log_1.log)('info', chalk_1.default.yellow(`Uploading files for ${platform}`));
|
|
141
|
+
yield uploadCodeArchive({
|
|
142
|
+
restApi,
|
|
143
|
+
pluginVersion,
|
|
144
|
+
platform,
|
|
145
|
+
codeArchive,
|
|
146
|
+
});
|
|
147
|
+
yield restApi.plugin.version.platform.update({
|
|
148
|
+
pluginUid: pluginVersion.pluginUid,
|
|
149
|
+
version: pluginVersion.version,
|
|
150
|
+
platform,
|
|
151
|
+
mainFile,
|
|
152
|
+
runtime,
|
|
153
|
+
md5Checksum: codeArchive.md5Checksum,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
yield codeArchive.delete();
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function uploadCodeArchive(_a) {
|
|
162
|
+
return __awaiter(this, arguments, void 0, function* ({ restApi, pluginVersion, platform, codeArchive, }) {
|
|
163
|
+
const filePath = codeArchive.filePath;
|
|
164
|
+
const fileSize = (yield fs.stat(filePath)).size;
|
|
165
|
+
const fileStream = fs.createReadStream(filePath);
|
|
166
|
+
yield restApi.plugin.version.platform.archive.upload({
|
|
167
|
+
pluginUid: pluginVersion.pluginUid,
|
|
168
|
+
version: pluginVersion.version,
|
|
169
|
+
platform,
|
|
170
|
+
md5Checksum: codeArchive.md5Checksum,
|
|
171
|
+
size: fileSize,
|
|
172
|
+
stream: fileStream,
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Generates an archive with the code for a particular platform, defined by the provided configuration.
|
|
178
|
+
*
|
|
179
|
+
* Archive is generated and stored in the runtime /tmp/signageos/plugin_scripts_builds/:uid/:version/ directory.
|
|
180
|
+
* After archive isn't needed anymore, it should be deleted using the delete method.
|
|
181
|
+
*/
|
|
182
|
+
function generatePluginPlatformCodeArchive(workDir, config, pluginVersion, platform) {
|
|
183
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
184
|
+
const buildsDir = yield ensureBuildsDirectory(pluginVersion);
|
|
185
|
+
const archiveFileName = `${platform}.zip`;
|
|
186
|
+
const archiveFilePath = path.join(buildsDir, archiveFileName);
|
|
187
|
+
yield (0, archive_1.generateZip)(workDir, config.rootDir, archiveFilePath);
|
|
188
|
+
const md5Checksum = yield (0, fileSystem_1.getFileMD5Checksum)(archiveFilePath);
|
|
189
|
+
return {
|
|
190
|
+
filePath: archiveFilePath,
|
|
191
|
+
md5Checksum,
|
|
192
|
+
delete() {
|
|
193
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
194
|
+
yield fs.unlink(archiveFilePath);
|
|
195
|
+
});
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Ensure that the runtime directory for plugin script version exists in the current working directory.
|
|
202
|
+
*
|
|
203
|
+
* This directory is used to store temporary files generated by the CLI.
|
|
204
|
+
*/
|
|
205
|
+
function ensureBuildsDirectory(pluginVersion) {
|
|
206
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
207
|
+
const runtimeDir = yield ensureRuntimeDir();
|
|
208
|
+
const buildsDir = path.join(runtimeDir, pluginVersion.pluginUid, pluginVersion.version);
|
|
209
|
+
yield fs.ensureDir(buildsDir);
|
|
210
|
+
return buildsDir;
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Ensure that the runtime directory exists in the current working directory.
|
|
215
|
+
*
|
|
216
|
+
* This directory is used to store temporary files generated by the CLI.
|
|
217
|
+
*/
|
|
218
|
+
function ensureRuntimeDir() {
|
|
219
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
const runtimeDir = path.join(os.tmpdir(), runtimeFileSystem_1.RUNTIME_DIRNAME, PLUGIN_BUILDS_DIRNAME);
|
|
221
|
+
yield fs.ensureDir(runtimeDir);
|
|
222
|
+
return runtimeDir;
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
function loadSchemas(workDir) {
|
|
226
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
227
|
+
const filePath = getConfigFilePath(workDir);
|
|
228
|
+
if (!(yield fs.pathExists(filePath))) {
|
|
229
|
+
throw new Error(`Config file schema.json not found`);
|
|
230
|
+
}
|
|
231
|
+
const fileContent = fs.readFileSync(filePath, 'utf-8');
|
|
232
|
+
return JSON.parse(fileContent);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
function getConfigFilePath(workDir) {
|
|
236
|
+
return path.join(workDir, 'schema.json');
|
|
237
|
+
}
|
|
238
|
+
exports.ConfigSchema = zod_1.default.object({
|
|
239
|
+
uid: zod_1.default.string().optional(),
|
|
240
|
+
name: zod_1.default.string(),
|
|
241
|
+
version: zod_1.default.string(),
|
|
242
|
+
description: zod_1.default.string().optional(),
|
|
243
|
+
/**
|
|
244
|
+
* Config of individual plugin script implementations for each target platform.
|
|
245
|
+
*
|
|
246
|
+
* A plugin Script is only a virtual unit that consists of multiple platform-specific scripts.
|
|
247
|
+
* This record is a mapping of platform names to their respective platform-specific scripts.
|
|
248
|
+
*/
|
|
249
|
+
platforms: zod_1.default.record(zod_1.default.string(), customScriptFacade_1.PlatformSchema),
|
|
250
|
+
configDefinition: zod_1.default.array(zod_1.default.object({}).passthrough()), // outsource validation to API because it's a bit complex
|
|
251
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.runnerGenerate = void 0;
|
|
16
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
17
|
+
const log_1 = require("@signageos/sdk/dist/Console/log");
|
|
18
|
+
const commandDefinition_1 = require("../../Command/commandDefinition");
|
|
19
|
+
const git_1 = require("../../Lib/git");
|
|
20
|
+
const customScriptFacade_1 = require("../../CustomScript/customScriptFacade");
|
|
21
|
+
const runnerGenerateFacade_1 = require("./runnerGenerateFacade");
|
|
22
|
+
exports.runnerGenerate = (0, commandDefinition_1.createCommandDefinition)({
|
|
23
|
+
name: 'generate',
|
|
24
|
+
description: 'Generates a local repository for developing a Runner',
|
|
25
|
+
optionList: [],
|
|
26
|
+
commands: [],
|
|
27
|
+
run() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
yield (0, git_1.throwErrorIfGitNotInstalled)();
|
|
30
|
+
const { targetDir, name, description } = yield (0, runnerGenerateFacade_1.askForParameters)();
|
|
31
|
+
yield (0, runnerGenerateFacade_1.downloadBoilerplateCode)(targetDir);
|
|
32
|
+
yield (0, customScriptFacade_1.addToConfigFile)(targetDir, { name, description });
|
|
33
|
+
(0, log_1.log)('info', `Runner ${chalk_1.default.green(name)} has been generated in ${chalk_1.default.green(targetDir)}.`);
|
|
34
|
+
(0, log_1.log)('info', 'Next steps:');
|
|
35
|
+
(0, log_1.log)('info', ` - Open the folder ${chalk_1.default.green(targetDir)} and read the ${chalk_1.default.green('README.md')} file.`);
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompts the user for the parameters needed to generate a runner.
|
|
3
|
+
*/
|
|
4
|
+
export declare function askForParameters(): Promise<{
|
|
5
|
+
targetDir: any;
|
|
6
|
+
name: any;
|
|
7
|
+
description: any;
|
|
8
|
+
}>;
|
|
9
|
+
/**
|
|
10
|
+
* Downloads the latest version of the boilerplate code from the GitHub repository.
|
|
11
|
+
*/
|
|
12
|
+
export declare function downloadBoilerplateCode(targetDir: string): Promise<void>;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.askForParameters = askForParameters;
|
|
49
|
+
exports.downloadBoilerplateCode = downloadBoilerplateCode;
|
|
50
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
51
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
52
|
+
const path = __importStar(require("path"));
|
|
53
|
+
const fs = __importStar(require("fs-extra"));
|
|
54
|
+
const log_1 = require("@signageos/sdk/dist/Console/log");
|
|
55
|
+
const git_1 = require("../../Lib/git");
|
|
56
|
+
/**
|
|
57
|
+
* Prompts the user for the parameters needed to generate a runner.
|
|
58
|
+
*/
|
|
59
|
+
function askForParameters() {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
const throwCanceledError = () => {
|
|
62
|
+
throw new Error('Runner generation was canceled.');
|
|
63
|
+
};
|
|
64
|
+
const { name, description } = yield (0, prompts_1.default)([
|
|
65
|
+
{
|
|
66
|
+
type: 'text',
|
|
67
|
+
name: 'name',
|
|
68
|
+
message: 'Type name',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
type: 'text',
|
|
72
|
+
name: 'description',
|
|
73
|
+
message: 'Type description',
|
|
74
|
+
},
|
|
75
|
+
], { onCancel: throwCanceledError });
|
|
76
|
+
const targetDir = name;
|
|
77
|
+
(0, log_1.log)('info', `Generating Runner with these parameters:\n` +
|
|
78
|
+
` - Directory: ${chalk_1.default.green(targetDir)}\n` +
|
|
79
|
+
` - Name: ${chalk_1.default.green(name)}\n` +
|
|
80
|
+
` - Description: ${chalk_1.default.green(description)}\n`);
|
|
81
|
+
const { confirm } = yield (0, prompts_1.default)({
|
|
82
|
+
type: 'confirm',
|
|
83
|
+
name: 'confirm',
|
|
84
|
+
message: 'Confirm',
|
|
85
|
+
});
|
|
86
|
+
if (!confirm) {
|
|
87
|
+
throwCanceledError();
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
targetDir,
|
|
91
|
+
name,
|
|
92
|
+
description,
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Downloads the latest version of the boilerplate code from the GitHub repository.
|
|
98
|
+
*/
|
|
99
|
+
function downloadBoilerplateCode(targetDir) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
// TODO: Update this URL to point to the actual runner boilerplate repository
|
|
102
|
+
const URL = 'https://github.com/signageos/runners-boilerplate';
|
|
103
|
+
yield (0, git_1.cloneGitRepository)(URL, targetDir);
|
|
104
|
+
// we just want the code, not the git history
|
|
105
|
+
yield fs.remove(path.join(targetDir, '.git'));
|
|
106
|
+
});
|
|
107
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CommandLineOptions } from '../../Command/commandDefinition';
|
|
2
|
+
export declare const OPTION_LIST: readonly [{
|
|
3
|
+
readonly name: "no-default-organization";
|
|
4
|
+
readonly type: BooleanConstructor;
|
|
5
|
+
readonly description: "Prevent using the defaultOrganizationUid from ~/.sosrc";
|
|
6
|
+
}, {
|
|
7
|
+
readonly name: "organization-uid";
|
|
8
|
+
readonly type: StringConstructor;
|
|
9
|
+
readonly description: "Organization UID";
|
|
10
|
+
}];
|
|
11
|
+
export declare const runnerUpload: {
|
|
12
|
+
name: "upload";
|
|
13
|
+
description: string;
|
|
14
|
+
optionList: readonly [{
|
|
15
|
+
readonly name: "no-default-organization";
|
|
16
|
+
readonly type: BooleanConstructor;
|
|
17
|
+
readonly description: "Prevent using the defaultOrganizationUid from ~/.sosrc";
|
|
18
|
+
}, {
|
|
19
|
+
readonly name: "organization-uid";
|
|
20
|
+
readonly type: StringConstructor;
|
|
21
|
+
readonly description: "Organization UID";
|
|
22
|
+
}];
|
|
23
|
+
commands: never[];
|
|
24
|
+
run(options: CommandLineOptions<typeof OPTION_LIST>): Promise<void>;
|
|
25
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.runnerUpload = exports.OPTION_LIST = void 0;
|
|
16
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
17
|
+
const util_1 = require("util");
|
|
18
|
+
const debug_1 = __importDefault(require("debug"));
|
|
19
|
+
const log_1 = require("@signageos/sdk/dist/Console/log");
|
|
20
|
+
const commandDefinition_1 = require("../../Command/commandDefinition");
|
|
21
|
+
const helper_1 = require("../../helper");
|
|
22
|
+
const organizationFacade_1 = require("../../Organization/organizationFacade");
|
|
23
|
+
const runnerFacede_1 = require("../runnerFacede");
|
|
24
|
+
const customScriptFacade_1 = require("../../CustomScript/customScriptFacade");
|
|
25
|
+
const Debug = (0, debug_1.default)('@signageos/cli:Runner:Upload:Command');
|
|
26
|
+
exports.OPTION_LIST = [organizationFacade_1.NO_DEFAULT_ORGANIZATION_OPTION, organizationFacade_1.ORGANIZATION_UID_OPTION];
|
|
27
|
+
exports.runnerUpload = (0, commandDefinition_1.createCommandDefinition)({
|
|
28
|
+
name: 'upload',
|
|
29
|
+
description: 'Uploads current runner version',
|
|
30
|
+
optionList: exports.OPTION_LIST,
|
|
31
|
+
commands: [],
|
|
32
|
+
run(options) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const currentDirectory = process.cwd();
|
|
35
|
+
const organizationUid = yield (0, organizationFacade_1.getOrganizationUidOrDefaultOrSelect)(options);
|
|
36
|
+
const organization = yield (0, organizationFacade_1.getOrganization)(organizationUid);
|
|
37
|
+
const restApi = yield (0, helper_1.createOrganizationRestApi)(organization);
|
|
38
|
+
const config = yield (0, customScriptFacade_1.getConfig)(currentDirectory);
|
|
39
|
+
const schema = yield (0, runnerFacede_1.loadSchemas)(currentDirectory);
|
|
40
|
+
const runnerVersion = yield (0, runnerFacede_1.ensureRunnerVersion)(restApi, config, schema);
|
|
41
|
+
for (const platform of Object.keys(config.platforms)) {
|
|
42
|
+
const platformConfig = config.platforms[platform];
|
|
43
|
+
if (!platformConfig) {
|
|
44
|
+
console.warn(`Skipping platform ${platform} due to missing configuration`);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
yield (0, runnerFacede_1.uploadCode)({
|
|
48
|
+
restApi,
|
|
49
|
+
workDir: currentDirectory,
|
|
50
|
+
platform,
|
|
51
|
+
config: platformConfig,
|
|
52
|
+
runnerVersion,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (!(0, util_1.isDeepStrictEqual)(runnerVersion.configDefinition, config.configDefinition)) {
|
|
56
|
+
Debug('Config definition is different, updating runner version.');
|
|
57
|
+
yield restApi.runner.version.update({
|
|
58
|
+
runnerUid: runnerVersion.runnerUid,
|
|
59
|
+
version: runnerVersion.version,
|
|
60
|
+
configDefinition: config.configDefinition,
|
|
61
|
+
input: schema.input,
|
|
62
|
+
output: schema.output,
|
|
63
|
+
description: config.description,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
Debug('Config definition is the same, skipping update.');
|
|
68
|
+
}
|
|
69
|
+
(0, log_1.log)('info', `Runner ${chalk_1.default.green(config.name)} version ${chalk_1.default.green(config.version)} has been uploaded.`);
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare const runner: {
|
|
2
|
+
name: "runner";
|
|
3
|
+
description: string;
|
|
4
|
+
optionList: never[];
|
|
5
|
+
commands: ({
|
|
6
|
+
name: "generate";
|
|
7
|
+
description: string;
|
|
8
|
+
optionList: never[];
|
|
9
|
+
commands: never[];
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
} | {
|
|
12
|
+
name: "upload";
|
|
13
|
+
description: string;
|
|
14
|
+
optionList: readonly [{
|
|
15
|
+
readonly name: "no-default-organization";
|
|
16
|
+
readonly type: BooleanConstructor;
|
|
17
|
+
readonly description: "Prevent using the defaultOrganizationUid from ~/.sosrc";
|
|
18
|
+
}, {
|
|
19
|
+
readonly name: "organization-uid";
|
|
20
|
+
readonly type: StringConstructor;
|
|
21
|
+
readonly description: "Organization UID";
|
|
22
|
+
}];
|
|
23
|
+
commands: never[];
|
|
24
|
+
run(options: import("../Command/commandDefinition").CommandLineOptions<typeof import("./Upload/runnerUploadCommand").OPTION_LIST>): Promise<void>;
|
|
25
|
+
})[];
|
|
26
|
+
run(): Promise<never>;
|
|
27
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.runner = void 0;
|
|
13
|
+
const commandDefinition_1 = require("../Command/commandDefinition");
|
|
14
|
+
const runnerGenerateCommand_1 = require("./Generate/runnerGenerateCommand");
|
|
15
|
+
const runnerUploadCommand_1 = require("./Upload/runnerUploadCommand");
|
|
16
|
+
exports.runner = (0, commandDefinition_1.createCommandDefinition)({
|
|
17
|
+
name: 'runner',
|
|
18
|
+
description: 'Runner management',
|
|
19
|
+
optionList: [],
|
|
20
|
+
commands: [runnerGenerateCommand_1.runnerGenerate, runnerUploadCommand_1.runnerUpload],
|
|
21
|
+
run() {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
throw new Error('Unknown command');
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import RestApi from '@signageos/sdk/dist/RestApi/RestApi';
|
|
2
|
+
import { PlatformConfig } from '../CustomScript/customScriptFacade';
|
|
3
|
+
import { IRunnerVersion } from '@signageos/sdk/dist/RestApi/Runner/Version/IRunnerVersion';
|
|
4
|
+
import z from 'zod';
|
|
5
|
+
import { ConfigSchema } from '../Plugin/pluginFacade';
|
|
6
|
+
export declare function ensureRunnerVersion(restApi: RestApi, config: RunnerConfig, schema: any): Promise<IRunnerVersion>;
|
|
7
|
+
export declare function uploadCode({ restApi, workDir, platform, config, runnerVersion, }: {
|
|
8
|
+
restApi: RestApi;
|
|
9
|
+
workDir: string;
|
|
10
|
+
platform: string;
|
|
11
|
+
config: PlatformConfig;
|
|
12
|
+
runnerVersion: IRunnerVersion;
|
|
13
|
+
}): Promise<void>;
|
|
14
|
+
export declare function loadSchemas(workDir: string): Promise<any>;
|
|
15
|
+
export type RunnerConfig = z.infer<typeof ConfigSchema>;
|