diff --git a/CHANGELOG.md b/CHANGELOG.md index 285329d..63216bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,6 @@ All notable changes to this project will be documented in this file. See [standa ### Documentation * add playground ([347f7c9](https://github.com/dico-app/dico-cli/commit/347f7c919e1227fa308b04eb960975ece3a34b29)) -* rename playground files to prevent conflicts ([a82bf08](https://github.com/dico-app/dico-cli/commit/a82bf08a01810d918c75f305dabe1673bcb039bb)) * rename playground files to prevent conflicts ([32365e9](https://github.com/dico-app/dico-cli/commit/32365e9b74e3bbcb2bf4891d2dce43888f688329)) * update readme ([b34f0f0](https://github.com/dico-app/dico-cli/commit/b34f0f08e1c1286be9fcef9ec03eb4481b4859e1)) diff --git a/src/commands/build.ts b/src/commands/build.ts index 2fc6b1b..1f55d90 100644 --- a/src/commands/build.ts +++ b/src/commands/build.ts @@ -11,15 +11,15 @@ import * as project from "../core/project"; import * as messages from "../messages"; import exit from "exit"; import { DEFAULT_TIMEOUT } from "../const"; -import { ConfigJSON } from "../types"; +import { ConfigJSON, ProjectKey } from "../types"; class BuildError extends Error {} interface BuildDicoContext { paths: string[]; - keys: { path: string; key: string }[]; + keys: ProjectKey[]; schema: ConfigJSON["schema"]; - conflicts: { path: string; key: string }[][]; + conflicts: ProjectKey[][]; } const buildDico = new Listr( @@ -62,12 +62,12 @@ const buildDico = new Listr( const path = ctx.paths[i]; promises.push( - new Promise<{ path: string; key: string }[]>((res, rej) => { + new Promise((res, rej) => { setTimeout(() => { observer.next(`(${i + 1}/${ctx.paths.length}) ${path}`); try { const keys = project.crawlFile(path); - res(keys.map(key => ({ path, key }))); + res(keys); } catch (error) { rej(error); } @@ -149,7 +149,8 @@ export const build = async ( lineBreak(); try { - await buildDico.run(); + const { keys } = await buildDico.run(); + console.log(keys); } catch (error) { // Handle conflicts error if (error instanceof BuildError && error.message.includes("conflict")) { @@ -165,17 +166,21 @@ export const build = async ( if (conflict.length === 1) { console.log( ` Key ${chalk.cyan(conflict[0].key)} (${chalk.cyan( - conflict[0].path - )}) is conflicting` + `${conflict[0].file}:${conflict[0].line}:${conflict[0].column}` + )}) is conflicting with at least another unknown declaration, this shouldn't happen` ); } else { console.log( ` Key ${chalk.cyan(conflict[0].key)} (${chalk.cyan( - conflict[0].path + `${conflict[0].file}:${conflict[0].line}:${conflict[0].column}` )}) is conflicting with key ${chalk.cyan( conflict[1].key - )} (${chalk.cyan(conflict[1].path)})${ - conflict.length > 2 ? ` and ${conflict.length - 2} more...` : "" + )} (${chalk.cyan( + `${conflict[1].file}:${conflict[1].line}:${conflict[1].column}` + )})${ + conflict.length > 2 + ? ` and ${conflict.length - 2} more from that collection...` + : "" }` ); } diff --git a/src/core/dicojson.ts b/src/core/dicojson.ts index d1371be..bc317ca 100644 --- a/src/core/dicojson.ts +++ b/src/core/dicojson.ts @@ -1,7 +1,7 @@ import fs from "fs"; import path from "path"; import { JSON_FILE } from "../const"; -import { ConfigJSON } from "../types"; +import { ConfigJSON, ProjectKey } from "../types"; import * as messages from "../messages"; import detectIndent from "detect-indent"; @@ -47,13 +47,13 @@ export const write = (config: ConfigJSON): void => { // TODO: Better test this export const createSchema = ( - keys: { path: string; key: string }[] + keys: ProjectKey[] ): { schema: ConfigJSON["schema"]; - conflicts: { path: string; key: string }[][]; + conflicts: ProjectKey[][]; } => { const schema: ConfigJSON["schema"] = {}; - const conflicts: { path: string; key: string }[][] = []; + const conflicts: ProjectKey[][] = []; const uniqueKeys = keys.filter((keyObj, i, keys) => { return keys.findIndex(i => i.key === keyObj.key) === i; diff --git a/src/types.ts b/src/types.ts index 41ba35c..54e0359 100644 --- a/src/types.ts +++ b/src/types.ts @@ -34,3 +34,10 @@ export interface Structure { schema: { [key: string]: unknown }; updated_at: string; } + +export interface ProjectKey { + key: string; + file: string; + line: number; + column: number; +}