Skip to content

Commit

Permalink
Apply Prettier (mdn#5250)
Browse files Browse the repository at this point in the history
  • Loading branch information
queengooborg authored and ddbeck committed Dec 3, 2019
1 parent 781b1c9 commit a3a55b4
Show file tree
Hide file tree
Showing 14 changed files with 339 additions and 200 deletions.
4 changes: 2 additions & 2 deletions scripts/compare-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
*/

const compareFeatures = (a,b) => {
const compareFeatures = (a, b) => {
if (a == '__compat') return -1;
if (b == '__compat') return 1;

Expand All @@ -34,6 +34,6 @@ const compareFeatures = (a,b) => {
return 1;
}
return a.localeCompare(b, 'en');
}
};

module.exports = compareFeatures;
33 changes: 18 additions & 15 deletions scripts/fix-browser-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,34 @@ const { platform } = require('os');
const IS_WINDOWS = platform() === 'win32';

const orderSupportBlock = (key, value) => {
if (key === "__compat") {
value.support = Object.keys(value.support).sort().reduce((result, key) => {
result[key] = value.support[key];
return result;
}, {});
if (key === '__compat') {
value.support = Object.keys(value.support)
.sort()
.reduce((result, key) => {
result[key] = value.support[key];
return result;
}, {});
}
return value;
};

/**
* @param {Promise<void>} filename
*/
const fixBrowserOrder = (filename) => {
let actual = fs.readFileSync(filename, 'utf-8').trim();
/**
* @param {Promise<void>} filename
*/
const fixBrowserOrder = filename => {
let actual = fs.readFileSync(filename, 'utf-8').trim();
let expected = JSON.stringify(JSON.parse(actual, orderSupportBlock), null, 2);

if (IS_WINDOWS) { // prevent false positives from git.core.autocrlf on Windows
actual = actual.replace(/\r/g, '');
if (IS_WINDOWS) {
// prevent false positives from git.core.autocrlf on Windows
actual = actual.replace(/\r/g, '');
expected = expected.replace(/\r/g, '');
}

if (actual !== expected) {
fs.writeFileSync(filename, expected + '\n', 'utf-8');
}
}
};

if (require.main === module) {
/**
Expand All @@ -72,7 +75,7 @@ if (require.main === module) {
continue;
}

const subFiles = fs.readdirSync(file).map((subfile) => {
const subFiles = fs.readdirSync(file).map(subfile => {
return path.join(file, subfile);
});

Expand All @@ -93,7 +96,7 @@ if (require.main === module) {
'mathml',
'test',
'webdriver',
'webextensions'
'webextensions',
);
}
}
Expand Down
31 changes: 17 additions & 14 deletions scripts/fix-feature-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,33 @@ const compareFeatures = require('./compare-features');

function orderFeatures(key, value) {
if (value instanceof Object && '__compat' in value) {
value = Object.keys(value).sort(compareFeatures).reduce((result, key) => {
result[key] = value[key];
return result;
}, {});
value = Object.keys(value)
.sort(compareFeatures)
.reduce((result, key) => {
result[key] = value[key];
return result;
}, {});
}
return value;
}

/**
* @param {Promise<void>} filename
*/
const fixFeatureOrder = (filename) => {
let actual = fs.readFileSync(filename, 'utf-8').trim();
/**
* @param {Promise<void>} filename
*/
const fixFeatureOrder = filename => {
let actual = fs.readFileSync(filename, 'utf-8').trim();
let expected = JSON.stringify(JSON.parse(actual, orderFeatures), null, 2);

if (IS_WINDOWS) { // prevent false positives from git.core.autocrlf on Windows
actual = actual.replace(/\r/g, '');
if (IS_WINDOWS) {
// prevent false positives from git.core.autocrlf on Windows
actual = actual.replace(/\r/g, '');
expected = expected.replace(/\r/g, '');
}

if (actual !== expected) {
fs.writeFileSync(filename, expected + '\n', 'utf-8');
}
}
};

if (require.main === module) {
/**
Expand All @@ -74,7 +77,7 @@ if (require.main === module) {
continue;
}

const subFiles = fs.readdirSync(file).map((subfile) => {
const subFiles = fs.readdirSync(file).map(subfile => {
return path.join(file, subfile);
});

Expand All @@ -95,7 +98,7 @@ if (require.main === module) {
'mathml',
'test',
'webdriver',
'webextensions'
'webextensions',
);
}
}
Expand Down
7 changes: 3 additions & 4 deletions scripts/fix.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const path = require('path');
const fixBrowserOrder = require('./fix-browser-order');
const fixFeatureOrder = require('./fix-feature-order');


const promises = [];

/**
Expand All @@ -17,7 +16,7 @@ function load(...files) {
}

if (!fs.existsSync(file)) {
console.warn("File not found, skipping:", file);
console.warn('File not found, skipping:', file);
continue; // Ignore non-existent files
}

Expand All @@ -30,7 +29,7 @@ function load(...files) {
continue;
}

const subFiles = fs.readdirSync(file).map((subfile) => {
const subFiles = fs.readdirSync(file).map(subfile => {
return path.join(file, subfile);
});

Expand All @@ -51,6 +50,6 @@ if (process.argv[2]) {
'mathml',
'test',
'webdriver',
'webextensions'
'webextensions',
);
}
136 changes: 84 additions & 52 deletions scripts/release-notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,49 @@ const chalk = require('chalk');

const bcd = require('..');

const { argv } = require('yargs')
.command('$0 <version-tag>', 'Initiate a release of this package on GitHub', (yargs) => {
const { argv } = require('yargs').command(
'$0 <version-tag>',
'Initiate a release of this package on GitHub',
yargs => {
yargs.positional('version-tag', {
describe: 'the version tag to generate release notes for',
type: 'string',
});
});

const getJSON = (url) => new Promise((resolve, reject) => http.get(url, { headers: { 'User-Agent': 'bcd-release-script' } }, (response) => {
let body = '';
response.on('data', (data) => {
body += data;
});
response.on('error', error => reject(error));
response.on('end', () => {
resolve(JSON.parse(body));
});
}));

const question = (query) => {
},
);

const getJSON = url =>
new Promise((resolve, reject) =>
http.get(
url,
{ headers: { 'User-Agent': 'bcd-release-script' } },
response => {
let body = '';
response.on('data', data => {
body += data;
});
response.on('error', error => reject(error));
response.on('end', () => {
resolve(JSON.parse(body));
});
},
),
);

const question = query => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
output: process.stdout,
});
return new Promise(resolve => rl.question(query, resolve))
.then((response) => {
rl.close();
return response;
});
}
return new Promise(resolve => rl.question(query, resolve)).then(response => {
rl.close();
return response;
});
};

const confirm = (str) => !['n', 'no'].includes(str.toLowerCase());
const confirm = str => !['n', 'no'].includes(str.toLowerCase());

const prompt = async (questions) => {
const prompt = async questions => {
const results = {};
for (const q of questions) {
const options = q.type === confirm ? '(Y/n) ' : '';
Expand All @@ -47,19 +56,28 @@ const prompt = async (questions) => {
return results;
};

const stargazers = () => getJSON('https://api.github.com/repos/mdn/browser-compat-data').then(json => json.stargazers_count);
const stargazers = () =>
getJSON('https://api.github.com/repos/mdn/browser-compat-data').then(
json => json.stargazers_count,
);

const stats = (version, previousVersion) => {
// Get just the diff stats summary
const diff = execSync(`git diff --shortstat ${previousVersion}...${version}`, { encoding: 'utf8' })
.trim();
const diff = execSync(
`git diff --shortstat ${previousVersion}...${version}`,
{ encoding: 'utf8' },
).trim();
// Extract the numbers from a line like this:
// 50 files changed, 1988 insertions(+), 2056 deletions(-)
const [, changed, insertions, deletions] = diff.match(/(\d+) files* changed, (\d+) insertions*\(\+\), (\d+) deletions*/);
const [, changed, insertions, deletions] = diff.match(
/(\d+) files* changed, (\d+) insertions*\(\+\), (\d+) deletions*/,
);

// Get the number of commits
const commits = execSync(`git rev-list --count ${previousVersion}...${version}`, { encoding: 'utf8' })
.trim();
const commits = execSync(
`git rev-list --count ${previousVersion}...${version}`,
{ encoding: 'utf8' },
).trim();

return {
commits,
Expand All @@ -69,24 +87,27 @@ const stats = (version, previousVersion) => {
};
};

const contributors = (version, previousVersion) => prompt([
{
name: 'releaseContributors',
type: Number,
message: `Find "contributors" at https://github.com/mdn/browser-compat-data/compare/${previousVersion}...${version}\nHow many people have contributed to this release?`,
},
{
name: 'totalContributors',
type: Number,
message: 'Find "contributors" at https://github.com/mdn/browser-compat-data/\nHow many people have contributed to browser-compat-data overall?',
},
]);
const contributors = (version, previousVersion) =>
prompt([
{
name: 'releaseContributors',
type: Number,
message: `Find "contributors" at https://github.com/mdn/browser-compat-data/compare/${previousVersion}...${version}\nHow many people have contributed to this release?`,
},
{
name: 'totalContributors',
type: Number,
message:
'Find "contributors" at https://github.com/mdn/browser-compat-data/\nHow many people have contributed to browser-compat-data overall?',
},
]);

const notableChanges = async () => {
const { result } = await prompt([
{
name: 'result',
message: 'Does this release contain any schema, test, or infrastructure changes?',
message:
'Does this release contain any schema, test, or infrastructure changes?',
type: confirm,
},
]);
Expand All @@ -99,8 +120,8 @@ const notableChanges = async () => {

const countFeatures = () => {
let count = 0;
JSON.parse(JSON.stringify(bcd), (k) => {
if (k === '__compat' ) {
JSON.parse(JSON.stringify(bcd), k => {
if (k === '__compat') {
count++;
}
return count;
Expand All @@ -112,18 +133,29 @@ const makeURL = (version, body) => {
const baseURL = 'https://github.com/mdn/browser-compat-data/releases/new';

// Adhering to RFC 3986 makes the full link clickable in Terminal.app
const encodedBody = encodeURIComponent(body).replace(/[!'()*]/g, c => `%${c.charCodeAt(0).toString(16)}`);
const encodedBody = encodeURIComponent(body).replace(
/[!'()*]/g,
c => `%${c.charCodeAt(0).toString(16)}`,
);

return `${baseURL}?title=${version}&tag=${version}&body=${encodedBody}`;
};

const main = async () => {
const version = argv.versionTag;
const previousVersion = execSync(`git describe --abbrev=0 ${version}^`, { encoding: 'utf8' }).trim();

const { commits, changed, insertions, deletions } = stats(version, previousVersion);

const { releaseContributors, totalContributors } = await contributors(version, previousVersion);
const previousVersion = execSync(`git describe --abbrev=0 ${version}^`, {
encoding: 'utf8',
}).trim();

const { commits, changed, insertions, deletions } = stats(
version,
previousVersion,
);

const { releaseContributors, totalContributors } = await contributors(
version,
previousVersion,
);
const changeMessage = await notableChanges();
const stars = await stargazers();
const features = countFeatures();
Expand Down
Loading

0 comments on commit a3a55b4

Please sign in to comment.