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

feat: add degit spec #1030

Merged
merged 3 commits into from Mar 23, 2022
Merged

feat: add degit spec #1030

merged 3 commits into from Mar 23, 2022

Conversation

clo4
Copy link
Contributor

@clo4 clo4 commented Mar 16, 2022

Generator only works with plain github user/repo for now but that's all most people ever use anyway

image

@withfig-bot
Copy link
Collaborator

withfig-bot commented Mar 16, 2022

Overview

src/npx.ts:

Info:

Single Functions:

postProcess:

 function (out) {
        const cli = [...suggestions].reduce(
          (acc, { name }) => [...acc, name],
          []
        );
        return out
          .split("\n")
          .filter((name) => !cli.includes(name))
          .map((name) => ({
            name,
            icon: "fig://icon?type=command",
            loadSpec: name,
          }));
      }

URLs:

  • https://raw.githubusercontent.com/babel/logo/master/babel.png
  • https://reactnative.dev/img/pwa/manifest-icon-512.png
  • https://reactnative.dev/img/pwa/manifest-icon-512.png
  • https://tailwindcss.com/favicon-32x32.png
  • https://nextjs.org/static/favicon/favicon-16x16.png
  • https://raw.githubusercontent.com/pmndrs/branding/master/logo.svg
  • https://raw.githubusercontent.com/prisma/docs/main/src/images/favicon-16x16.png
  • https://eslint.org/assets/img/favicon.512x512.png
  • https://prettier.io/icon.png
  • https://upload.wikimedia.org/wikipedia/commons/thumb/4/4c/Typescript_logo_2020.svg/240px-Typescript_logo_2020.svg.png
  • https://avatars.githubusercontent.com/u/20165699?s=200&v=4
  • https://fig.io/icons/fig-light.png
  • https://fig.io/icons/fig-light.png
  • https://nextjs.org/static/favicon/favicon-16x16.png
  • https://raw.githubusercontent.com/remotion-dev/remotion/main/packages/docs/static/img/logo-small.png
  • https://raw.githubusercontent.com/remotion-dev/remotion/main/packages/docs/static/img/logo-small.png
  • https://remix.run/favicon-light.1.png
  • https://remix.run/favicon-light.1.png

src/yarn.ts:

Info:

Script:
cat "$(yarn global dir)/package.json"
script(function):

 function (context) {
    return `\cat ${context[context.length - 2]}/package.json`;
  }

Script:
cat "$(yarn global dir)/package.json"
postProcess(function):

 function (out) {
    if (out.trim() == "") {
      return [];
    }
    try {
      const packageContent = JSON.parse(out);
      const scripts = packageContent["scripts"];
      if (scripts) {
        return Object.keys(scripts).map((script) => ({ name: script }));
      }
    } catch (e) {}
    return [];
  }

Script:
yarn config list
postProcess(function):

 function (out) {
    if (out.trim() == "") {
      return [];
    }

    try {
      const startIndex = out.indexOf("{");
      const endIndex = out.indexOf("}");
      let output = out.substring(startIndex, endIndex + 1);
      // TODO: fix hacky code
      // reason: JSON parse was not working without double quotes
      output = output
        .replace(/\'/gi, '"')
        .replace("lastUpdateCheck", '"lastUpdateCheck"')
        .replace("registry", '"lastUpdateCheck"');
      const configObject = JSON.parse(output);
      if (configObject) {
        return Object.keys(configObject).map((key) => ({ name: key }));
      }
    } catch (e) {}

    return [];
  }

Script:
until [[ -f package.json ]] || [[ $PWD = '/' ]]; do cd ..; done; cat package.json
postProcess(function):

 function (out, context = []) {
    if (out.trim() === "") {
      return [];
    }

    try {
      const packageContent = JSON.parse(out);
      const dependencies = packageContent["dependencies"] ?? {};
      const devDependencies = packageContent["devDependencies"];
      const optionalDependencies = packageContent["optionalDependencies"] ?? {};
      Object.assign(dependencies, devDependencies, optionalDependencies);

      return Object.keys(dependencies)
        .filter((pkgName) => {
          const isListed = context.some((current) => current === pkgName);
          return !isListed;
        })
        .map((pkgName) => ({
          name: pkgName,
          icon: "📦",
          description: dependencies[pkgName]
            ? "dependency"
            : optionalDependencies[pkgName]
            ? "optionalDependency"
            : "devDependency",
        }));
    } catch (e) {
      console.error(e);
      return [];
    }
  }

Script:
until [[ -f package.json ]] || [[ $PWD = '/' ]]; do cd ..; done; cat package.json
script(function):

 function (context) {
    if (context[context.length - 1] === "") return "";
    const searchTerm = "create-" + context[context.length - 1];
    return `curl -s -H "Accept: application/json" "https://api.npms.io/v2/search?q=${searchTerm}&size=20"`;
  }

Script:
until [[ -f package.json ]] || [[ $PWD = '/' ]]; do cd ..; done; cat package.json
postProcess(function):

 function (out) {
    try {
      return JSON.parse(out).results.map(
        (item) =>
          ({
            name: item.package.name.substring(7),
            description: item.package.description,
          } as Fig.Suggestion)
      ) as Fig.Suggestion[];
    } catch (e) {
      return [];
    }
  }

URLs:

  • https://api.npms.io/v2/search?q=

src/degit.ts:

Info:

URLs:

  • https://api.github.com/users/

@withfig-bot
Copy link
Collaborator

Hello @SeparateRecords,
thank you very much for creating a Pull Request!
Here is a small checklist to get this PR merged as quickly as possible:

  • Do all subcommands / options which take arguments include the args property (args: {})?
  • Are all options modular? E.g. -a -u -x instead of -aux
  • Have all other checks passed?

Please add a 👍 as a reaction to this comment to show that you read this.

src/npx.ts Show resolved Hide resolved
@clo4 clo4 requested a review from fedeci March 23, 2022 06:12
fedeci
fedeci approved these changes Mar 23, 2022
Copy link
Member

@fedeci fedeci left a comment

Choose a reason for hiding this comment

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

Thanks!

@fedeci fedeci merged commit 9bdf79f into withfig:master Mar 23, 2022
4 checks passed
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

3 participants