Skip to content

Commit

Permalink
Update npm optout: copy files instead of modifying (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Jun 5, 2019
1 parent a24d2ea commit 91a04b4
Show file tree
Hide file tree
Showing 5 changed files with 520 additions and 549 deletions.
46 changes: 8 additions & 38 deletions check.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,10 @@ if (disabledForMachine || disabledForProject) {
`);
}
try {
fs.renameSync('vaadin-usage-statistics.js', 'vaadin-usage-statistics.js.bak');
fs.copyFileSync('vaadin-usage-statistics-optout.js', 'vaadin-usage-statistics.js');
} catch (err) {
if (err.code === 'ENOENT') {
console.log('File not found!');
} else {
throw err;
}
}

try {
fs.renameSync('vaadin-usage-statistics-optout.js', 'vaadin-usage-statistics.js');
} catch (err) {
if (err.code === 'ENOENT') {
console.log('File not found!');
} else {
throw err;
}
console.log('Error while copying file!');
throw err;
}
} else {
console.log(`
Expand All @@ -55,28 +42,11 @@ if (disabledForMachine || disabledForProject) {
For more details, see https://github.com/vaadin/vaadin-usage-statistics
`);
/* restore backup files if previously disabled */
if (fs.existsSync('vaadin-usage-statistics.js.bak')) {
try {
fs.renameSync('vaadin-usage-statistics.js', 'vaadin-usage-statistics-optout.js');
} catch (err) {
if (err.code === 'ENOENT') {
console.log('File not found!');
} else {
throw err;
}
}

try {
fs.renameSync('vaadin-usage-statistics.js.bak', 'vaadin-usage-statistics.js');
} catch (err) {
if (err.code === 'ENOENT') {
console.log('File not found!');

} else {
throw err;
}
}
try {
fs.copyFileSync('vaadin-usage-statistics-collect.js', 'vaadin-usage-statistics.js');
} catch (err) {
console.log('Error while copying file!');
throw err;
}
}

6 changes: 3 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { promisify } = require('util');
const exec = promisify(require('child_process').exec);

async function rebuild() {
await fs.remove(path.join(__dirname, 'vaadin-usage-statistics.html'));
await fs.remove(path.join(__dirname, 'vaadin-usage-statistics-collect.html'));

const template = await fs.readFile(
path.join(__dirname, 'src/vaadin-usage-statistics.tpl.html'), 'utf-8');
Expand All @@ -17,7 +17,7 @@ async function rebuild() {
path.join(__dirname, 'vaadin-usage-statistics.es5.js'), 'utf-8');

await fs.outputFile(
path.join(__dirname, 'vaadin-usage-statistics.html'),
path.join(__dirname, 'vaadin-usage-statistics-collect.html'),
'<!-- This file is autogenerated from src/vaadin-usage-statistics.tpl.html -->\n' +
template.replace('${vaadin-usage-statistics.js}', bundle));

Expand All @@ -37,7 +37,7 @@ gulp.task('auto-amend-commit', async () => {
const depsStaged = rc.stdout.split('\n').some(file => deps.includes(file));
if (depsStaged) {
await rebuild();
await exec('git add vaadin-usage-statistics.html');
await exec('git add vaadin-usage-statistics-collect.html');
}
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"IE 11"
],
"files": [
"vaadin-usage-statistics.js",
"vaadin-usage-statistics-collect.js",
"vaadin-usage-statistics-optout.js",
"check.js"
],
Expand Down
Loading

0 comments on commit 91a04b4

Please sign in to comment.