Skip to content

Commit 37ba9b2

Browse files
committed
Add ignore option to component generation.
1 parent 75a285f commit 37ba9b2

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

dash/development/component_generator.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ class _CombinedFormatter(argparse.ArgumentDefaultsHelpFormatter,
2222

2323
# pylint: disable=too-many-locals
2424
def generate_components(components_source, project_shortname,
25-
package_info_filename='package.json'):
25+
package_info_filename='package.json',
26+
ignore='^_'):
2627
is_windows = sys.platform == 'win32'
2728

2829
extract_path = pkg_resources.resource_filename('dash', 'extract-meta.js')
2930

3031
os.environ['NODE_PATH'] = 'node_modules'
31-
cmd = shlex.split('node {} {}'.format(extract_path, components_source),
32-
posix=not is_windows)
32+
cmd = shlex.split(
33+
'node {} {} {}'.format(extract_path, ignore, components_source),
34+
posix=not is_windows
35+
)
3336

3437
shutil.copyfile('package.json',
3538
os.path.join(project_shortname, package_info_filename))
@@ -83,10 +86,18 @@ def cli():
8386
default='package.json',
8487
help='The filename of the copied `package.json` to `project_shortname`'
8588
)
89+
parser.add_argument(
90+
'-i', '--ignore',
91+
default='^_',
92+
help='Files/directories matching the pattern will be ignored'
93+
)
8694

8795
args = parser.parse_args()
88-
generate_components(args.components_source, args.project_shortname,
89-
package_info_filename=args.package_info_filename)
96+
generate_components(
97+
args.components_source, args.project_shortname,
98+
package_info_filename=args.package_info_filename,
99+
ignore=args.ignore
100+
)
90101

91102

92103
if __name__ == '__main__':

dash/extract-meta.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ const fs = require('fs');
44
const path = require('path');
55
const reactDocs = require('react-docgen');
66

7-
const componentPaths = process.argv.slice(2);
7+
const componentPaths = process.argv.slice(3);
8+
const ignorePattern = new RegExp(process.argv[2]);
9+
10+
const excludedDocProps = [
11+
'setProps', 'id', 'className', 'style', 'dashEvents', 'fireEvent'
12+
];
13+
814
if (!componentPaths.length) {
915
help();
1016
process.exit(1);
@@ -36,8 +42,7 @@ function writeError(msg, filePath) {
3642
}
3743

3844
function checkWarn(name, value) {
39-
const excluded = ['setProps', 'id', 'className', 'style', 'dashEvents', 'fireEvent'];
40-
if (value.length < 1 && !excluded.includes(name)) {
45+
if (value.length < 1 && !excludedDocProps.includes(name.split('.').pop())) {
4146
process.stderr.write(`\nDescription for ${name} is missing!\n`)
4247
}
4348
}
@@ -69,6 +74,9 @@ function parseFile(filepath) {
6974
}
7075

7176
function collectMetadataRecursively(componentPath) {
77+
if (ignorePattern.test(componentPath)) {
78+
return;
79+
}
7280
if (fs.lstatSync(componentPath).isDirectory()) {
7381
let dirs;
7482
try {
@@ -80,11 +88,11 @@ function collectMetadataRecursively(componentPath) {
8088
const filepath = path.join(componentPath, filename);
8189
if (fs.lstatSync(filepath).isDirectory()) {
8290
collectMetadataRecursively(filepath);
83-
} else {
91+
} else if (!ignorePattern.test(filename)) {
8492
parseFile(filepath);
8593
}
8694
});
87-
} else {
95+
} else if (!ignorePattern.test(componentPath)) {
8896
parseFile(componentPath);
8997
}
9098
}

0 commit comments

Comments
 (0)