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

Commit

Permalink
feat(main): write the files
Browse files Browse the repository at this point in the history
Sorta missed this out the first release, whoops
  • Loading branch information
mattyclarkson committed Feb 6, 2018
1 parent 03c9892 commit bb5026c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as yargs from 'yargs';
import convert from '@lib/convert';
import TspmError from '@lib/Error';
import ParseError from '@lib/error/Parse';
import File from '@lib/File';

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

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

try {
const {blue: r, yellow: p, green: t, reset: _} = colours(colour, process.stderr);
const files = new Set<File>();
for await (const mapped of convert(options)) {
if (!silent) {
if (!silent && verbose) {
const { original, path, module } = mapped;
const relative = module.relative(root);
process.stdout.write(`${t}Mapped${_} '${r}${relative}${_}': '${p}${original}${_}' → '${p}${path}${_}'\n`);
}
files.add(mapped.file);
}
for (const file of files) {
await file.write();
if (!silent) {
const relative = file.destination.relative(root);
process.stdout.write(`${t}Wrote${_} '${r}${relative}${_}'\n`);
}
}
return 0;
} catch (error) {
Expand Down

0 comments on commit bb5026c

Please sign in to comment.