readmes.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Since we moved our documentation to our website repo, we want to point to the
  3. * website from the docs in this repo
  4. *
  5. * This script write the link to the website in every READMEs.
  6. */
  7. const { join } = require("path");
  8. const { readdirSync, writeFileSync } = require("fs");
  9. const cwd = process.cwd();
  10. const packageDir = join(cwd, "packages");
  11. const packages = readdirSync(packageDir);
  12. const getWebsiteLink = n => `https://new.babeljs.io/docs/en/next/${n}.html`;
  13. const getPackageJson = pkg => require(join(packageDir, pkg, "package.json"));
  14. const generateReadme = ({ link, name, description }) =>
  15. `# ${name}
  16. > ${description}
  17. See our website [${name}](${link}) for more information.
  18. ## Install
  19. Using npm:
  20. \`\`\`sh
  21. npm install --save ${name}
  22. \`\`\`
  23. or using yarn:
  24. \`\`\`sh
  25. yarn add --save ${name}
  26. \`\`\`
  27. `;
  28. packages
  29. .filter(x => x !== "README.md") // ignore root readme
  30. .forEach(id => {
  31. const { name, description } = getPackageJson(id);
  32. const readmePath = join(packageDir, id, "README.md");
  33. // generate
  34. const link = getWebsiteLink(id);
  35. const readme = generateReadme({ link, name, description });
  36. // write
  37. writeFileSync(readmePath, readme);
  38. console.log("OK", id);
  39. });