Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
artufimtcev committed Nov 8, 2024
1 parent 87aa2c0 commit 0ec1e22
Show file tree
Hide file tree
Showing 10 changed files with 28,047 additions and 27,992 deletions.
55,867 changes: 27,945 additions & 27,922 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"globby": "^11",
"mocha": "^9",
"oclif": "4.14.15",
"prettier": "^3.3.3",
"shx": "^0.3.3",
"ts-node": "10.9.1",
"tslib": "^2.3.1",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/describe-design-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class DescribeDesignSystem extends Command {
this.log(`\n↳ Design system "${designSystem.name}", id: ${designSystem.id}`.cyan)
for (let brand of brands) {
this.log(` ↳ Brand: "${brand.name}", id: ${brand.id}`)
let brandThemes = themes.filter((t) => t.brandId === brand.id)
let brandThemes = themes.filter(t => t.brandId === brand.id)
if (brandThemes.length > 0) {
for (let theme of brandThemes) {
this.log(` ↳ Theme: "${theme.name}", id: ${theme.id}`)
Expand Down
16 changes: 10 additions & 6 deletions src/commands/describe-workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,24 @@ export class DescribeWorkspaces extends Command {
for (let workspace of workspaces) {
// Get design systems and log
let designSystems = await instance.designSystems.designSystems(workspace.id)
this.log(`↳ Workspace "${workspace.profile.name}", handle: "${workspace.profile.handle}", id: ${workspace.id}`.magenta)
this.log(
`↳ Workspace "${workspace.profile.name}", handle: "${workspace.profile.handle}", id: ${workspace.id}`.magenta,
)
for (let designSystem of designSystems) {
this.log(` ↳ Design system "${designSystem.name}", id: ${designSystem.id}`.cyan)
let version = await instance.versions.getActiveVersion(designSystem.id)
if (!version) {
this.log(`Design system ${designSystem.id} active version not found or not available under provided API key`)
continue;
this.log(
`Design system ${designSystem.id} active version not found or not available under provided API key`,
)
continue
}
let id: RemoteVersionIdentifier = { designSystemId: designSystem.id, versionId: version.id };
let id: RemoteVersionIdentifier = { designSystemId: designSystem.id, versionId: version.id }
let brands = await instance.brands.getBrands(id)
let themes = await instance.tokens.getTokenThemes(id)
for (let brand of brands) {
this.log(` ↳ Brand: "${brand.name}", id: ${brand.id}`)
let brandThemes = themes.filter((t) => t.brandId === brand.id)
let brandThemes = themes.filter(t => t.brandId === brand.id)
if (brandThemes.length > 0) {
for (let theme of brandThemes) {
this.log(` ↳ Theme: "${theme.name}", id: ${theme.id}`.gray)
Expand Down Expand Up @@ -120,7 +124,7 @@ export class DescribeWorkspaces extends Command {
// Create instance for prod / dev
let apiUrl = environmentAPI(flags.environment as Environment, "v2")
let sdkInstance = new Supernova(flags.apiKey, { apiUrl, bypassEnvFetch: true, proxyUrl: flags.proxyUrl })
let user = await sdkInstance.me.me();
let user = await sdkInstance.me.me()
let workspaces = await sdkInstance.workspaces.workspaces(user.id)
return {
instance: sdkInstance,
Expand Down
14 changes: 9 additions & 5 deletions src/commands/run-local-exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,17 @@ export class RunLocalExporter extends Command {
apiKey: Flags.string({ description: "API key to use for accessing Supernova instance", required: true }),
designSystemId: Flags.string({ description: "Design System to export from", required: true }),
exporterDir: Flags.string({ description: "Path to exporter package", required: true }),
outputDir: Flags.string({ description: "Path to output folder. Must be empty, unless `forceClearOutputDir` is set", required: true }),
outputDir: Flags.string({
description: "Path to output folder. Must be empty, unless `forceClearOutputDir` is set",
required: true,
}),
themeId: Flags.string({
description: "Theme to export. Will only be used when exporter has usesThemes: true, and is optional",
required: false,
}),
brandId: Flags.string({
description: "Brand to export. Will only be used when exporter has usesBrands: true, but then it is required to be provided",
description:
"Brand to export. Will only be used when exporter has usesBrands: true, but then it is required to be provided",
required: false,
}),
allowOverridingOutput: Flags.boolean({
Expand Down Expand Up @@ -143,7 +147,7 @@ export class RunLocalExporter extends Command {

async executeExporter(
flags: RunLocalExporterFlags,
versionId: string
versionId: string,
): Promise<{
logger: PLLogger
result: PCEngineExporterProcessingResult | Error
Expand Down Expand Up @@ -200,7 +204,7 @@ export class RunLocalExporter extends Command {
const destination = path.join(flags.outputDir, file.path)
if (fs.existsSync(destination)) {
throw new Error(
`Exporter produced file for destination ${destination} but that file already exists. Enable --allowOverridingOutput option to allow overriding`
`Exporter produced file for destination ${destination} but that file already exists. Enable --allowOverridingOutput option to allow overriding`,
)
}
}
Expand Down Expand Up @@ -230,7 +234,7 @@ export class RunLocalExporter extends Command {
const chunkSize = 4
for (let i = 0; i < result.emittedFiles.length; i += chunkSize) {
const chunk = result.emittedFiles.slice(i, i + chunkSize)
await Promise.all(chunk.map((file) => processFile(file)))
await Promise.all(chunk.map(file => processFile(file)))
}

// Write all files from the temporary structure to the filesystem as a final step - this is to avoid partial writes
Expand Down
7 changes: 5 additions & 2 deletions src/commands/sync-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ export class SyncDesignTokens extends Command {
exactlyOne: ["tokenDirPath", "tokenFilePath"],
}),
configFilePath: Flags.string({ description: "Path to configuration JSON file", required: true, exclusive: [] }),
apiUrl: Flags.string({ description: "API url to use for accessing Supernova instance, would ignore defaults", hidden: true }),
apiUrl: Flags.string({
description: "API url to use for accessing Supernova instance, would ignore defaults",
hidden: true,
}),
environment: Flags.string({
description: "When set, CLI will target a specific environment",
hidden: true,
Expand Down Expand Up @@ -109,7 +112,7 @@ export class SyncDesignTokens extends Command {
let tokenDefinition = flags.tokenDirPath
? await dataLoader.loadTokensFromDirectory(flags.tokenDirPath, flags.configFilePath)
: await dataLoader.loadTokensFromPath(flags.tokenFilePath!)
const response = await instance.versions.writeTokenStudioData(id, buildData(tokenDefinition)) as any
const response = (await instance.versions.writeTokenStudioData(id, buildData(tokenDefinition))) as any
if (response?.result?.logs && response.result.logs.length > 0) {
for (const log of response.result.logs) {
this.log(log)
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {run} from '@oclif/core'
export { run } from "@oclif/core"
6 changes: 3 additions & 3 deletions src/utils/figma-tokens-data-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ export class FigmaTokensDataLoader {
((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.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",
)
}
}
Expand Down Expand Up @@ -213,7 +213,7 @@ export class FigmaTokensDataLoader {
dryRun: mapping.settings?.dryRun ?? false,
verbose: mapping.settings?.verbose ?? false,
preciseCopy: toPreciseCopyStrategy(mapping.settings?.preciseCopy),
themeOverridesStrategy: mapping.settings?.themeOverridesStrategy ?? "default" as DTPluginThemeOverrideStrategy,
themeOverridesStrategy: mapping.settings?.themeOverridesStrategy ?? ("default" as DTPluginThemeOverrideStrategy),
}

return {
Expand Down
119 changes: 67 additions & 52 deletions src/utils/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,86 @@
import { Brand, DesignSystem, DesignSystemVersion, RemoteWorkspaceVersionIdentifier, Supernova, TokenTheme } from "@supernovaio/sdk"
import {
Brand,
DesignSystem,
DesignSystemVersion,
RemoteWorkspaceVersionIdentifier,
Supernova,
TokenTheme,
} from "@supernovaio/sdk"
import { Environment } from "../types/types"
import { environmentAPI } from "../utils/network"
import "colors"

export interface DefaultDesignSystemFlags {
apiKey: string
apiUrl?: string
designSystemId: string
environment: string
themeId?: string
brandId?: string
proxyUrl?: string
apiKey: string
apiUrl?: string
designSystemId: string
environment: string
themeId?: string
brandId?: string
proxyUrl?: string
}

export async function getWritableVersion(flags: DefaultDesignSystemFlags, apiVersion: string = "v2"): Promise<{
instance: Supernova
designSystem: DesignSystem
version: DesignSystemVersion
brand: Brand | null
theme: TokenTheme | null
id: RemoteWorkspaceVersionIdentifier
export async function getWritableVersion(
flags: DefaultDesignSystemFlags,
apiVersion: string = "v2",
): Promise<{
instance: Supernova
designSystem: DesignSystem
version: DesignSystemVersion
brand: Brand | null
theme: TokenTheme | null
id: RemoteWorkspaceVersionIdentifier
}> {
if (!flags.apiKey || flags.apiKey.length === 0) {
throw new Error(`API key must not be empty`)
}
if (!flags.apiKey || flags.apiKey.length === 0) {
throw new Error(`API key must not be empty`)
}

if (!flags.designSystemId || flags.designSystemId.length === 0) {
throw new Error(`Design System ID must not be empty`)
}
if (!flags.designSystemId || flags.designSystemId.length === 0) {
throw new Error(`Design System ID must not be empty`)
}

// Create instance for prod / dev
let apiUrl = flags.apiUrl && flags.apiUrl.length > 0 ? flags.apiUrl : environmentAPI(flags.environment as Environment, apiVersion)
let instance = new Supernova(flags.apiKey, { apiUrl, bypassEnvFetch: true, proxyUrl: flags.proxyUrl })
// Create instance for prod / dev
let apiUrl =
flags.apiUrl && flags.apiUrl.length > 0
? flags.apiUrl
: environmentAPI(flags.environment as Environment, apiVersion)
let instance = new Supernova(flags.apiKey, { apiUrl, bypassEnvFetch: true, proxyUrl: flags.proxyUrl })

let designSystem = await instance.designSystems.designSystem(flags.designSystemId)
if (!designSystem) {
throw new Error(`Design system ${flags.designSystemId} not found or not available under provided API key`)
}
let designSystem = await instance.designSystems.designSystem(flags.designSystemId)
if (!designSystem) {
throw new Error(`Design system ${flags.designSystemId} not found or not available under provided API key`)
}

let version = await instance.versions.getActiveVersion(flags.designSystemId)
if (!version) {
throw new Error(`Design system ${flags.designSystemId} writable version not found or not available under provided API key`)
}
let version = await instance.versions.getActiveVersion(flags.designSystemId)
if (!version) {
throw new Error(
`Design system ${flags.designSystemId} writable version not found or not available under provided API key`,
)
}

let id: RemoteWorkspaceVersionIdentifier = {
designSystemId: flags.designSystemId,
versionId: version.id,
workspaceId: designSystem.workspaceId
};
let id: RemoteWorkspaceVersionIdentifier = {
designSystemId: flags.designSystemId,
versionId: version.id,
workspaceId: designSystem.workspaceId,
}

let brand: Brand | null = null
if (flags.brandId) {
const brands = await instance.brands.getBrands(id)
brand = brands.find((brand) => brand.id === flags.brandId || brand.idInVersion === flags.brandId) ?? null
if (!brand) {
throw new Error(`Brand ${flags.brandId} not found in specified design system`)
}
let brand: Brand | null = null
if (flags.brandId) {
const brands = await instance.brands.getBrands(id)
brand = brands.find(brand => brand.id === flags.brandId || brand.idInVersion === flags.brandId) ?? null
if (!brand) {
throw new Error(`Brand ${flags.brandId} not found in specified design system`)
}
}

let theme: TokenTheme | null = null
if (flags.themeId) {
const themes = await instance.tokens.getTokenThemes(id)
theme = themes.find((theme) => theme.id === flags.themeId || theme.idInVersion === flags.themeId) ?? null
if (!theme) {
throw new Error(`Theme ${flags.themeId} not found in specified brand`)
}
let theme: TokenTheme | null = null
if (flags.themeId) {
const themes = await instance.tokens.getTokenThemes(id)
theme = themes.find(theme => theme.id === flags.themeId || theme.idInVersion === flags.themeId) ?? null
if (!theme) {
throw new Error(`Theme ${flags.themeId} not found in specified brand`)
}
}

return { instance, designSystem, version, brand, theme, id }
return { instance, designSystem, version, brand, theme, id }
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7271,6 +7271,11 @@ prelude-ls@^1.2.1:
resolved "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz"
integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==

prettier@^3.3.3:
version "3.3.3"
resolved "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz"
integrity sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==

proc-log@^3.0.0:
version "3.0.0"

Expand Down

0 comments on commit 0ec1e22

Please sign in to comment.