@supernovaio/cli 1.1.1 → 1.1.2
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/commands/describe-design-system.js +1 -1
- package/dist/commands/describe-workspaces.js +1 -1
- package/dist/commands/publish-documentation.d.ts +1 -0
- package/dist/commands/publish-documentation.js +35 -7
- package/dist/commands/run-local-exporter.js +5 -2
- package/dist/commands/sync-tokens.js +5 -2
- package/dist/index.d.ts +1 -1
- package/dist/utils/common.d.ts +1 -0
- package/dist/utils/common.js +7 -0
- package/dist/utils/sdk.js +6 -4
- package/oclif.manifest.json +7 -1
- package/package.json +2 -1
|
@@ -35,7 +35,7 @@ class DescribeDesignSystem extends core_1.Command {
|
|
|
35
35
|
this.log(`\n↳ Design system "${designSystem.name}", id: ${designSystem.id}`.cyan);
|
|
36
36
|
for (let brand of brands) {
|
|
37
37
|
this.log(` ↳ Brand: "${brand.name}", id: ${brand.id}`);
|
|
38
|
-
let brandThemes = themes.filter(
|
|
38
|
+
let brandThemes = themes.filter(t => t.brandId === brand.id);
|
|
39
39
|
if (brandThemes.length > 0) {
|
|
40
40
|
for (let theme of brandThemes) {
|
|
41
41
|
this.log(` ↳ Theme: "${theme.name}", id: ${theme.id}`);
|
|
@@ -45,7 +45,7 @@ class DescribeWorkspaces extends core_1.Command {
|
|
|
45
45
|
let themes = await instance.tokens.getTokenThemes(id);
|
|
46
46
|
for (let brand of brands) {
|
|
47
47
|
this.log(` ↳ Brand: "${brand.name}", id: ${brand.id}`);
|
|
48
|
-
let brandThemes = themes.filter(
|
|
48
|
+
let brandThemes = themes.filter(t => t.brandId === brand.id);
|
|
49
49
|
if (brandThemes.length > 0) {
|
|
50
50
|
for (let theme of brandThemes) {
|
|
51
51
|
this.log(` ↳ Theme: "${theme.name}", id: ${theme.id}`.gray);
|
|
@@ -12,6 +12,7 @@ export declare class PublishDocumentation extends Command {
|
|
|
12
12
|
target: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
13
13
|
environment: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
14
14
|
proxyUrl: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
15
|
+
awaitPublishJob: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
15
16
|
};
|
|
16
17
|
run(): Promise<void>;
|
|
17
18
|
}
|
|
@@ -15,6 +15,7 @@ const types_1 = require("../types/types");
|
|
|
15
15
|
const sdk_1 = require("../utils/sdk");
|
|
16
16
|
require("colors");
|
|
17
17
|
const sdk_2 = require("@supernovaio/sdk");
|
|
18
|
+
const common_1 = require("../utils/common");
|
|
18
19
|
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
|
|
19
20
|
// MARK: - Definition
|
|
20
21
|
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
|
|
@@ -26,6 +27,7 @@ class PublishDocumentation extends core_1.Command {
|
|
|
26
27
|
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
|
|
27
28
|
// MARK: - Command runtime
|
|
28
29
|
async run() {
|
|
30
|
+
var _a;
|
|
29
31
|
try {
|
|
30
32
|
const { flags } = await this.parse(PublishDocumentation);
|
|
31
33
|
const environment = tryParseDocsEnvironment(flags.target);
|
|
@@ -34,19 +36,35 @@ class PublishDocumentation extends core_1.Command {
|
|
|
34
36
|
this.error(`Unknown target ${flags.target}, must be one of [${supportedEnvs.join(", ")}]`);
|
|
35
37
|
}
|
|
36
38
|
// Get workspace -> design system –> version
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
const { instance, id, designSystem } = await (0, sdk_1.getWritableVersion)(flags);
|
|
40
|
+
const publishJob = await instance.documentation.publishDrafts(id, environment, {
|
|
39
41
|
pagePersistentIds: [],
|
|
40
42
|
groupPersistentIds: [],
|
|
41
43
|
});
|
|
42
|
-
if (
|
|
44
|
+
if (!((_a = flags.awaitPublishJob) !== null && _a !== void 0 ? _a : true)) {
|
|
45
|
+
this.log(`Publishing documentation in ${designSystem.name} has started, job await is disabled, exiting...`);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
this.log(`Publishing documentation in ${designSystem.name}...`);
|
|
49
|
+
}
|
|
50
|
+
// Timeout is roughly 30 minutes
|
|
51
|
+
for (let i = 0; i < 30 * 60; i++) {
|
|
52
|
+
await (0, common_1.sleep)(1000);
|
|
53
|
+
const updatedJob = await instance.documentation.getDocumentationBuild(designSystem.workspaceId, publishJob.id);
|
|
54
|
+
if (isJobStatusDone(updatedJob.status))
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
if (publishJob.status === "Success") {
|
|
43
58
|
this.log("\nDone: Documentation queued for publishing".green);
|
|
44
59
|
}
|
|
45
|
-
else if (
|
|
46
|
-
|
|
60
|
+
else if (publishJob.status === "Failed") {
|
|
61
|
+
throw new Error(`Documentation publish failed`);
|
|
47
62
|
}
|
|
48
|
-
else if (
|
|
49
|
-
throw new Error(`Documentation publish
|
|
63
|
+
else if (publishJob.status === "Timeout") {
|
|
64
|
+
throw new Error(`Documentation publish timed out`);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
throw new Error(`Error awaiting publish job`);
|
|
50
68
|
}
|
|
51
69
|
}
|
|
52
70
|
catch (error) {
|
|
@@ -86,6 +104,13 @@ PublishDocumentation.flags = {
|
|
|
86
104
|
hidden: true,
|
|
87
105
|
required: false,
|
|
88
106
|
}),
|
|
107
|
+
awaitPublishJob: core_1.Flags.boolean({
|
|
108
|
+
description: "Whether to block the process until the publishing is done. " +
|
|
109
|
+
"Setting the flag to false will exit with success as long as documentation publish was successfully triggered, " +
|
|
110
|
+
"but before the publish is completed. Setting the flag to true will exit once the publish is complete and will " +
|
|
111
|
+
"throw if documentation publish is not successful.",
|
|
112
|
+
default: true,
|
|
113
|
+
}),
|
|
89
114
|
};
|
|
90
115
|
function tryParseDocsEnvironment(targetArg) {
|
|
91
116
|
switch (targetArg.toLowerCase()) {
|
|
@@ -97,3 +122,6 @@ function tryParseDocsEnvironment(targetArg) {
|
|
|
97
122
|
return null;
|
|
98
123
|
}
|
|
99
124
|
}
|
|
125
|
+
function isJobStatusDone(status) {
|
|
126
|
+
return (status === sdk_2.ExportBuildStatus.Failed || status === sdk_2.ExportBuildStatus.Success || status === sdk_2.ExportBuildStatus.Timeout);
|
|
127
|
+
}
|
|
@@ -134,7 +134,7 @@ class RunLocalExporter extends core_1.Command {
|
|
|
134
134
|
const chunkSize = 4;
|
|
135
135
|
for (let i = 0; i < result.emittedFiles.length; i += chunkSize) {
|
|
136
136
|
const chunk = result.emittedFiles.slice(i, i + chunkSize);
|
|
137
|
-
await Promise.all(chunk.map(
|
|
137
|
+
await Promise.all(chunk.map(file => processFile(file)));
|
|
138
138
|
}
|
|
139
139
|
// Write all files from the temporary structure to the filesystem as a final step - this is to avoid partial writes
|
|
140
140
|
filesToWrite.forEach(({ filePath, content }) => {
|
|
@@ -200,7 +200,10 @@ RunLocalExporter.flags = {
|
|
|
200
200
|
apiKey: core_1.Flags.string({ description: "API key to use for accessing Supernova instance", required: true }),
|
|
201
201
|
designSystemId: core_1.Flags.string({ description: "Design System to export from", required: true }),
|
|
202
202
|
exporterDir: core_1.Flags.string({ description: "Path to exporter package", required: true }),
|
|
203
|
-
outputDir: core_1.Flags.string({
|
|
203
|
+
outputDir: core_1.Flags.string({
|
|
204
|
+
description: "Path to output folder. Must be empty, unless `forceClearOutputDir` is set",
|
|
205
|
+
required: true,
|
|
206
|
+
}),
|
|
204
207
|
themeId: core_1.Flags.string({
|
|
205
208
|
description: "Theme to export. Will only be used when exporter has usesThemes: true, and is optional",
|
|
206
209
|
required: false,
|
|
@@ -46,7 +46,7 @@ class SyncDesignTokens extends core_1.Command {
|
|
|
46
46
|
let tokenDefinition = flags.tokenDirPath
|
|
47
47
|
? await dataLoader.loadTokensFromDirectory(flags.tokenDirPath, flags.configFilePath)
|
|
48
48
|
: await dataLoader.loadTokensFromPath(flags.tokenFilePath);
|
|
49
|
-
const response = await instance.versions.writeTokenStudioData(id, buildData(tokenDefinition));
|
|
49
|
+
const response = (await instance.versions.writeTokenStudioData(id, buildData(tokenDefinition)));
|
|
50
50
|
if (((_a = response === null || response === void 0 ? void 0 : response.result) === null || _a === void 0 ? void 0 : _a.logs) && response.result.logs.length > 0) {
|
|
51
51
|
for (const log of response.result.logs) {
|
|
52
52
|
this.log(log);
|
|
@@ -94,7 +94,10 @@ SyncDesignTokens.flags = {
|
|
|
94
94
|
exactlyOne: ["tokenDirPath", "tokenFilePath"],
|
|
95
95
|
}),
|
|
96
96
|
configFilePath: core_1.Flags.string({ description: "Path to configuration JSON file", required: true, exclusive: [] }),
|
|
97
|
-
apiUrl: core_1.Flags.string({
|
|
97
|
+
apiUrl: core_1.Flags.string({
|
|
98
|
+
description: "API url to use for accessing Supernova instance, would ignore defaults",
|
|
99
|
+
hidden: true,
|
|
100
|
+
}),
|
|
98
101
|
environment: core_1.Flags.string({
|
|
99
102
|
description: "When set, CLI will target a specific environment",
|
|
100
103
|
hidden: true,
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { run } from
|
|
1
|
+
export { run } from "@oclif/core";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sleep(ms: number): Promise<void>;
|
package/dist/utils/sdk.js
CHANGED
|
@@ -13,7 +13,9 @@ async function getWritableVersion(flags, apiVersion = "v2") {
|
|
|
13
13
|
throw new Error(`Design System ID must not be empty`);
|
|
14
14
|
}
|
|
15
15
|
// Create instance for prod / dev
|
|
16
|
-
let apiUrl = flags.apiUrl && flags.apiUrl.length > 0
|
|
16
|
+
let apiUrl = flags.apiUrl && flags.apiUrl.length > 0
|
|
17
|
+
? flags.apiUrl
|
|
18
|
+
: (0, network_1.environmentAPI)(flags.environment, apiVersion);
|
|
17
19
|
let instance = new sdk_1.Supernova(flags.apiKey, { apiUrl, bypassEnvFetch: true, proxyUrl: flags.proxyUrl });
|
|
18
20
|
let designSystem = await instance.designSystems.designSystem(flags.designSystemId);
|
|
19
21
|
if (!designSystem) {
|
|
@@ -26,12 +28,12 @@ async function getWritableVersion(flags, apiVersion = "v2") {
|
|
|
26
28
|
let id = {
|
|
27
29
|
designSystemId: flags.designSystemId,
|
|
28
30
|
versionId: version.id,
|
|
29
|
-
workspaceId: designSystem.workspaceId
|
|
31
|
+
workspaceId: designSystem.workspaceId,
|
|
30
32
|
};
|
|
31
33
|
let brand = null;
|
|
32
34
|
if (flags.brandId) {
|
|
33
35
|
const brands = await instance.brands.getBrands(id);
|
|
34
|
-
brand = (_a = brands.find(
|
|
36
|
+
brand = (_a = brands.find(brand => brand.id === flags.brandId || brand.idInVersion === flags.brandId)) !== null && _a !== void 0 ? _a : null;
|
|
35
37
|
if (!brand) {
|
|
36
38
|
throw new Error(`Brand ${flags.brandId} not found in specified design system`);
|
|
37
39
|
}
|
|
@@ -39,7 +41,7 @@ async function getWritableVersion(flags, apiVersion = "v2") {
|
|
|
39
41
|
let theme = null;
|
|
40
42
|
if (flags.themeId) {
|
|
41
43
|
const themes = await instance.tokens.getTokenThemes(id);
|
|
42
|
-
theme = (_b = themes.find(
|
|
44
|
+
theme = (_b = themes.find(theme => theme.id === flags.themeId || theme.idInVersion === flags.themeId)) !== null && _b !== void 0 ? _b : null;
|
|
43
45
|
if (!theme) {
|
|
44
46
|
throw new Error(`Theme ${flags.themeId} not found in specified brand`);
|
|
45
47
|
}
|
package/oclif.manifest.json
CHANGED
|
@@ -186,6 +186,12 @@
|
|
|
186
186
|
"hasDynamicHelp": false,
|
|
187
187
|
"multiple": false,
|
|
188
188
|
"type": "option"
|
|
189
|
+
},
|
|
190
|
+
"awaitPublishJob": {
|
|
191
|
+
"description": "Whether to block the process until the publishing is done. Setting the flag to false will exit with success as long as documentation publish was successfully triggered, but before the publish is completed. Setting the flag to true will exit once the publish is complete and will throw if documentation publish is not successful.",
|
|
192
|
+
"name": "awaitPublishJob",
|
|
193
|
+
"allowNo": false,
|
|
194
|
+
"type": "boolean"
|
|
189
195
|
}
|
|
190
196
|
},
|
|
191
197
|
"hasDynamicHelp": false,
|
|
@@ -405,5 +411,5 @@
|
|
|
405
411
|
]
|
|
406
412
|
}
|
|
407
413
|
},
|
|
408
|
-
"version": "1.1.
|
|
414
|
+
"version": "1.1.2"
|
|
409
415
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supernovaio/cli",
|
|
3
3
|
"description": "Supernova.io Command Line Interface",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.2",
|
|
5
5
|
"author": "Supernova.io",
|
|
6
6
|
"homepage": "https://supernova.io/",
|
|
7
7
|
"keywords": [
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"globby": "^11",
|
|
57
57
|
"mocha": "^9",
|
|
58
58
|
"oclif": "4.14.15",
|
|
59
|
+
"prettier": "^3.3.3",
|
|
59
60
|
"shx": "^0.3.3",
|
|
60
61
|
"ts-node": "10.9.1",
|
|
61
62
|
"tslib": "^2.3.1",
|