diff --git a/change/@adaptive-web-adaptive-ui-designer-figma-c0e00d8c-c4ff-4895-bfa8-19cf6ec650f8.json b/change/@adaptive-web-adaptive-ui-designer-figma-c0e00d8c-c4ff-4895-bfa8-19cf6ec650f8.json new file mode 100644 index 00000000..be320be3 --- /dev/null +++ b/change/@adaptive-web-adaptive-ui-designer-figma-c0e00d8c-c4ff-4895-bfa8-19cf6ec650f8.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "Fixing a few CLI runtime issues", + "packageName": "@adaptive-web/adaptive-ui-designer-figma", + "email": "47367562+bheston@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/packages/adaptive-ui-designer-figma/src/cli/library-config.ts b/packages/adaptive-ui-designer-figma/src/cli/library-config.ts index 9fffdd43..8afc80ef 100644 --- a/packages/adaptive-ui-designer-figma/src/cli/library-config.ts +++ b/packages/adaptive-ui-designer-figma/src/cli/library-config.ts @@ -1,9 +1,7 @@ /* eslint @typescript-eslint/naming-convention: off */ -import { readFile } from 'fs/promises'; -import { fileURLToPath } from 'url'; import path from 'path'; import fs from 'fs/promises'; -import { config } from 'process'; +import { ErrorObject } from 'ajv'; import { File, FileType, parseFilePath } from './figma-rest-client.js'; import librarySchema from './library-schema.js'; import { ISchemaValidator, SchemaValidator } from './schema-validator.js'; @@ -26,10 +24,13 @@ interface LibrarySchema { export interface ILibraryConfig { readonly file: File; readonly valid: boolean; + readonly errorMessages: Array; readonly outDir: string; } class ErrorLibraryConfig implements ILibraryConfig { + constructor(public readonly errorMessages: Array) { + } public readonly file: File = { url: '', file_key: '', file_name: '', file_type: FileType.file }; public readonly valid = false; public readonly outDir: string = ''; @@ -43,6 +44,7 @@ export class LibraryConfig implements ILibraryConfig { } public readonly valid: boolean = true; + public readonly errorMessages: Array = []; public readonly file: File; public readonly outDir: string; @@ -54,7 +56,8 @@ export class LibraryConfig implements ILibraryConfig { if (result === true) { return new LibraryConfig(JSON.parse(configData), path.dirname(configPath)); } else { - return new ErrorLibraryConfig(); + const messages = (result as ErrorObject[]).map(error => `${error.instancePath}: ${error.message}`); + return new ErrorLibraryConfig(messages); } } diff --git a/packages/adaptive-ui-designer-figma/src/cli/main.ts b/packages/adaptive-ui-designer-figma/src/cli/main.ts index 1fe99587..22a6761d 100644 --- a/packages/adaptive-ui-designer-figma/src/cli/main.ts +++ b/packages/adaptive-ui-designer-figma/src/cli/main.ts @@ -24,11 +24,12 @@ interface ProgramOptions { } async function main({ library }: ProgramOptions) { - logger.neutral('Validating library config file...'); const configPath = path.resolve(process.cwd(), library); + logger.neutral('Validating library config file: ' + configPath); const libraryConfig = await LibraryConfig.create(configPath); if (libraryConfig.valid !== true) { logger.fail('Hmmm... there is something wrong with the config file you provided.'); + logger.fail(libraryConfig.errorMessages.join("\n")); process.exit(1); } @@ -112,7 +113,7 @@ async function main({ library }: ProgramOptions) { try { const anatomy = await AnatomyConfiguration.create(libraryConfig, node.document, logger); return anatomy; - } catch (e) { + } catch (e) { logger.fail('Something went wrong compiling anatomy'); logger.fail(e as any); return null; @@ -122,11 +123,11 @@ async function main({ library }: ProgramOptions) { await Promise.allSettled( anatomies.map(async (anatomy) => { - if (anatomy.status === "fulfilled" && anatomy.value !== null) { - const stylesheet = StyleSheet.create(anatomy.value, logger); - await stylesheet.render(); - } - }) + if (anatomy.status === "fulfilled" && anatomy.value !== null) { + const stylesheet = StyleSheet.create(anatomy.value, logger); + await stylesheet.render(); + } + }) ); // process components diff --git a/packages/adaptive-ui-designer-figma/src/cli/stylesheet.ts b/packages/adaptive-ui-designer-figma/src/cli/stylesheet.ts index 1207a115..2b0582b3 100644 --- a/packages/adaptive-ui-designer-figma/src/cli/stylesheet.ts +++ b/packages/adaptive-ui-designer-figma/src/cli/stylesheet.ts @@ -24,7 +24,7 @@ export class StyleSheet implements IStylesheet { public async render(): Promise { try { - const compiler = spawn('npx', ['aui', 'compile-json-anatomy', this.anatomy.path]); + const compiler = spawn('npx', ['aui', 'compile-json-anatomy', this.anatomy.path], { shell: true }); compiler.stderr.on('data', (chunk) => { this.logger.fail(chunk); });