Skip to content

Commit 89dfea0

Browse files
committed
Fix CLI where files are being synced from the project document instead of from the filesystem
CLI sync should not create files as this is the role of the versionning system (git). This allow a project to contain file from 2 different repos (like a webapp and a API CMS). This is a fix from a recent addition that was also consider a fix. The fix was wrong so the document-paths-fetcher.ts file is patched. The stats command also reflect which document from Accent’s project is found in the filesystem.
1 parent de6dd81 commit 89dfea0

File tree

5 files changed

+58
-10
lines changed

5 files changed

+58
-10
lines changed

cli/src/commands/stats.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {CLIError} from '@oclif/errors';
1010
import Formatter from '../services/formatters/project-stats';
1111
import ProjectFetcher from '../services/project-fetcher';
1212
import {Revision} from '../types/project';
13+
import DocumentPathsFetcher from '../services/document-paths-fetcher';
1314

1415
export default class Stats extends Command {
1516
static description = 'Fetch stats from the API and display them beautifully';
@@ -44,9 +45,15 @@ export default class Stats extends Command {
4445
this.project = response.project;
4546
}
4647

48+
const documents = this.projectConfig.files();
49+
const targets = documents.flatMap((document) => {
50+
return new DocumentPathsFetcher().fetch(this.project!, document);
51+
});
52+
4753
const formatter = new Formatter(
4854
this.project!,
4955
this.projectConfig.config,
56+
targets,
5057
flags.version
5158
);
5259

cli/src/commands/sync.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export default class Sync extends Command {
149149
formatter.logSync(path, documentPath);
150150
}
151151
}
152+
console.log('');
152153
}
153154

154155
private async addTranslationsDocumentConfig(document: Document) {
@@ -191,5 +192,6 @@ export default class Sync extends Command {
191192
);
192193
}
193194
}
195+
console.log('');
194196
}
195197
}

cli/src/services/document-paths-fetcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default class DocumentPathsFetcher {
88
fetch(project: Project, document: Document): DocumentPath[] {
99
const languageSlugs = fetchFromRevisions(project.revisions);
1010
const documentPaths: Set<string> = new Set();
11-
project.documents.entries.forEach(({path}) => documentPaths.add(path));
11+
1212
document.paths.forEach((documentPath) => {
1313
const name = document.parseDocumentName(documentPath, document.config);
1414
documentPaths.add(name);

cli/src/services/formatters/commit-operation.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export default class CommitOperationFormatter {
1515
chalk.bold.white(path),
1616
chalk.gray.dim(documentPath)
1717
);
18-
console.log('');
1918
}
2019

2120
logAddTranslations(path: string, documentPath: string) {
@@ -25,7 +24,6 @@ export default class CommitOperationFormatter {
2524
chalk.bold.white(path),
2625
chalk.gray.dim(documentPath)
2726
);
28-
console.log('');
2927
}
3028

3129
logEmptyExistingTarget(path: string) {

cli/src/services/formatters/project-stats.ts

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,29 @@ import {
1818
} from '../revision-slug-fetcher';
1919
import Base from './base';
2020

21+
interface DocumentTarget {
22+
documentPath: string;
23+
path: string;
24+
language: string;
25+
}
26+
2127
export default class ProjectStatsFormatter extends Base {
2228
private readonly project: Project;
2329
private readonly config: Config;
30+
private readonly targets: DocumentTarget[];
2431
private readonly version: string | undefined;
2532

26-
constructor(project: Project, config: Config, version?: string) {
33+
constructor(
34+
project: Project,
35+
config: Config,
36+
targets: DocumentTarget[],
37+
version?: string
38+
) {
2739
super();
2840
this.project = project;
2941
this.config = config;
3042
this.version = version;
43+
this.targets = targets;
3144
}
3245

3346
percentageReviewedString(number: number, translationsCount: number) {
@@ -142,11 +155,39 @@ export default class ProjectStatsFormatter extends Base {
142155
`(${this.project.documents.meta.totalEntries})`
143156
)
144157
);
145-
this.project.documents.entries.forEach((document: Document) => {
146-
console.log(chalk.gray('Format:'), chalk.white.bold(document.format));
147-
console.log(chalk.gray('Path:'), chalk.white.bold(document.path));
148-
console.log('');
149-
});
158+
this.project.documents.entries
159+
.sort((a, b) => {
160+
const existingTargetA = this.targets.find(
161+
(target) => a.path === target.documentPath
162+
);
163+
const existingTargetB = this.targets.find(
164+
(target) => b.path === target.documentPath
165+
);
166+
167+
if (existingTargetA) return -1;
168+
if (existingTargetB) return 1;
169+
return 0;
170+
})
171+
.forEach((document: Document) => {
172+
const existingTarget = this.targets.find(
173+
(target) => document.path === target.documentPath
174+
);
175+
176+
if (existingTarget) {
177+
console.log(
178+
chalk.white(document.path),
179+
chalk.whiteBright.underline(existingTarget.path)
180+
);
181+
} else {
182+
console.log(
183+
chalk.gray.dim(document.path),
184+
chalk.gray.dim('-'),
185+
chalk.gray.dim(document.format),
186+
chalk.gray.dim('(No matches in config file)')
187+
);
188+
}
189+
});
190+
console.log('');
150191
}
151192

152193
if (this.project.versions.meta.totalEntries !== 0) {
@@ -196,7 +237,7 @@ export default class ProjectStatsFormatter extends Base {
196237

197238
console.log(
198239
chalk.magenta('Project URL:'),
199-
chalk.gray.dim(`${this.config.apiUrl}/app/projects/${this.project.id}`)
240+
chalk.gray(`${this.config.apiUrl}/app/projects/${this.project.id}`)
200241
);
201242
console.log('');
202243
}

0 commit comments

Comments
 (0)