Skip to content
This repository has been archived by the owner on Apr 4, 2020. It is now read-only.

Commit

Permalink
Modify webpack config (#2)
Browse files Browse the repository at this point in the history
* Make reset/clean recursive
* do the build directly
* log errors
* success message
* manually edit config file
  • Loading branch information
TheJaredWilcurt committed Jul 19, 2018
1 parent 3889714 commit b726415
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 23 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -9,7 +9,8 @@
"test": "nw .",
"lint": "eslint --config=.eslintrc.js postinstall.js resetandclean.js",
"fix": "eslint --fix --config=.eslintrc.js postinstall.js resetandclean.js",
"clean": "node resetandclean.js"
"clean": "node resetandclean.js",
"reset": "node resetandclean.js"
},
"chromium-args": "--load-extension='./extension'",
"devDependencies": {
Expand Down
62 changes: 58 additions & 4 deletions postinstall.js
Expand Up @@ -12,6 +12,7 @@ let postInstall = {
originalDir: __dirname + '',
clonedLocation: path.join(__dirname, 'src', 'vue-devtools'),
builtExtension: path.join(__dirname, 'src', 'vue-devtools', 'shells', 'chrome'),
buildConfig: path.join(__dirname, 'src', 'vue-devtools', 'shells', 'createConfig.js'),
destination: path.join(__dirname, 'extension'),
flagFile: path.join(__dirname, 'extension', 'flag.txt')
},
Expand All @@ -31,6 +32,12 @@ let postInstall = {
} catch (err) {
this.data.anErrorOccured = true;
console.log('Vue-DevTools:', err);
if (err.stderr) {
console.log('STDERR: ' + err.stderr.toString());
}
if (err.stdout) {
console.log('STDOUT: ' + err.stdout.toString());
}
}
},
/**
Expand Down Expand Up @@ -60,7 +67,10 @@ let postInstall = {
if (fs.existsSync(this.data.clonedLocation)) {
this.cleanClonedLocation();
}
console.log('Vue-DevTools: Downloading Vue-DevTools source code');
if (this.data.anErrorOccured) {
return;
}
console.log('Vue-DevTools: Downloading latest Vue-DevTools source code');

let executable = 'git clone --quiet';
let url = 'https://github.com/vuejs/vue-devtools.git';
Expand Down Expand Up @@ -108,15 +118,54 @@ let postInstall = {

process.chdir(this.data.originalDir);
},
modifyWebpackConfig: function () {
if (this.data.anErrorOccured) {
return;
}
console.log('Vue-DevTools: Modifying Webpack Configuration');

let config = '';

try {
config = fs.readFileSync(this.data.buildConfig);
} catch (err) {
console.log('Vue-DevTools: Error reading Vue-Devtools config file.');
this.data.anErrorOccured = true;
return;
}

config = String(config);
// Convert CRLF to LF
config = config.split('\r\n').join('\n');
config = config.split('\n');

config = config.filter(function (line) {
return !line.includes('exclude: /node_modules');
});

config = config.join('\n');

try {
fs.writeFileSync(this.data.buildConfig, config);
} catch (err) {
console.log('Vue-DevTools: Error writing Vue-Devtools config file.');
this.data.anErrorOccured = true;
return;
}
},
npmRunBuild: function () {
if (this.data.anErrorOccured) {
return;
}
console.log('Vue-DevTools: Building Vue-DevTools');

process.chdir(this.data.clonedLocation);
process.chdir(this.data.builtExtension);

this.runner('npm run build');
if (process.platform === 'win32') {
this.runner('..\\..\\node_modules\\.bin\\webpack.cmd --hide-modules');
} else {
this.runner('node ../../node_modules/.bin/webpack --hide-modules');
}

process.chdir(this.data.originalDir);
},
Expand Down Expand Up @@ -155,11 +204,16 @@ let postInstall = {
}
this.gitClone();
this.npmInstall();
this.modifyWebpackConfig();
this.npmRunBuild();
this.relocateDevTools();
this.setSuccessFlag();

console.log('Vue-DevTools: Success.');
if (this.data.anErrorOccured) {
console.log('Vue-DevTools: Finished with errors.');
} else {
console.log('Vue-DevTools: Success.');
}
}
};

Expand Down
46 changes: 28 additions & 18 deletions resetandclean.js
Expand Up @@ -6,6 +6,7 @@ let exec = require('child_process').execSync;

let taskRunner = {
runner: function (args) {
console.log(args);
try {
let runner = exec(args);

Expand All @@ -17,27 +18,36 @@ let taskRunner = {
// console.log(err);
}
},
resetAndClean: function () {
if (process.platform === 'win32') {
this.runner('rd /s /q src');
this.runner('rd /s /q src');
this.runner('rd /s /q src');
this.runner('rd /s /q extension');
this.runner('rd /s /q extension');
this.runner('rd /s /q extension');
this.runner('rd /s /q node_modules');
this.runner('rd /s /q node_modules');
this.runner('rd /s /q node_modules');
} else {
this.runner('rm -r -f src');
this.runner('rm -r -f extension');
this.runner('rm -r -f node_modules');
deleteFolder: function (folder) {
let directory = path.join('.', folder);

if (fs.existsSync(directory)) {
if (process.platform === 'win32') {
this.runner('rd /s /q ' + folder);
} else {
this.runner('rm -r -f ' + folder);
}
}
if (fs.existsSync(directory)) {
this.deleteFolder(folder);
}
},
deleteFile: function (file) {
let item = path.join('.', file);

let lock = path.join('.', 'package-lock.json');
if (fs.existsSync(lock)) {
fs.unlinkSync(lock);
if (fs.existsSync(item)) {
fs.unlinkSync(item);
}

if (fs.existsSync(item)) {
this.deleteFile(file);
}
},
resetAndClean: function () {
this.deleteFolder('src');
this.deleteFolder('extension');
this.deleteFolder('node_modules');
this.deleteFile('package-lock.json');
}
};

Expand Down

0 comments on commit b726415

Please sign in to comment.