Skip to content

Commit

Permalink
refactor(publish): update release and build scripts to make them work…
Browse files Browse the repository at this point in the history
…space-friendly (#251)
  • Loading branch information
mimshins authored Nov 10, 2024
1 parent 8762341 commit b56baab
Show file tree
Hide file tree
Showing 17 changed files with 2,864 additions and 5,629 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dev:transpile": "tsc --project tsconfig.dev.json --watch --preserveWatchOutput",
"dev": "pnpm clear:dist && pnpm dev:transpile & wds",
"build:packages": "pnpm run -r --parallel build",
"release:packages": "pnpm run -r release",
"test": "pnpm run -r --parallel test",
"lint:ts": "tsc --project tsconfig.json",
"lint:ecma": "eslint packages/*/src/**/* --fix",
Expand Down
2 changes: 1 addition & 1 deletion packages/icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
},
"scripts": {
"build": "tsx ./scripts/build.ts",
"release": "pnpm publish ./dist --tag latest --access public"
"release": "pnpm publish . --tag latest --access public"
}
}
62 changes: 9 additions & 53 deletions packages/icons/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import Mustache from "mustache";
import { exec } from "node:child_process";
import * as fs from "node:fs/promises";
import * as path from "node:path";
import { fileURLToPath } from "node:url";
import { promisify } from "node:util";
import { ensureDirExists } from "../../../scripts/utils";
import {
createModulePackages,
ensureDirExists,
getFileMeta,
toPascalCase,
} from "../../../scripts/utils";

const execCmd = promisify(exec);

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const { dirname } = getFileMeta(import.meta.url);

const packageDir = path.resolve(__dirname, "..");
const packageDir = path.resolve(dirname, "..");
const iconsDir = path.join(packageDir, "src");
const distDir = path.join(packageDir, "dist");
const templatesDir = path.join(packageDir, "templates");
Expand All @@ -36,24 +39,6 @@ type SVGIconInfo = {
paths: SVGPathInfo[];
};

const toPascalCase = (str: string, splitRegex: RegExp | string) => {
const baseCase = str.split(splitRegex);

return baseCase
.map(part => part.charAt(0).toUpperCase() + part.substring(1))
.join("");
};

const doesFileExist = async (filePath: string) => {
try {
await fs.stat(filePath);

return true;
} catch {
return false;
}
};

