Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🏗 Ensure that list on amp-video-interface.md is complete (#32810)
Successful `--fix` run: ```diff gulp check-video-interface-list --fix [09:21:06] Using gulpfile ~/git/amphtml/gulpfile.js [09:21:06] Starting 'check-video-interface-list'... diff --git a/spec/amp-video-interface.md b/spec/amp-video-interface.md index b67fb4364..a59bf9ec0 100644 --- a/spec/amp-video-interface.md +++ b/spec/amp-video-interface.md @@ -30,2 +30,3 @@ these players implement. - [amp-ima-video](https://amp.dev/documentation/components/amp-ima-video) +- [amp-jwplayer](https://amp.dev/documentation/components/amp-jwplayer) - [amp-minute-media-player](https://amp.dev/documentation/components/amp-minute-media-player) @@ -35,2 +36,3 @@ these players implement. - [amp-powr-player](https://amp.dev/documentation/components/amp-powr-player) +- [amp-redbull-player](https://amp.dev/documentation/components/amp-redbull-player) - [amp-vimeo](https://amp.dev/documentation/components/amp-vimeo) [09:21:07] Wrote spec/amp-video-interface.md [09:21:07] Finished 'check-video-interface-list' after 620 ms ``` A check failure run is the same, except it errors-out when the list is incomplete.
- Loading branch information
1 parent
319372d
commit 9648728
Showing
5 changed files
with
189 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Copyright 2021 The AMP HTML Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS-IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
const argv = require('minimist')(process.argv.slice(2)); | ||
const tempy = require('tempy'); | ||
const {blue, bold, cyan, red} = require('kleur/colors'); | ||
const {getStdout} = require('./process'); | ||
const {log, logWithoutTimestamp} = require('./logging'); | ||
const {writeFile} = require('fs-extra'); | ||
|
||
/** | ||
* Diffs a file against content that might replace it. | ||
* @param {string} filepath | ||
* @param {string} content | ||
* @return {!Promise<string>} | ||
*/ | ||
const diffTentative = (filepath, content) => | ||
tempy.write.task(content, (temporary) => | ||
getStdout(`git -c color.ui=always diff -U1 ${filepath} ${temporary}`) | ||
.trim() | ||
.replace(new RegExp(temporary, 'g'), `/${filepath}`) | ||
); | ||
|
||
/** | ||
* Diffs a file against new content. | ||
* If `argv.fix` is true, the file is written with the new content, otherwise | ||
* errors out. | ||
* @param {string} callerTask | ||
* @param {string} filepath | ||
* @param {string} tentative | ||
*/ | ||
async function writeDiffOrFail(callerTask, filepath, tentative) { | ||
const diff = await diffTentative(filepath, tentative); | ||
|
||
if (!diff.length) { | ||
return; | ||
} | ||
|
||
logWithoutTimestamp(); | ||
logWithoutTimestamp(diff); | ||
logWithoutTimestamp(); | ||
|
||
if (!argv.fix) { | ||
log(red('ERROR:'), cyan(filepath), 'is missing the changes above.'); | ||
log('⤷ To automatically apply them, run', cyan(`gulp ${callerTask} --fix`)); | ||
throw new Error(`${filepath} is outdated`); | ||
} | ||
|
||
await writeFile(filepath, tentative); | ||
log('Wrote', bold(blue(filepath))); | ||
} | ||
|
||
module.exports = { | ||
diffTentative, | ||
writeDiffOrFail, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* Copyright 2021 The AMP HTML Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS-IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
const globby = require('globby'); | ||
const {getStdout} = require('../common/process'); | ||
const {readFile} = require('fs-extra'); | ||
const {writeDiffOrFail} = require('../common/diff'); | ||
|
||
/** Checks or updates 3rd party video player list on this Markdown file. */ | ||
const filepath = 'spec/amp-video-interface.md'; | ||
|
||
/** Excludes these extensions since they're on a separate list. */ | ||
const excludeGeneric = ['amp-video', 'amp-video-iframe']; | ||
|
||
/** Determines whether a file belongs to an extension that should be listed. */ | ||
const grepJsContent = '@implements {.*VideoInterface}'; | ||
|
||
/** Finds extension files here. */ | ||
const grepJsFiles = 'extensions/**/*.js'; | ||
|
||
/** | ||
* Returns a formatted list entry. | ||
* @param {string} name | ||
* @return {name} | ||
*/ | ||
const entry = (name) => | ||
`- [${name}](https://github.com/ampproject/amphtml/blob/master/extensions/${name}/${name}.md)\n`; | ||
|
||
/** | ||
* Generates Markdown list by finding matching extensions. | ||
* @return {string} | ||
*/ | ||
const generateList = () => | ||
getStdout( | ||
['grep -lr', `"${grepJsContent}"`, ...globby.sync(grepJsFiles)].join(' ') | ||
) | ||
.trim() | ||
.split('\n') | ||
.reduce((list, path) => { | ||
const name = path.substr('extensions/'.length).split('/').shift(); | ||
return list + (excludeGeneric.includes(name) ? '' : entry(name)); | ||
}, ''); | ||
|
||
/** | ||
* Returns a RegExp that matches the existing list. | ||
* @return {RegExp} | ||
*/ | ||
const getListRegExp = () => | ||
new RegExp( | ||
`(${entry('NAME') | ||
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') | ||
.replace(/\NAME/g, `((?!${excludeGeneric.join('|')})[a-z0-9-]+)`)})+`, | ||
'gim' | ||
); | ||
|
||
/** | ||
* Checks or updates 3rd party video player list. | ||
*/ | ||
async function checkVideoInterfaceList() { | ||
const current = await readFile(filepath, 'utf-8'); | ||
const tentative = current.replace(getListRegExp(), generateList()); | ||
if (current !== tentative) { | ||
await writeDiffOrFail('check-video-interface-list', filepath, tentative); | ||
} | ||
} | ||
|
||
module.exports = { | ||
checkVideoInterfaceList, | ||
}; | ||
|
||
checkVideoInterfaceList.description = `Checks or updates 3rd party video player list on ${filepath}`; | ||
|
||
checkVideoInterfaceList.flags = { | ||
'fix': ' Write to file', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters