Skip to content
This repository was archived by the owner on Jun 22, 2020. It is now read-only.

Commit bb5026c

Browse files
committed
feat(main): write the files
Sorta missed this out the first release, whoops
1 parent 03c9892 commit bb5026c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/main.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as yargs from 'yargs';
55
import convert from '@lib/convert';
66
import TspmError from '@lib/Error';
77
import ParseError from '@lib/error/Parse';
8+
import File from '@lib/File';
89

910
interface IColours {
1011
[name: string]: string;
@@ -82,16 +83,25 @@ function colours(colour: true | 'auto' | false, stream: NodeJS.WriteStream): ICo
8283
}
8384

8485
export async function map(options: IOptions): Promise<number> {
85-
const { projectRoot: root, colour, silent } = options;
86+
const { projectRoot: root, colour, silent, verbose } = options;
8687

8788
try {
8889
const {blue: r, yellow: p, green: t, reset: _} = colours(colour, process.stderr);
90+
const files = new Set<File>();
8991
for await (const mapped of convert(options)) {
90-
if (!silent) {
92+
if (!silent && verbose) {
9193
const { original, path, module } = mapped;
9294
const relative = module.relative(root);
9395
process.stdout.write(`${t}Mapped${_} '${r}${relative}${_}': '${p}${original}${_}' → '${p}${path}${_}'\n`);
9496
}
97+
files.add(mapped.file);
98+
}
99+
for (const file of files) {
100+
await file.write();
101+
if (!silent) {
102+
const relative = file.destination.relative(root);
103+
process.stdout.write(`${t}Wrote${_} '${r}${relative}${_}'\n`);
104+
}
95105
}
96106
return 0;
97107
} catch (error) {

0 commit comments

Comments
 (0)