Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

Alorel / personal-build-tools / 801

20 Mar 2019 - 7:52 coverage increased (+2.9%) to 83.558%
801

Pull #76

travis-ci-com

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
chore(package): update lockfile yarn.lock
Pull Request #76: Update rollup to the latest version 🚀

304 of 452 branches covered (67.26%)

Branch coverage included in aggregate %.

936 of 1032 relevant lines covered (90.7%)

44.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.0
/src/commands/copy-files.ts
1
import * as fs from 'fs-extra';
2
import {IOptions, sync as glob} from 'glob';
12×
3
import * as _ from 'lodash';
12×
4
import {basename, dirname, join} from 'path';
12×
5
import {CommandModule} from 'yargs';
12×
6
import {addConfig} from '../fns/add-cmd/addConfig';
12×
7
import {cmdName} from '../fns/cmdName';
12×
8
import {flattenGlob} from '../fns/flattenGlob';
12×
9

12×
10
interface Conf {
11
  from: string[];
12

24×
13
  to: string[];
14
}
15

16
interface FromTo {
17
  from: string;
18

19
  to: string;
20
}
21

22
const command = cmdName(__filename);
23

24
const cmd: CommandModule<any, Conf> = {
25
  builder(argv): any {
26
    return addConfig(argv, command)
27
      .option('from', {
28
        alias: 'f',
29
        array: true,
UNCOV
30
        demandOption: true,
!
31
        describe: 'Glob(s) to copy'
32
      })
UNCOV
33
      .option('to', {
!
34
        alias: 't',
35
        array: true,
24×
36
        demandOption: true,
24×
37
        describe: 'Dir(s) to copy to'
38
      });
30×
39
  },
40
  command,
48×
41
  describe: 'Copy files from point A to point B',
42
  handler(c: Conf) {
43
    if (!c.from.length || !c.to.length) {
44
      throw new Error('At least one from/to path is required');
24×
45
    }
46
    if (c.to.length !== 1 && c.to.length !== c.from.length) {
47
      throw new Error('"to" must either contain 1 path or have the same number of paths as "from"');
48
    }
24×
49

50
    const opts: IOptions = {cwd: process.cwd()};
48×
51

52
    const fromTos = c.from
53
      .map<FromTo[]>((p, idx) => {
54
        return glob(p, opts)
12×
55
          .map<FromTo>(from => {
56
            return {from, to: join(c.to[idx] || c.to[0], basename(from))};
57
          });
58
      })
59
      .reduce<FromTo[]>(flattenGlob, []);
60

61
    _(fromTos)
62
      .map('to')
63
      .map(dirname)
64
      .uniq()
65
      .forEach(dir => fs.mkdirpSync(dir));
66

67
    for (const ft of fromTos) {
68
      fs.copySync(ft.from, ft.to, {dereference: true, preserveTimestamps: true});
69
    }
70
  }
71
};
72

73
export = cmd;
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2022 Coveralls, Inc