-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathcreate-index.js
95 lines (92 loc) · 2.58 KB
/
create-index.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env node
import yargs from 'yargs';
import {
writeIndexCli
} from '../utilities';
const argv = yargs
.demand(1)
.options({
recursive: {
alias: 'r',
default: false,
description: 'Create/update index files recursively. Halts on any unsafe "index.js" files.',
type: 'boolean'
}
})
.options({
ignoreUnsafe: {
alias: 'i',
default: false,
description: 'Ignores unsafe "index.js" files instead of halting.',
type: 'boolean'
}
})
.options({
ignoreDirectories: {
alias: 'd',
default: false,
description: 'Ignores importing directories into the index file, even if they have a safe "index.js".',
type: 'boolean'
}
})
.options({
update: {
alias: 'u',
default: false,
description: 'Updates only previously created index files (recursively).',
type: 'boolean'
}
})
.options({
banner: {
description: 'Add a custom banner at the top of the index file',
type: 'string'
}
})
.options({
extensions: {
alias: 'x',
default: ['js'],
description: 'Allows some extensions to be parsed as valid source. First extension will always be preferred to homonyms with another allowed extension.',
type: 'array'
}
})
.options({
implicitDefault: {
alias: 'm',
default: false,
description: 'Uses implicit defaults as implicit instead of explicit. export { default as thing } from \'./thing.js\' becomes export thing from \'./thing.js\'',
type: 'boolean'
}
})
.options({
wildcardFolders: {
alias: 'w',
default: false,
description: 'Export folders as wildcards instead of defaults. Works well with recursion.',
type: 'boolean'
}
})
.example(
'create-index ./src ./src/utilities',
'Creates or updates an existing create-index index file in the target (./src, ./src/utilities) directories.'
)
.example(
'create-index --update ./src ./tests',
'Finds all create-index index files in the target directories and descending directories. Updates found index files.'
)
.example(
'create-index ./src --extensions js jsx',
'Creates or updates an existing create-index index file in the target (./src) directory for both .js and .jsx extensions.'
)
.argv;
writeIndexCli(argv._, {
banner: argv.banner,
extensions: argv.extensions,
ignoreDirectories: argv.ignoreDirectories,
ignoreUnsafe: argv.ignoreUnsafe,
implicitDefault: argv.implicitDefault,
recursive: argv.recursive,
updateIndex: argv.update,
wildcardFolders: argv.wildcardFolders
});