const extractPathsInfo = (svgData: string) => {
const paths = svgData
// Remove the opening <svg> tag
Expand Down Expand Up @@ -145,40 +130,11 @@ const generatePaths = async () => {
await execCmd(["shx", "rm", entryFile].join(" "));
};

const createModulePackages = async () => {
console.log("> creating module packages...");

const moduleDirectories = globAsync
.sync(path.join(distDir, "**/index.js"))
.map(p => path.dirname(p));

for (const moduleDirectory of moduleDirectories) {
const typesPath = path.join(moduleDirectory, "index.d.ts");
const typesExist = await doesFileExist(typesPath);

const packageJsonPath = path.join(moduleDirectory, "package.json");

await fs.writeFile(
packageJsonPath,
JSON.stringify(
{
sideEffects: false,
types: typesExist ? "./index.d.ts" : undefined,
main: "./index.js",
type: "module",
},
null,
2,
),
);
}
};

void (async () => {
console.time("build");
await execCmd(["shx", "rm", "-rf", distDir].join(" "));
await generatePaths();
await createModulePackages();
await createModulePackages(distDir);
console.timeEnd("build");
})();
/* eslint-enable no-console */
2 changes: 1 addition & 1 deletion packages/react-icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"scripts": {
"build": "tsx ./scripts/build.ts",
"release": "pnpm publish ./dist --tag latest --access public"
"release": "pnpm publish . --tag latest --access public"
},
"dependencies": {
"@tapsioss/rasti-icons": "workspace:*"
Expand Down
54 changes: 8 additions & 46 deletions packages/react-icons/scripts/build.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,28 @@
/* eslint-disable no-console */
import icons from "@tapsioss/rasti-icons";
import globAsync from "fast-glob";
import Mustache from "mustache";
import { exec } from "node:child_process";
import * as fs from "node:fs/promises";
import * as path from "node:path";
import { fileURLToPath } from "node:url";
import { promisify } from "node:util";
import { ensureDirExists } from "../../../scripts/utils";
import {
createModulePackages,
ensureDirExists,
getFileMeta,
} from "../../../scripts/utils";

const execCmd = promisify(exec);

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const { dirname } = getFileMeta(import.meta.url);

const packageDir = path.resolve(__dirname, "..");
const packageDir = path.resolve(dirname, "..");
const distDir = path.join(packageDir, "dist");
const templatesDir = path.join(packageDir, "templates");

const iconTemplate = path.join(templatesDir, "react-icon.txt");
const tsconfigFile = path.join(packageDir, "tsconfig.build.json");
const baseIconFile = path.join(packageDir, "src/base-icon.tsx");

const doesFileExist = async (filePath: string) => {
try {
await fs.stat(filePath);

return true;
} catch {
return false;
}
};

const generateComponents = async () => {
console.log("> generating web components...");

Expand Down Expand Up @@ -94,40 +85,11 @@ const generateComponents = async () => {
await execCmd(`shx ls ${distDir}/*.tsx | xargs rm`);
};

const createModulePackages = async () => {
console.log("> creating module packages...");

const moduleDirectories = globAsync
.sync(path.join(distDir, "**/index.js"))
.map(p => path.dirname(p));

for (const moduleDirectory of moduleDirectories) {
const typesPath = path.join(moduleDirectory, "index.d.ts");
const typesExist = await doesFileExist(typesPath);

const packageJsonPath = path.join(moduleDirectory, "package.json");

await fs.writeFile(
packageJsonPath,
JSON.stringify(
{
sideEffects: false,
types: typesExist ? "./index.d.ts" : undefined,
main: "./index.js",
type: "module",
},
null,
2,
),
);
}
};

void (async () => {
console.time("build");
await execCmd(["shx", "rm", "-rf", distDir].join(" "));
await generateComponents();
await createModulePackages();
await createModulePackages(distDir);
console.timeEnd("build");
})();
/* eslint-enable no-console */
9 changes: 9 additions & 0 deletions packages/theme/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
src
templates
scripts
node_modules

tsconfig.*

dist/*.ts
!dist/*.d.ts
11 changes: 10 additions & 1 deletion packages/theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@
"engines": {
"node": ">=20"
},
"files": [
"./dist/**/*.css"
],
"main": "./dist/index.css",
"exports": {
".": {
"default": "./dist/index.css"
}
},
"scripts": {
"build": "tsx ./scripts/build.ts",
"release": "pnpm publish ./dist --tag latest --access public"
"release": "pnpm publish . --tag latest --access public"
}
}
16 changes: 3 additions & 13 deletions packages/theme/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@
import { exec } from "node:child_process";
import * as path from "node:path";
import { promisify } from "node:util";
import { fileURLToPath } from "url";
import {
createMainPackage,
createNPMRC,
ensureDirExists,
} from "../../../scripts/utils";
import { ensureDirExists, getFileMeta } from "../../../scripts/utils";

const execCmd = promisify(exec);

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const { dirname } = getFileMeta(import.meta.url);

const packageDir = path.resolve(__dirname, "..");
const packageDir = path.resolve(dirname, "..");
const distPath = path.join(packageDir, "dist");
const entryPoint = path.join(packageDir, "src/index.css");
const outputPath = path.join(distPath, "index.css");
Expand Down Expand Up @@ -46,10 +40,6 @@ const compile = async () => {
void (async () => {
console.time("build");
await compile();
await createMainPackage(packageDir, distPath, {
main: "index.css",
});
await createNPMRC(distPath);
console.timeEnd("build");
})();
/* eslint-enable no-console */
9 changes: 9 additions & 0 deletions packages/web-components/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
src
templates
scripts
node_modules

tsconfig.*

dist/*.ts
!dist/*.d.ts
13 changes: 12 additions & 1 deletion packages/web-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@
"engines": {
"node": ">=20"
},
"files": [
"./dist/**/*.js",
"./dist/**/*.d.ts",
"./dist/**/package.json"
],
"exports": {
"./*": {
"types": "./dist/*/index.d.ts",
"default": "./dist/*/index.js"
}
},
"scripts": {
"build": "tsx ./scripts/build.ts",
"release": "pnpm publish ./dist --tag latest --access public"
"release": "pnpm publish . --tag latest --access public"
},
"dependencies": {
"@floating-ui/dom": "^1.6.11",
Expand Down
55 changes: 6 additions & 49 deletions packages/web-components/scripts/build.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,35 @@
/* eslint-disable no-console */
import glob from "fast-glob";
import { exec } from "node:child_process";
import * as fs from "node:fs/promises";
import * as path from "node:path";
import { fileURLToPath } from "node:url";
import { promisify } from "node:util";
import { createMainPackage, createNPMRC } from "../../../scripts/utils";
import { createModulePackages, getFileMeta } from "../../../scripts/utils";

const execCmd = promisify(exec);

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const { dirname } = getFileMeta(import.meta.url);

const packageDir = path.resolve(__dirname, "..");
const packageDir = path.resolve(dirname, "..");
const distPath = path.join(packageDir, "dist");

const moduleDirectories = glob
.sync(path.join(distPath, "**/index.js"))
.map(p => path.dirname(p));

const doesFileExist = async (filePath: string) => {
try {
await fs.stat(filePath);

return true;
} catch {
return false;
}
};

const transpile = async () => {
console.log("> transpiling...");

const configPath = path.resolve(packageDir, "tsconfig.build.json");
const tsconfigPath = path.resolve(packageDir, "tsconfig.build.json");

await execCmd(["shx", "rm", "-rf", distPath].join(" "));

const { stderr, stdout } = await execCmd(
["tsc", "--project", configPath].join(" "),
["tsc", "--project", tsconfigPath].join(" "),
);

if (stdout) console.log(stdout);
if (stderr) console.error(stderr);
};

const createModulePackages = async () => {
console.log("> creating module packages...");
for (const moduleDirectory of moduleDirectories) {
const typesPath = path.join(moduleDirectory, "index.d.ts");
const typesExist = await doesFileExist(typesPath);

const packageJsonPath = path.join(moduleDirectory, "package.json");

await fs.writeFile(
packageJsonPath,
JSON.stringify(
{
sideEffects: false,
types: typesExist ? "./index.d.ts" : undefined,
main: "./index.js",
},
null,
2,
),
);
}
};

void (async () => {
console.time("build");
await transpile();
await createModulePackages();
await createMainPackage(packageDir, distPath);
await createNPMRC(distPath);
await createModulePackages(distPath);
console.timeEnd("build");
})();
/* eslint-enable no-console */
2 changes: 1 addition & 1 deletion packages/web-components/src/badge-wrapper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export { Slots } from "./constants";
*
* @prop {"rectangle" | "circle" | "pill"} [anchor-shape="rectangle"] - The shape of the anchor.
* @prop {"left" | "right"} [badge-side="right"] - The horizontal placement of the badge.
* @prop {"top" | "middle"} [badge-alignment="alignment"] - The vertical alignment of the badge.
* @prop {"top" | "middle"} [badge-alignment="top"] - The vertical alignment of the badge.
*
* @slot - The default slot for the anchor element.
* @slot badge - The slot for the badge to be positioned.
Expand Down
Loading

0 comments on commit b56baab

Please sign in to comment.