Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing a few CLI runtime issues #202

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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"
}
11 changes: 7 additions & 4 deletions packages/adaptive-ui-designer-figma/src/cli/library-config.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -26,10 +24,13 @@ interface LibrarySchema {
export interface ILibraryConfig {
readonly file: File;
readonly valid: boolean;
readonly errorMessages: Array<string>;
readonly outDir: string;
}

class ErrorLibraryConfig implements ILibraryConfig {
constructor(public readonly errorMessages: Array<string>) {
}
public readonly file: File = { url: '', file_key: '', file_name: '', file_type: FileType.file };
public readonly valid = false;
public readonly outDir: string = '';
Expand All @@ -43,6 +44,7 @@ export class LibraryConfig implements ILibraryConfig {
}

public readonly valid: boolean = true;
public readonly errorMessages: Array<string> = [];
public readonly file: File;
public readonly outDir: string;

Expand All @@ -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);
}
}

Expand Down
15 changes: 8 additions & 7 deletions packages/adaptive-ui-designer-figma/src/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class StyleSheet implements IStylesheet {

public async render(): Promise<void> {
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);
});
Expand Down
Loading