Skip to content

Commit

Permalink
update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
stevensacks committed Nov 27, 2023
1 parent 5b46dfc commit 3692f76
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 22 deletions.
31 changes: 28 additions & 3 deletions scripts/eject-typescript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,32 @@ await $`cp -r ./src ./srcTS`;
await $`rm -rf ./src`;
await $`mkdir ./src`;

// Install Babel and TS preset
console.log(chalk.green`
🔃 Installing dependencies...
`);
await $`npm install --save-dev @babel/cli @babel/preset-typescript --ignore-scripts`;

// Convert TS code to JS
await $`babel --no-babelrc --presets @babel/preset-typescript ./srcTS -d ./src --extensions \".js,.jsx,.ts,.tsx\" --ignore "./srcTS/typings.d.ts"`;

// Format the newly created .js files
console.log(chalk.green`
💅 Format the newly created .js files...
`);
await $`prettier --write ./src`;

// Add in minimal files required for the TS build setup
console.log(chalk.green`
➕ Add minimal files required for the TS build setup
`);
await $`prettier --write ./src`;
await $`touch ./src/dummy.ts`;
await $`printf "export {};" >> ./src/dummy.ts`;

Expand All @@ -20,11 +39,17 @@ await $`printf 'declare module "global";' >> ./src/typings.d.ts`;

// Clean up
await $`rm -rf ./srcTS`;
console.log(chalk.green`
🧹 Clean up...
`);
await $`npm uninstall @babel/cli @babel/preset-typescript --ignore-scripts`;

console.log(
chalk.green.bold`
chalk.green.bold`
TypeScript Ejection complete!`,
chalk.green`
chalk.green`
Addon code converted with JS. The TypeScript build setup is still available in case you want to adopt TypeScript in the future.
`
);
);
68 changes: 49 additions & 19 deletions scripts/prepublish-checks.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/usr/bin/env zx

const packageJson = require("../package.json");
const boxen = require("boxen");
const dedent = require("dedent");
import boxen from "boxen";
import dedent from "dedent";
import { readFile } from 'fs/promises';
import { globalPackages as globalManagerPackages } from "@storybook/manager/globals";
import { globalPackages as globalPreviewPackages } from "@storybook/preview/globals";

const packageJson = await readFile('./package.json', 'utf8').then(JSON.parse);

const name = packageJson.name;
const displayName = packageJson.storybook.displayName;
Expand All @@ -14,43 +18,69 @@ $.verbose = false;
* Check that meta data has been updated
*/
if (name.includes("addon-kit") || displayName.includes("Addon Kit")) {
console.error(
boxen(
dedent`
console.error(
boxen(
dedent`
${chalk.red.bold("Missing metadata")}
${chalk.red(dedent`Your package name and/or displayName includes default values from the Addon Kit.
The addon gallery filters out all such addons.
Please configure appropriate metadata before publishing your addon. For more info, see:
https://storybook.js.org/docs/react/addons/addon-catalog#addon-metadata`)}`,
{ padding: 1, borderColor: "red" }
)
);
{ padding: 1, borderColor: "red" }
)
);

exitCode = 1;
exitCode = 1;
}

/**
* Check that README has been updated
*/
const readmeTestStrings =
"# Storybook Addon Kit|Click the \\*\\*Use this template\\*\\* button to get started.|https://user-images.githubusercontent.com/42671/106809879-35b32000-663a-11eb-9cdc-89f178b5273f.gif";
"# Storybook Addon Kit|Click the \\*\\*Use this template\\*\\* button to get started.|https://user-images.githubusercontent.com/42671/106809879-35b32000-663a-11eb-9cdc-89f178b5273f.gif";

if ((await $`cat README.md | grep -E ${readmeTestStrings}`.exitCode) == 0) {
console.error(
boxen(
dedent`
console.error(
boxen(
dedent`
${chalk.red.bold("README not updated")}
${chalk.red(dedent`You are using the default README.md file that comes with the addon kit.
Please update it to provide info on what your addon does and how to use it.`)}
`,
{ padding: 1, borderColor: "red" }
)
);
{ padding: 1, borderColor: "red" }
)
);

exitCode = 1;
exitCode = 1;
}

process.exit(exitCode);
/**
* Check that globalized packages are not incorrectly listed as peer dependencies
*/
const peerDependencies = Object.keys(packageJson.peerDependencies || {});
const globalPackages = [...globalManagerPackages, ...globalPreviewPackages];
peerDependencies.forEach((dependency) => {
if(globalPackages.includes(dependency)) {
console.error(
boxen(
dedent`
${chalk.red.bold("Unnecessary peer dependency")}
${chalk.red(dedent`You have a peer dependency on ${chalk.bold(dependency)} which is most likely unnecessary
as that is provided by Storybook directly.
Check the "bundling" section in README.md for more information.
If you are absolutely sure you are doing it correct, you should remove this check from scripts/prepublish-checks.mjs.`)}
`,
{ padding: 1, borderColor: "red" }
)
);

exitCode = 1;

}
})

process.exit(exitCode);

0 comments on commit 3692f76

Please sign in to comment.