Skip to content

Commit

Permalink
fix: Use real paths from argvs instead of dummy hard-coded file (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
okonet authored Feb 22, 2017
1 parent 6a4a62b commit a46edbb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions bin/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,13 @@ var initInquirer = require('../lib/initialize');
if(argv.init) {
initInquirer(argv._);
} else if(argv.migrate) {
const dummyConfigLoc = require.resolve(path.join(process.cwd(), 'example/webpack.config.js'));
const outputConfigLoc = path.join(process.cwd(), 'example/neo-webpack.config.js');
require('../lib/migrate.js')(dummyConfigLoc, outputConfigLoc);
const filePaths = argv._;
if (!filePaths.length) {
throw new Error('Please specify a path to your webpack config');
}
const inputConfigPath = path.resolve(process.cwd(), filePaths[0]);

require('../lib/migrate.js')(inputConfigPath, inputConfigPath);
} else {
processOptions(yargs,argv);
}
8 changes: 4 additions & 4 deletions lib/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const chalk = require('chalk');
const transform = require('./transformations').transform;
const inquirer = require('inquirer');

module.exports = (currentConfigLoc, outputConfigLoc) => {
let currentConfig = fs.readFileSync(currentConfigLoc, 'utf8');
module.exports = (currentConfigPath, outputConfigPath) => {
let currentConfig = fs.readFileSync(currentConfigPath, 'utf8');
const outputConfig = transform(currentConfig);
const diffOutput = diff.diffLines(currentConfig, outputConfig);
diffOutput.map(diffLine => {
Expand All @@ -27,8 +27,8 @@ module.exports = (currentConfigLoc, outputConfigLoc) => {
.then(answers => {
if (answers['confirmMigration']) {
// TODO validate the config
fs.writeFileSync(outputConfigLoc, outputConfig, 'utf8');
process.stdout.write(chalk.green(`Congratulations! Your new webpack v2 config file is at ${outputConfigLoc}`));
fs.writeFileSync(outputConfigPath, outputConfig, 'utf8');
process.stdout.write(chalk.green(`Congratulations! Your new webpack v2 config file is at ${outputConfigPath}`));
} else {
process.stdout.write(chalk.yellow('Migration aborted'));
}
Expand Down

0 comments on commit a46edbb

Please sign in to comment.