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

refactor(route/caniuse): merge respec-caniuse-route to main #146

Merged
merged 2 commits into from Feb 18, 2021

Conversation

sidvishnoi
Copy link
Member

@sidvishnoi sidvishnoi commented Feb 17, 2021

  1. Brings https://github.com/sidvishnoi/respec-caniuse-route into this repo. I've chosen routes/caniuse/lib as the destination.
- import { createResponseBody } from "respec-caniuse-route";
+ import { createResponseBody } from "./lib/index.js";
  1. Added a sh utility, which respec-caniuse-route/scraper and others can use consistently. I've used this it in spec-prod, so it's "well tested".
- const args = shouldClone
-   ? ['clone', 'https://github.com/Fyrd/caniuse.git', 'caniuse-raw']
-   : ['pull', 'origin', 'master'];
- const cwd = shouldClone ? path.resolve(DATA_DIR) : dataDir;

- return new Promise<boolean>((resolve, reject) => {
-   const git = spawn('git', args, { cwd });
-   let hasUpdated = true;
-   git.stdout.on('data', (data: ArrayBuffer) => {
-     hasUpdated = !data.toString().includes('Already up to date');
-   });
-   git.on('error', reject);
-   git.on('exit', (code: number) => {
-     if (code !== 0) {
-       reject(new Error(`The process exited with code ${code}`));
-     } else {
-       resolve(hasUpdated);
-     }
-   });
- });
+ const stdout = await sh(command, { cwd, output: "stream" });
+ const hasUpdated = !stdout.toString().includes("Already up to date");
+ return hasUpdated;
  1. routes/caniuse/lib/index.ts makes use of ucontent instead of manipulating template strings. i.e.
-  return `<button class="${className}" title="${title}">${text}</button>`;
+  return html`<button class="${className}" title="${title}">${text}</button>`;
  1. routes/caniuse/lib/scraper.ts does shallow git clone/pull to save space on server (from 125MB to 25MB). i.e.
- ['clone', 'https://github.com/Fyrd/caniuse.git', 'caniuse-raw']
+ `git clone ${INPUT_REPO_SRC} ${INPUT_REPO_NAME} --filter=blob:none`
  1. routes/caniuse/lib/index.ts uses utils/mem-cache instead of its own cache.
  2. No changes for end user.

@sidvishnoi sidvishnoi changed the title refactor(route/caniuse): merge sidvishnmoi/respec-caniuse-route to main refactor(route/caniuse): merge respec-caniuse-route to main Feb 17, 2021
Copy link
Member

@marcoscaceres marcoscaceres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants