From 5c4bed246efe0adac80e43641a33cc9b3bec35e5 Mon Sep 17 00:00:00 2001 From: Artem Ufimtcev Date: Fri, 8 Nov 2024 15:10:58 +0100 Subject: [PATCH 1/5] Bump SDK, add page drafts support --- .prettierrc | 6 +-- package-lock.json | 23 ++++++----- package.json | 2 +- src/commands/publish-documentation.ts | 59 +++++++++++++++++++-------- yarn.lock | 12 +++--- 5 files changed, 64 insertions(+), 38 deletions(-) diff --git a/.prettierrc b/.prettierrc index a9278e4..8a8d013 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,5 @@ { - "printWidth": 120, - "arrowParens": "avoid", - "tabWidth": 4 + "printWidth": 120, + "arrowParens": "avoid", + "tabWidth": 2 } diff --git a/package-lock.json b/package-lock.json index 6921199..36e3be1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "@oclif/plugin-help": "6.2.8", "@oclif/plugin-plugins": "5.4.2", "@supernova-studio/pulsar-core": "2.3.21", - "@supernovaio/sdk": "2.0.12", + "@supernovaio/sdk": "^2.0.27", "axios": "^1.7.7", "colors": "^1.4.0", "minimatch": "^9.0.5", @@ -5337,16 +5337,17 @@ } }, "node_modules/@supernovaio/sdk": { - "version": "2.0.12", - "resolved": "https://registry.npmjs.org/@supernovaio/sdk/-/sdk-2.0.12.tgz", - "integrity": "sha512-gE3rvLGS/cyakJ51QKRX7JmnUuGaImVQRYwQJjdQdtkGaKI4e9rcuZxk5RGOIJkCmH8so6ZOqDtrezqkB4NlZA==", + "version": "2.0.27", + "resolved": "https://registry.npmjs.org/@supernovaio/sdk/-/sdk-2.0.27.tgz", + "integrity": "sha512-9hxYBpM2DGnr1aGOuozo3txKwtQizlugQZ2v3RqmwxWPBFaOpA75C5Kv5FnDrrC/jxfoNYB7q2FT7jR3fcTiow==", "bundleDependencies": [ "@supernova-studio/client", "@supernova-studio/model" ], + "license": "MIT", "dependencies": { - "@supernova-studio/client": "^0.4.6", - "@supernova-studio/model": "^0.4.1", + "@supernova-studio/client": "0.55.27", + "@supernova-studio/model": "0.55.27", "abab": "^2.0.5", "async-mutex": "^0.3.1", "color-string": "^1.9.1", @@ -20371,12 +20372,12 @@ "integrity": "sha512-0Cfy6XXUDJ5JV2Yxz4alQEmnQiptSl5fDDfpYG6bvTqZk3ZPjAWMCTd0D7aScltKo02P06Wgj240HStoxatKAA==" }, "@supernovaio/sdk": { - "version": "2.0.12", - "resolved": "https://registry.npmjs.org/@supernovaio/sdk/-/sdk-2.0.12.tgz", - "integrity": "sha512-gE3rvLGS/cyakJ51QKRX7JmnUuGaImVQRYwQJjdQdtkGaKI4e9rcuZxk5RGOIJkCmH8so6ZOqDtrezqkB4NlZA==", + "version": "2.0.27", + "resolved": "https://registry.npmjs.org/@supernovaio/sdk/-/sdk-2.0.27.tgz", + "integrity": "sha512-9hxYBpM2DGnr1aGOuozo3txKwtQizlugQZ2v3RqmwxWPBFaOpA75C5Kv5FnDrrC/jxfoNYB7q2FT7jR3fcTiow==", "requires": { - "@supernova-studio/client": "^0.4.6", - "@supernova-studio/model": "^0.4.1", + "@supernova-studio/client": "0.55.27", + "@supernova-studio/model": "0.55.27", "abab": "^2.0.5", "async-mutex": "^0.3.1", "color-string": "^1.9.1", diff --git a/package.json b/package.json index 7fd9eec..d97ef1a 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "@oclif/plugin-help": "6.2.8", "@oclif/plugin-plugins": "5.4.2", "@supernova-studio/pulsar-core": "2.3.21", - "@supernovaio/sdk": "2.0.12", + "@supernovaio/sdk": "^2.0.27", "axios": "^1.7.7", "colors": "^1.4.0", "minimatch": "^9.0.5", diff --git a/src/commands/publish-documentation.ts b/src/commands/publish-documentation.ts index 906315d..d522b42 100644 --- a/src/commands/publish-documentation.ts +++ b/src/commands/publish-documentation.ts @@ -9,10 +9,11 @@ // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- // MARK: - Imports -import { Command, Flags } from "@oclif/core" -import { Environment, ErrorCode } from "../types/types" -import { getWritableVersion } from "../utils/sdk" -import "colors" +import { Command, Flags } from "@oclif/core"; +import { Environment, ErrorCode } from "../types/types"; +import { getWritableVersion } from "../utils/sdk"; +import "colors"; +import { DocumentationEnvironment } from "@supernovaio/sdk"; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- // MARK: - Definition @@ -29,20 +30,24 @@ export class PublishDocumentation extends Command { // MARK: - Command configuration // Command help description - static description = "Publish latest version of the documentation" + static description = "Publish latest version of the documentation"; // Examples how to use the command - static examples = [`$ @supernovaio/cli publish-documentation --apiKey="{xxx-xxx-xxx}" --designSystemId="{1234}"`] + static examples = [`$ @supernovaio/cli publish-documentation --apiKey="{xxx-xxx-xxx}" --designSystemId="{1234}"`]; // How this command can be run - static aliases: ["publish-documentation"] + static aliases: ["publish-documentation"]; // Static flags to enable / disable features static flags = { apiKey: Flags.string({ description: "API key to use for accessing Supernova instance", required: true }), designSystemId: Flags.string({ description: "Design System to publish the documentation", required: true }), dev: Flags.boolean({ description: "When enabled, CLI will target dev server", hidden: true, default: false }), - target: Flags.string({ description: "Environment to use for publishing: Live or Preview", required: false, default: "Live" }), + target: Flags.string({ + description: "Environment to use for publishing: Live or Preview", + required: false, + default: "Live", + }), environment: Flags.string({ description: "When set, CLI will target a specific environment", hidden: true, @@ -55,32 +60,52 @@ export class PublishDocumentation extends Command { hidden: true, required: false, }), - } + }; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- // MARK: - Command runtime async run(): Promise { try { - const { flags } = await this.parse(PublishDocumentation) + const { flags } = await this.parse(PublishDocumentation); + + const environment = tryParseDocsEnvironment(flags.target); + if (!environment) { + const supportedEnvs = [DocumentationEnvironment.live, DocumentationEnvironment.preview]; + this.error(`Unknown target ${flags.target}, must be one of [${supportedEnvs.join(", ")}]`); + } // Get workspace -> design system –> version - let { instance, id } = await getWritableVersion(flags) - let documentation = await instance.documentation.getDocumentation(id) - let result = await instance.documentation.publish(id, flags.target as any) + let { instance, id } = await getWritableVersion(flags); + let result = await instance.documentation.publishDrafts(id, environment, { + pagePersistentIds: [], + groupPersistentIds: [], + }); if (result.status === "Success") { - this.log("\nDone: Documentation queued for publishing".green) + this.log("\nDone: Documentation queued for publishing".green); } else if (result.status === "InProgress") { - this.log("\n Done: Skipped documentation publish as another build is already in progress".green) + this.log("\n Done: Skipped documentation publish as another build is already in progress".green); } else if (result.status === "Failed") { - throw new Error(`Documentation publish failed with unknown failure`) + throw new Error(`Documentation publish failed with unknown failure`); } } catch (error) { // Catch general error this.error(`Publishing documentation failed: ${error}`.red, { code: ErrorCode.documentationPublishingFailed, - }) + }); } } } + +function tryParseDocsEnvironment(targetArg: string) { + switch (targetArg.toLowerCase()) { + case "live": + return DocumentationEnvironment.live; + case "preview": + return DocumentationEnvironment.preview; + + default: + return null; + } +} diff --git a/yarn.lock b/yarn.lock index b22ac5e..a9dcf10 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3028,13 +3028,13 @@ resolved "https://registry.npmjs.org/@supernova-studio/simple-parse-github-url/-/simple-parse-github-url-1.0.0.tgz" integrity sha512-0Cfy6XXUDJ5JV2Yxz4alQEmnQiptSl5fDDfpYG6bvTqZk3ZPjAWMCTd0D7aScltKo02P06Wgj240HStoxatKAA== -"@supernovaio/sdk@2.0.12": - version "2.0.12" - resolved "https://registry.npmjs.org/@supernovaio/sdk/-/sdk-2.0.12.tgz" - integrity sha512-gE3rvLGS/cyakJ51QKRX7JmnUuGaImVQRYwQJjdQdtkGaKI4e9rcuZxk5RGOIJkCmH8so6ZOqDtrezqkB4NlZA== +"@supernovaio/sdk@^2.0.27": + version "2.0.27" + resolved "https://registry.npmjs.org/@supernovaio/sdk/-/sdk-2.0.27.tgz" + integrity sha512-9hxYBpM2DGnr1aGOuozo3txKwtQizlugQZ2v3RqmwxWPBFaOpA75C5Kv5FnDrrC/jxfoNYB7q2FT7jR3fcTiow== dependencies: - "@supernova-studio/client" "^0.4.6" - "@supernova-studio/model" "^0.4.1" + "@supernova-studio/client" "0.55.27" + "@supernova-studio/model" "0.55.27" abab "^2.0.5" async-mutex "^0.3.1" color-string "^1.9.1" From 055dbfd1333150e7e819ed637faf2d2f7a624f2e Mon Sep 17 00:00:00 2001 From: Artem Ufimtcev Date: Fri, 8 Nov 2024 15:12:13 +0100 Subject: [PATCH 2/5] Formatting --- .prettierrc | 1 + src/commands/publish-documentation.ts | 44 +++++++++++++-------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/.prettierrc b/.prettierrc index 8a8d013..7c14910 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,6 @@ { "printWidth": 120, "arrowParens": "avoid", + "semi": false, "tabWidth": 2 } diff --git a/src/commands/publish-documentation.ts b/src/commands/publish-documentation.ts index d522b42..a2a049d 100644 --- a/src/commands/publish-documentation.ts +++ b/src/commands/publish-documentation.ts @@ -9,11 +9,11 @@ // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- // MARK: - Imports -import { Command, Flags } from "@oclif/core"; -import { Environment, ErrorCode } from "../types/types"; -import { getWritableVersion } from "../utils/sdk"; -import "colors"; -import { DocumentationEnvironment } from "@supernovaio/sdk"; +import { Command, Flags } from "@oclif/core" +import { Environment, ErrorCode } from "../types/types" +import { getWritableVersion } from "../utils/sdk" +import "colors" +import { DocumentationEnvironment } from "@supernovaio/sdk" // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- // MARK: - Definition @@ -30,13 +30,13 @@ export class PublishDocumentation extends Command { // MARK: - Command configuration // Command help description - static description = "Publish latest version of the documentation"; + static description = "Publish latest version of the documentation" // Examples how to use the command - static examples = [`$ @supernovaio/cli publish-documentation --apiKey="{xxx-xxx-xxx}" --designSystemId="{1234}"`]; + static examples = [`$ @supernovaio/cli publish-documentation --apiKey="{xxx-xxx-xxx}" --designSystemId="{1234}"`] // How this command can be run - static aliases: ["publish-documentation"]; + static aliases: ["publish-documentation"] // Static flags to enable / disable features static flags = { @@ -60,40 +60,40 @@ export class PublishDocumentation extends Command { hidden: true, required: false, }), - }; + } // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- // MARK: - Command runtime async run(): Promise { try { - const { flags } = await this.parse(PublishDocumentation); + const { flags } = await this.parse(PublishDocumentation) - const environment = tryParseDocsEnvironment(flags.target); + const environment = tryParseDocsEnvironment(flags.target) if (!environment) { - const supportedEnvs = [DocumentationEnvironment.live, DocumentationEnvironment.preview]; - this.error(`Unknown target ${flags.target}, must be one of [${supportedEnvs.join(", ")}]`); + const supportedEnvs = [DocumentationEnvironment.live, DocumentationEnvironment.preview] + this.error(`Unknown target ${flags.target}, must be one of [${supportedEnvs.join(", ")}]`) } // Get workspace -> design system –> version - let { instance, id } = await getWritableVersion(flags); + let { instance, id } = await getWritableVersion(flags) let result = await instance.documentation.publishDrafts(id, environment, { pagePersistentIds: [], groupPersistentIds: [], - }); + }) if (result.status === "Success") { - this.log("\nDone: Documentation queued for publishing".green); + this.log("\nDone: Documentation queued for publishing".green) } else if (result.status === "InProgress") { - this.log("\n Done: Skipped documentation publish as another build is already in progress".green); + this.log("\n Done: Skipped documentation publish as another build is already in progress".green) } else if (result.status === "Failed") { - throw new Error(`Documentation publish failed with unknown failure`); + throw new Error(`Documentation publish failed with unknown failure`) } } catch (error) { // Catch general error this.error(`Publishing documentation failed: ${error}`.red, { code: ErrorCode.documentationPublishingFailed, - }); + }) } } } @@ -101,11 +101,11 @@ export class PublishDocumentation extends Command { function tryParseDocsEnvironment(targetArg: string) { switch (targetArg.toLowerCase()) { case "live": - return DocumentationEnvironment.live; + return DocumentationEnvironment.live case "preview": - return DocumentationEnvironment.preview; + return DocumentationEnvironment.preview default: - return null; + return null } } From 7188daeb97d031f9ef8e9960407f35ccba4fadb0 Mon Sep 17 00:00:00 2001 From: Artem Ufimtcev Date: Fri, 8 Nov 2024 15:18:25 +0100 Subject: [PATCH 3/5] Fix inconsistencies with the latest SDK --- src/utils/figma-tokens-data-loader.ts | 150 +++++++++++--------------- 1 file changed, 65 insertions(+), 85 deletions(-) diff --git a/src/utils/figma-tokens-data-loader.ts b/src/utils/figma-tokens-data-loader.ts index 46b00e5..fb5f9c1 100644 --- a/src/utils/figma-tokens-data-loader.ts +++ b/src/utils/figma-tokens-data-loader.ts @@ -3,27 +3,26 @@ import { DTPluginToSupernovaSettings, DTPluginToSupernovaMapPack, DTPluginToSupernovaMappingFile, - DTPluginToSupernovaMapType + DTPluginToSupernovaMapType, + DTPluginPreciseCopyStrategy, + DTPluginThemeOverrideStrategy, } from "@supernovaio/sdk" -import * as fs from 'fs' -const path = require('path') +import * as fs from "fs" +const path = require("path") export class FigmaTokensDataLoader { - /** Load token definitions from path */ async loadTokensFromPath(pathToFile: string): Promise { try { if (!(fs.existsSync(pathToFile) && fs.lstatSync(pathToFile).isFile())) { - throw Error( - `Provided token file directory ${pathToFile} is not a file or doesn't exist` - ) + throw Error(`Provided token file directory ${pathToFile} is not a file or doesn't exist`) } - let definition = fs.readFileSync(pathToFile, 'utf8') + let definition = fs.readFileSync(pathToFile, "utf8") let parsedDefinition = this.parseDefinition(definition) return parsedDefinition } catch (error) { - throw new Error('Unable to load JSON definition file: ' + error) + throw new Error("Unable to load JSON definition file: " + error) } } @@ -32,16 +31,14 @@ export class FigmaTokensDataLoader { let fullStructuredObject: Record = {} if (!(fs.existsSync(pathToDirectory) && fs.lstatSync(pathToDirectory).isDirectory())) { - throw new Error( - `Provided data directory ${pathToDirectory} is not a directory or doesn't exist` - ) + throw new Error(`Provided data directory ${pathToDirectory} is not a directory or doesn't exist`) } let jsonPaths = this.getAllJSONFiles(pathToDirectory) for (let path of jsonPaths) { - if (path.endsWith('json') && path !== settingsPath && !path.includes('$')) { + if (path.endsWith("json") && path !== settingsPath && !path.includes("$")) { let result = await this.loadObjectFile(path) - if (typeof result === 'object') { + if (typeof result === "object") { // let name = this.getFileNameWithoutExtension(path) let name = this.getSetKey(path, pathToDirectory) fullStructuredObject[name] = result @@ -50,22 +47,22 @@ export class FigmaTokensDataLoader { } // Try to load themes, if any - let themePath = pathToDirectory + '/' + '$themes.json' + let themePath = pathToDirectory + "/" + "$themes.json" if (fs.existsSync(themePath)) { let themes = await this.loadObjectFile(themePath) - fullStructuredObject['$themes'] = themes + fullStructuredObject["$themes"] = themes } // Try to load metadata, if any - let metadataPath = pathToDirectory + '/' + '$metadata.json' + let metadataPath = pathToDirectory + "/" + "$metadata.json" if (fs.existsSync(metadataPath)) { let metadata = await this.loadObjectFile(metadataPath) - fullStructuredObject['$metadata'] = metadata + fullStructuredObject["$metadata"] = metadata } return fullStructuredObject } catch (error) { - throw new Error('Unable to load JSON definition file: ' + error) + throw new Error("Unable to load JSON definition file: " + error) } } @@ -79,7 +76,7 @@ export class FigmaTokensDataLoader { if (fileStat.isDirectory()) { jsonFiles.push(...this.getAllJSONFiles(filePath)) - } else if (fileStat.isFile() && filePath.endsWith('.json')) { + } else if (fileStat.isFile() && filePath.endsWith(".json")) { jsonFiles.push(filePath) } } @@ -101,9 +98,7 @@ export class FigmaTokensDataLoader { return jsonFilePath.substring(loadedDirectory.length + 1, jsonFilePath.length - 5) } - loadConfigFromPath( - pathToFile: string - ): { + loadConfigFromPath(pathToFile: string): { mapping: DTPluginToSupernovaMapPack settings: DTPluginToSupernovaSettings } { @@ -112,98 +107,89 @@ export class FigmaTokensDataLoader { this.weakValidateMapping(parsedDefinition) return this.processFileToMapping(parsedDefinition) } catch (error) { - throw new Error('Unable to load JSON definition file: ' + error) + throw new Error("Unable to load JSON definition file: " + error) } } loadConfigFromPathAsIs(pathToFile: string): DTPluginToSupernovaMappingFile { try { if (!(fs.existsSync(pathToFile) && fs.lstatSync(pathToFile).isFile())) { - throw new Error( - `Provided configuration file directory ${pathToFile} is not a file or doesn't exist` - ) + throw new Error(`Provided configuration file directory ${pathToFile} is not a file or doesn't exist`) } - let definition = fs.readFileSync(pathToFile, 'utf8') + let definition = fs.readFileSync(pathToFile, "utf8") let parsedDefinition = this.parseDefinition(definition) as DTPluginToSupernovaMappingFile return parsedDefinition } catch (error) { - throw new Error('Unable to load JSON definition file: ' + error) + throw new Error("Unable to load JSON definition file: " + error) } } private weakValidateMapping(mapping: DTPluginToSupernovaMappingFile) { if ( - !mapping.hasOwnProperty('mode') || - typeof mapping.mode !== 'string' || - (mapping.mode !== 'multi-file' && mapping.mode !== 'single-file') + !mapping.hasOwnProperty("mode") || + typeof mapping.mode !== "string" || + (mapping.mode !== "multi-file" && mapping.mode !== "single-file") ) { - throw new Error( - 'Unable to load mapping file: `mode` must be provided [single-file or multi-file]`' - ) + throw new Error("Unable to load mapping file: `mode` must be provided [single-file or multi-file]`") } if (!mapping.mapping || !(mapping.mapping instanceof Array)) { - throw new Error('Unable to load mapping file: `mapping` key must be present and array.') + throw new Error("Unable to load mapping file: `mapping` key must be present and array.") } let mapPack = mapping.mapping for (let map of mapPack) { - if (typeof map !== 'object') { - throw new Error('Unable to load mapping file: `mapping` must contain objects only') + if (typeof map !== "object") { + throw new Error("Unable to load mapping file: `mapping` must contain objects only") } if (!map.tokenSets && !map.tokensTheme) { - throw new Error( - 'Unable to load mapping file: `mapping` must contain either `tokensTheme` or `tokenSets`' - ) + throw new Error("Unable to load mapping file: `mapping` must contain either `tokensTheme` or `tokenSets`") } if (map.tokenSets && map.tokensTheme) { - throw new Error( - 'Unable to load mapping file: `mapping` must not contain both `tokensTheme` or `tokenSets`' - ) + throw new Error("Unable to load mapping file: `mapping` must not contain both `tokensTheme` or `tokenSets`") } if (map.tokenSets && (!(map.tokenSets instanceof Array) || (map.tokenSets as Array).length === 0)) { - throw new Error( - 'Unable to load mapping file: `mapping`.`tokenSets` must be an Array with at least one entry' - ) + throw new Error("Unable to load mapping file: `mapping`.`tokenSets` must be an Array with at least one entry") } - if (map.tokensTheme && ((typeof map.tokensTheme !== 'string' && !Array.isArray(map.tokensTheme)) || map.tokensTheme.length === 0)) { + if ( + map.tokensTheme && + ((typeof map.tokensTheme !== "string" && !Array.isArray(map.tokensTheme)) || map.tokensTheme.length === 0) + ) { throw new Error( - 'Unable to load mapping file: `mapping`.`tokensTheme` must be a non-empty string or non-empty array of strings' + "Unable to load mapping file: `mapping`.`tokensTheme` must be a non-empty string or non-empty array of strings" ) } - if (!map.supernovaBrand || typeof map.supernovaBrand !== 'string' || map.supernovaBrand.length === 0) { - throw new Error( - 'Unable to load mapping file: `supernovaBrand` must be a non-empty string' - ) + if (!map.supernovaBrand || typeof map.supernovaBrand !== "string" || map.supernovaBrand.length === 0) { + throw new Error("Unable to load mapping file: `supernovaBrand` must be a non-empty string") } - if (map.supernovaTheme && (typeof map.supernovaTheme !== 'string' || map.supernovaTheme.length === 0)) { + if (map.supernovaTheme && (typeof map.supernovaTheme !== "string" || map.supernovaTheme.length === 0)) { throw new Error( - 'Unable to load mapping file: `supernovaTheme` may be empty but must be non-empty string if not' + "Unable to load mapping file: `supernovaTheme` may be empty but must be non-empty string if not" ) } } if (mapping.settings) { - if (typeof mapping.settings !== 'object') { - throw new Error('Unable to load mapping file: `settings` must be an object') + if (typeof mapping.settings !== "object") { + throw new Error("Unable to load mapping file: `settings` must be an object") } - if (mapping.settings.hasOwnProperty('dryRun') && typeof mapping.settings.dryRun !== 'boolean') { - throw new Error('Unable to load mapping file: `dryRun` must be of boolean type') + if (mapping.settings.hasOwnProperty("dryRun") && typeof mapping.settings.dryRun !== "boolean") { + throw new Error("Unable to load mapping file: `dryRun` must be of boolean type") } - if (mapping.settings.hasOwnProperty('verbose') && typeof mapping.settings.verbose !== 'boolean') { - throw new Error('Unable to load mapping file: `verbose` must be of boolean type') + if (mapping.settings.hasOwnProperty("verbose") && typeof mapping.settings.verbose !== "boolean") { + throw new Error("Unable to load mapping file: `verbose` must be of boolean type") } - if (mapping.settings.hasOwnProperty('preciseCopy') - && typeof mapping.settings.preciseCopy !== 'boolean' - && typeof mapping.settings.preciseCopy !== "string") { - throw new Error('Unable to load mapping file: `preciseCopy` must be of boolean or string type') + if ( + mapping.settings.hasOwnProperty("preciseCopy") && + typeof mapping.settings.preciseCopy !== "boolean" && + typeof mapping.settings.preciseCopy !== "string" + ) { + throw new Error("Unable to load mapping file: `preciseCopy` must be of boolean or string type") } } } - private processFileToMapping( - mapping: DTPluginToSupernovaMappingFile - ): { + private processFileToMapping(mapping: DTPluginToSupernovaMappingFile): { mapping: DTPluginToSupernovaMapPack settings: DTPluginToSupernovaSettings } { @@ -217,7 +203,7 @@ export class FigmaTokensDataLoader { bindToTheme: map.supernovaTheme ?? null, nodes: null, processedNodes: null, - processedGroups: null + processedGroups: null, }) } @@ -225,12 +211,13 @@ export class FigmaTokensDataLoader { ...(mapping.settings ?? {}), dryRun: mapping.settings?.dryRun ?? false, verbose: mapping.settings?.verbose ?? false, - preciseCopy: mapping.settings?.preciseCopy ?? false + preciseCopy: (mapping.settings?.preciseCopy ? "deleteAll" : "none") as DTPluginPreciseCopyStrategy, + themeOverridesStrategy: "default" as DTPluginThemeOverrideStrategy, } return { mapping: result, - settings: settings + settings: settings, } } @@ -240,33 +227,26 @@ export class FigmaTokensDataLoader { private parseDefinition(definition: string): object { try { let object = JSON.parse(definition) - if (typeof object !== 'object') { - throw new Error( - 'Invalid Supernova mapping definition JSON file - root level entity must be object' - ) + if (typeof object !== "object") { + throw new Error("Invalid Supernova mapping definition JSON file - root level entity must be object") } return object } catch (error) { - throw new Error( - 'Invalid Supernova mapping definition JSON file - file structure invalid' - ) + throw new Error("Invalid Supernova mapping definition JSON file - file structure invalid") } } - private async loadObjectFile(pathToFile: string): Promise { try { if (!(fs.existsSync(pathToFile) && fs.lstatSync(pathToFile).isFile())) { - throw new Error( - `Provided token file directory ${pathToFile} is not a file or doesn't exist` - ) + throw new Error(`Provided token file directory ${pathToFile} is not a file or doesn't exist`) } - let definition = fs.readFileSync(pathToFile, 'utf8') + let definition = fs.readFileSync(pathToFile, "utf8") let parsedDefinition = this.parseDefinition(definition) return parsedDefinition } catch (error) { - throw new Error('Unable to load JSON definition file: ' + error) + throw new Error("Unable to load JSON definition file: " + error) } } -} \ No newline at end of file +} From fe6dfb4d81af9270c41e7b88f7a81149e296b706 Mon Sep 17 00:00:00 2001 From: Sergii Golyshev Date: Fri, 8 Nov 2024 16:38:19 +0200 Subject: [PATCH 4/5] Use new TS settings flags for preciseCopy, themeOverridesStrategy --- src/utils/figma-tokens-data-loader.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/utils/figma-tokens-data-loader.ts b/src/utils/figma-tokens-data-loader.ts index fb5f9c1..cda5173 100644 --- a/src/utils/figma-tokens-data-loader.ts +++ b/src/utils/figma-tokens-data-loader.ts @@ -6,6 +6,7 @@ import { DTPluginToSupernovaMapType, DTPluginPreciseCopyStrategy, DTPluginThemeOverrideStrategy, + toPreciseCopyStrategy, } from "@supernovaio/sdk" import * as fs from "fs" const path = require("path") @@ -211,8 +212,8 @@ export class FigmaTokensDataLoader { ...(mapping.settings ?? {}), dryRun: mapping.settings?.dryRun ?? false, verbose: mapping.settings?.verbose ?? false, - preciseCopy: (mapping.settings?.preciseCopy ? "deleteAll" : "none") as DTPluginPreciseCopyStrategy, - themeOverridesStrategy: "default" as DTPluginThemeOverrideStrategy, + preciseCopy: toPreciseCopyStrategy(mapping.settings?.preciseCopy), + themeOverridesStrategy: mapping.settings?.themeOverridesStrategy ?? "default" as DTPluginThemeOverrideStrategy, } return { From 3c58c963c989a199803f51371d894af8bb66f98b Mon Sep 17 00:00:00 2001 From: Artem Ufimtcev Date: Fri, 8 Nov 2024 16:30:51 +0100 Subject: [PATCH 5/5] Bump version --- package.json | 216 +++++++++++++++++++++++++-------------------------- 1 file changed, 108 insertions(+), 108 deletions(-) diff --git a/package.json b/package.json index d97ef1a..9aaf432 100644 --- a/package.json +++ b/package.json @@ -1,111 +1,111 @@ { - "name": "@supernovaio/cli", - "description": "Supernova.io Command Line Interface", - "version": "1.1.0", - "author": "Supernova.io", - "homepage": "https://supernova.io/", - "keywords": [ - "Supernova", - "Design Systems", - "Supernovaio", - "SDK", - "Design Tokens", - "Tokens", - "Assets", - "Components", - "Documentation", - "CMS" + "name": "@supernovaio/cli", + "description": "Supernova.io Command Line Interface", + "version": "1.1.1", + "author": "Supernova.io", + "homepage": "https://supernova.io/", + "keywords": [ + "Supernova", + "Design Systems", + "Supernovaio", + "SDK", + "Design Tokens", + "Tokens", + "Assets", + "Components", + "Documentation", + "CMS" + ], + "license": "MIT", + "bin": { + "supernova": "./bin/run" + }, + "bugs": "https://github.com/Supernova-Studio/cli/issues", + "dependencies": { + "@oclif/core": "4.0.17", + "@oclif/plugin-help": "6.2.8", + "@oclif/plugin-plugins": "5.4.2", + "@supernova-studio/pulsar-core": "2.3.21", + "@supernovaio/sdk": "^2.0.27", + "axios": "^1.7.7", + "colors": "^1.4.0", + "minimatch": "^9.0.5", + "node-fetch": "^3.2.4" + }, + "bundleDependencies": [ + "@supernova-studio/pulsar-core", + "@supernova-studio/simple-parse-github-url", + "@supernova-studio/client", + "@supernova-studio/model" + ], + "devDependencies": { + "@babel/core": "^7.9.0", + "@babel/preset-env": "^7.3.4", + "@babel/preset-react": "7.18.6", + "@babel/register": "^7.18.9", + "@oclif/test": "4.0.8", + "@types/chai": "^4", + "@types/colors": "^1.2.1", + "@types/mocha": "^9.0.0", + "@types/node": "^16.11.36", + "chai": "^4", + "dotenv": "^16.0.0", + "eslint": "^7.32.0", + "eslint-config-oclif": "^5.2.1", + "eslint-config-oclif-typescript": "^3.1.9", + "globby": "^11", + "mocha": "^9", + "oclif": "4.14.15", + "shx": "^0.3.3", + "ts-node": "10.9.1", + "tslib": "^2.3.1", + "typescript": "5.2.2" + }, + "engines": { + "node": ">=18.0.0" + }, + "files": [ + "/bin", + "/dist", + "/npm-shrinkwrap.json", + "/oclif.manifest.json" + ], + "main": "dist/index.js", + "oclif": { + "bin": "supernova", + "dirname": "supernova", + "commands": "./dist/commands", + "plugins": [ + "@oclif/plugin-help", + "@oclif/plugin-plugins" ], - "license": "MIT", - "bin": { - "supernova": "./bin/run" - }, - "bugs": "https://github.com/Supernova-Studio/cli/issues", - "dependencies": { - "@oclif/core": "4.0.17", - "@oclif/plugin-help": "6.2.8", - "@oclif/plugin-plugins": "5.4.2", - "@supernova-studio/pulsar-core": "2.3.21", - "@supernovaio/sdk": "^2.0.27", - "axios": "^1.7.7", - "colors": "^1.4.0", - "minimatch": "^9.0.5", - "node-fetch": "^3.2.4" - }, - "bundleDependencies": [ - "@supernova-studio/pulsar-core", - "@supernova-studio/simple-parse-github-url", - "@supernova-studio/client", - "@supernova-studio/model" - ], - "devDependencies": { - "@babel/core": "^7.9.0", - "@babel/preset-env": "^7.3.4", - "@babel/preset-react": "7.18.6", - "@babel/register": "^7.18.9", - "@oclif/test": "4.0.8", - "@types/chai": "^4", - "@types/colors": "^1.2.1", - "@types/mocha": "^9.0.0", - "@types/node": "^16.11.36", - "chai": "^4", - "dotenv": "^16.0.0", - "eslint": "^7.32.0", - "eslint-config-oclif": "^5.2.1", - "eslint-config-oclif-typescript": "^3.1.9", - "globby": "^11", - "mocha": "^9", - "oclif": "4.14.15", - "shx": "^0.3.3", - "ts-node": "10.9.1", - "tslib": "^2.3.1", - "typescript": "5.2.2" - }, - "engines": { - "node": ">=18.0.0" - }, - "files": [ - "/bin", - "/dist", - "/npm-shrinkwrap.json", - "/oclif.manifest.json" - ], - "main": "dist/index.js", - "oclif": { - "bin": "supernova", - "dirname": "supernova", - "commands": "./dist/commands", - "plugins": [ - "@oclif/plugin-help", - "@oclif/plugin-plugins" - ], - "topicSeparator": " ", - "topics": { - "sync-tokens": { - "description": "Synchronize tokens from Figma Tokens plugin to Supernova workspaces" - }, - "describe-design-system": { - "description": "Describe structure (brands and themes) of selected design system" - }, - "describe-workspaces": { - "description": "Describe structure of all workspaces provided API key has access to" - }, - "publish-documentation": { - "description": "Publish current documentation" - }, - "run-local-exporter": { - "description": "Run exporer package locally" - } - } - }, - "repository": "https://github.com/Supernova-Studio/cli", - "scripts": { - "build": "shx rm -rf dist && tsc -b", - "lint": "eslint . --ext .ts --config .eslintrc", - "postpack": "shx rm -f oclif.manifest.json", - "prepack": "yarn build && oclif manifest", - "test": "DEBUG=* && npm run build && env TS_NODE_PROJECT=\"tsconfig.testing.json\" mocha --require ts-node/register --forbid-only \"test/**/sync-tokens.test.ts\"", - "publish-package": "npm run build && npm run prepack && npm publish --access public && npm run postpack" - }, - "types": "dist/index.d.ts" + "topicSeparator": " ", + "topics": { + "sync-tokens": { + "description": "Synchronize tokens from Figma Tokens plugin to Supernova workspaces" + }, + "describe-design-system": { + "description": "Describe structure (brands and themes) of selected design system" + }, + "describe-workspaces": { + "description": "Describe structure of all workspaces provided API key has access to" + }, + "publish-documentation": { + "description": "Publish current documentation" + }, + "run-local-exporter": { + "description": "Run exporer package locally" + } + } + }, + "repository": "https://github.com/Supernova-Studio/cli", + "scripts": { + "build": "shx rm -rf dist && tsc -b", + "lint": "eslint . --ext .ts --config .eslintrc", + "postpack": "shx rm -f oclif.manifest.json", + "prepack": "yarn build && oclif manifest", + "test": "DEBUG=* && npm run build && env TS_NODE_PROJECT=\"tsconfig.testing.json\" mocha --require ts-node/register --forbid-only \"test/**/sync-tokens.test.ts\"", + "publish-package": "npm run build && npm run prepack && npm publish --access public && npm run postpack" + }, + "types": "dist/index.d.ts" }