Skip to content

Commit 823114e

Browse files
authored
Merge pull request #50 from jelhan/configurable-path
Add support for passing paths or glob patterns as CLI options
2 parents 7c84f9e + 9d5af1d commit 823114e

3 files changed

Lines changed: 60 additions & 6 deletions

File tree

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,42 @@ export default Component.extend({
5050
```
5151

5252

53+
Configuration
54+
------------------------------------------------------------------------------
55+
56+
### Paths
57+
58+
By default, `tagless-ember-components-codemod` will process components in the
59+
following folders relatively to project root:
60+
61+
```
62+
app/components
63+
addon/components
64+
```
65+
66+
You may pass alternative paths or globs as arguments:
67+
68+
```bash
69+
# process one component only
70+
npx tagless-ember-components-codemod app/components/my-component.js
71+
72+
# process a component and all components under it's namespace
73+
npx tagless-ember-components-codemod app/components/my-component.js app/components/my-component/
74+
75+
# process all components matching a glob
76+
npx tagless-ember-components-codemod app/components/**/foo-*.js
77+
```
78+
79+
### Debug
80+
81+
Debug logging could be enabled by setting `DEBUG` environment variable to
82+
`tagless-ember-components-codemod`:
83+
84+
```bash
85+
DEBUG=tagless-ember-components-codemod npx tagless-ember-components-codemod
86+
```
87+
88+
5389
Known Caveats
5490
------------------------------------------------------------------------------
5591

bin/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
const chalk = require('chalk');
66
const { run } = require('../lib/index');
77

8-
run().catch(error => {
8+
run(process.argv).catch(error => {
99
process.exitCode = 1;
1010
console.error(chalk.red(error.stack));
1111
});

lib/index.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,39 @@ const chalk = require('chalk');
77
const SilentError = require('./silent-error');
88
const { transformPath } = require('./transform');
99

10-
async function run() {
11-
let path = await pkgDir();
12-
await runForPath(path);
10+
async function run(argv) {
11+
let patterns = argv.slice(2);
12+
if (patterns.length !== 0) {
13+
await runForGlobs(patterns, process.cwd());
14+
} else {
15+
let baseDir = await pkgDir();
16+
await runForPath(baseDir);
17+
}
1318
}
1419

1520
async function runForPath(path, options = {}) {
1621
debug('runForPath(%o, %o)', path, options);
1722

23+
let patterns = ['app/components/**/*.js', 'addon/components/**/*.js'];
24+
await runForGlobs(patterns, path, options);
25+
}
26+
27+
async function runForGlobs(patterns, cwd, options = {}) {
28+
debug('runForGlobs(%o, %o, %o)', patterns, cwd, options);
29+
1830
let log = options.log || console.log;
1931

2032
log(` 🔍 Searching for component files...`);
21-
let paths = await globby(['app/components/**/*.js', 'addon/components/**/*.js'], { cwd: path });
33+
let paths = await globby(patterns, {
34+
cwd,
35+
expandDirectories: {
36+
extensions: ['js'],
37+
},
38+
});
2239
debug('componentPaths = %O', paths);
2340

24-
let pkgContent = fs.readFileSync(`${path}/package.json`);
41+
let packageRoot = await pkgDir(cwd);
42+
let pkgContent = fs.readFileSync(`${packageRoot}/package.json`);
2543
let pkg = JSON.parse(pkgContent);
2644
let hasComponentCSS =
2745
pkg.dependencies['ember-component-css'] || pkg.devDependencies['ember-component-css'];

0 commit comments

Comments
 (0)