forked from ljharb/npmignore
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.js
53 lines (39 loc) · 1.22 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env node
'use strict';
var fs = require('fs');
var path = require('path');
var log = require('verbalize');
var argv = require('minimist')(process.argv.slice(2));
var parser = require('./');
log.runner = 'dockerignore';
/**
* Find the local `ignore` files we need
*/
var gitignore = argv.g || argv.gitignore || '.gitignore';
var dockerignore = argv.d || argv.dockerignore || '.dockerignore';
// optionally specify a different destination
var dest = argv.D || argv.dest || dockerignore;
// patterns to ignore
var i = argv.i || argv.ignore;
// patterns to un-ignore
var u = argv.u || argv.unignore;
if (typeof i === 'string') i = i.split(',');
if (typeof u === 'string') u = u.split(',');
var git = read(gitignore);
var dock = read(dockerignore);
// Parse the files and create a new `.dockerignore` file
// based on the given arguments along with data that
// is already present in either or both files.
var res = parser(dock, git, {ignore: i, unignore: u});
// write the file.
fs.writeFileSync(dest, res);
console.log();
log.inform('updated', dest);
log.success(' Done.');
function read(fp) {
fp = path.join(process.cwd(), fp);
if (!fs.existsSync(fp)) {
return null;
}
return fs.readFileSync(fp, 'utf8');
}