Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🏗 Automatically write react.js files for bento components when publishing #34586

Merged
merged 4 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish-npm-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
run: |
npm install
node ./build-system/npm-publish/build-npm-binaries.js ${{ matrix.extension }}
node ./build-system/npm-publish/write-package-jsons.js ${{ matrix.extension }} ${{ github.event.inputs.ampversion }}
node ./build-system/npm-publish/write-package-files.js ${{ matrix.extension }} ${{ github.event.inputs.ampversion }}
- name: Publish v1
run: npm publish ./extensions/${{ matrix.extension }}/1.0 --access public --tag ${{ github.event.inputs.tag }}
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,34 @@

/**
* @fileoverview
* Creates package.json files for a given component and AMP version to be
* published on npm.
* Creates npm package files for a given component and AMP version.
*/

const [extension, ampVersion] = process.argv.slice(2);
const {log} = require('../common/logging');
const {stat, writeFile} = require('fs/promises');
const {valid} = require('semver');

async function writePackageJson(extensionVersion) {
/**
* Determines whether to skip
* @param {string} extensionVersion
* @return {Promise<boolean>}
*/
async function shouldSkip(extensionVersion) {
try {
await stat(`extensions/${extension}/${extensionVersion}`);
return false;
} catch {
log(`${extension} ${extensionVersion} : skipping, does not exist`);
return;
return true;
}
}

/**
* Write package.json
* @param {string} extensionVersion
*/
async function writePackageJson(extensionVersion) {
const extensionVersionArr = extensionVersion.split('.', 2);
const major = extensionVersionArr[0];
const minor = ampVersion.slice(0, 10);
Expand Down Expand Up @@ -105,5 +116,36 @@ async function writePackageJson(extensionVersion) {
}
}

writePackageJson('1.0');
writePackageJson('2.0');
/**
* Write react.js
* @param {string} extensionVersion
*/
async function writeReactJs(extensionVersion) {
const content = "module.exports = require('./dist/component-react');";
try {
await writeFile(
`extensions/${extension}/${extensionVersion}/react.js`,
content
);
log(extension, extensionVersion, ': created react.js');
} catch (e) {
log(e);
process.exitCode = 1;
return;
}
}

/**
* Main
*/
async function main() {
for (const version of ['1.0', '2.0']) {
if (await shouldSkip(version)) {
continue;
}
writePackageJson(version);
writeReactJs(version);
}
}

main();