Skip to content

Commit 3b8274a

Browse files
committed
Specify a path
By default, `ember-modules-codemode` will modify files in those folders: "app", "addon", "addon-test-support", "tests", "test-support", "lib" If you want to run a change in another folder, you can specify a path: ```ember-modules-codemod path_to_use```
1 parent bb21d2d commit 3b8274a

2 files changed

Lines changed: 47 additions & 5 deletions

File tree

__tests__/bin-test.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ const originalCwd = process.cwd();
99

1010
let tmpPath;
1111

12-
function run() {
12+
function run(codemodArgs) {
1313
let stdout = '';
1414
let stderr = '';
1515

1616
return new Promise(resolve => {
17-
let ps = cp.spawn('node', [
18-
path.join(originalCwd, 'bin/ember-modules-codemod')
19-
], {
17+
let codemodCmd = [path.join(originalCwd, 'bin/ember-modules-codemod')];
18+
if(codemodArgs) {
19+
codemodCmd = codemodCmd.concat(codemodArgs);
20+
}
21+
let ps = cp.spawn('node', codemodCmd, {
2022
cwd: tmpPath
2123
});
2224

@@ -153,5 +155,36 @@ describe('bin acceptance', function() {
153155
});
154156
});
155157
});
158+
159+
describe('with a custom path', function() {
160+
let tmpFile;
161+
const inputFile = path.join(originalCwd, '__testfixtures__/final-boss.input.js');
162+
const outputFile = path.join(originalCwd, '__testfixtures__/final-boss.output.js');
163+
164+
165+
beforeEach(function() {
166+
fs.ensureDirSync(path.join(tmpPath, 'custom-path'));
167+
168+
tmpFile = path.join(tmpPath, 'custom-path/final-boss.js');
169+
170+
fs.copySync(
171+
inputFile,
172+
tmpFile
173+
);
174+
});
175+
176+
it('works', function() {
177+
return run('custom-path').then(result => {
178+
let exitCode = result.exitCode;
179+
let stdout = result.stdout;
180+
181+
expect(exitCode).toEqual(0);
182+
183+
expect(stdout).toMatch('Done! All uses of the Ember global have been updated.\n');
184+
185+
expect(fs.readFileSync(tmpFile, 'utf8')).toEqual(fs.readFileSync(outputFile, 'utf8'));
186+
});
187+
});
188+
});
156189
});
157190
});

bin/ember-modules-codemod.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@ try {
2222
EMBER_MODULES_CODEMOD: true
2323
}, process.env);
2424

25-
let transform = execa(binPath, ["-t", transformPath, "app", "addon", "addon-test-support", "tests", "test-support", "lib"], {
25+
const args = process.argv;
26+
let jscodeshiftPaths;
27+
if (args[2]) {
28+
jscodeshiftPaths = [args[2]];
29+
} else {
30+
jscodeshiftPaths = ["app", "addon", "addon-test-support", "tests", "test-support", "lib"];
31+
}
32+
const jscodeshiftArgs = ["-t", transformPath].concat(jscodeshiftPaths);
33+
34+
let transform = execa(binPath, jscodeshiftArgs, {
2635
stdio: "inherit",
2736
env: env
2837
});

0 commit comments

Comments
 (0)