@stackshift-ui/scripts 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/rebrander.js ADDED
@@ -0,0 +1,165 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const { packageName, owner, repo, title } = require("./rebrand.config.json");
4
+ const packageJSON = require("../lib/package.json");
5
+
6
+ const rootDir = process.cwd();
7
+ const oldPkgName = packageJSON.name;
8
+ const [oldOwner, oldRepo] = packageJSON.repository.split(":")[1].split("/");
9
+
10
+ // Rebrand lib packageJSON
11
+ packageJSON.name = packageName;
12
+ packageJSON.description = "";
13
+ packageJSON.version = "0.0.0";
14
+ packageJSON.repository = `github:${owner}/${repo}`;
15
+ packageJSON.funding.pop();
16
+ packageJSON.bugs = `https://github.com/${owner}/${repo}/issues`;
17
+ packageJSON.homepage = `https://github.com/${owner}/${repo}/#readme`;
18
+ packageJSON.funding.unshift({
19
+ type: "github",
20
+ url: `https://github.com/sponsors/${owner}`,
21
+ });
22
+ packageJSON.keywords = packageJSON.keywords.slice(2);
23
+
24
+ fs.writeFileSync(
25
+ path.resolve(rootDir, "lib", "package.json"),
26
+ JSON.stringify(packageJSON, null, 2),
27
+ );
28
+
29
+ const updatePkgAndRemoveChangelogs = dir => {
30
+ // update package.json for packages and examples
31
+ const pkgPath = path.resolve(dir, "package.json");
32
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
33
+ pkg.version = "0.0.0";
34
+ if (pkg.dependencies?.[oldPkgName]) {
35
+ pkg.dependencies[oldPkgName] = "latest";
36
+ pkg.dependencies[packageJSON.name] = "workspace:*";
37
+ } else if (pkg.devDependencies?.[oldPkgName]) {
38
+ pkg.devDependencies[oldPkgName] = "latest";
39
+ pkg.dependencies[packageJSON.name] = "workspace:*";
40
+ }
41
+
42
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
43
+
44
+ // Delete old changelogs
45
+ try {
46
+ fs.unlinkSync(path.resolve(dir, "CHANGELOG.md"));
47
+ } catch {
48
+ /* empty */
49
+ }
50
+ };
51
+
52
+ ["examples", "packages"].forEach(dir => {
53
+ fs.readdirSync(path.resolve(rootDir, dir)).forEach(f =>
54
+ updatePkgAndRemoveChangelogs(path.resolve(rootDir, dir, f)),
55
+ );
56
+ });
57
+
58
+ try {
59
+ fs.unlinkSync(path.resolve(rootDir, "lib", "CHANGELOG.md"));
60
+ } catch {
61
+ /* empty */
62
+ }
63
+
64
+ // Update README
65
+ const readme = fs
66
+ .readFileSync(path.resolve(rootDir, "lib", "README.md"), "utf-8")
67
+ .replace(new RegExp(oldPkgName, "g"), packageName)
68
+ .replace(new RegExp(oldOwner, "g"), owner)
69
+ .replace(new RegExp(oldRepo, "g"), repo)
70
+ .replace(new RegExp(oldPkgName.replace("-", " "), "ig"), title)
71
+ .replace(/> This package also.*[^\n]/, "");
72
+ fs.writeFileSync(path.resolve(rootDir, "README.md"), readme);
73
+ fs.writeFileSync(path.resolve(rootDir, "lib", "README.md"), readme);
74
+
75
+ // Update page title
76
+ const pageFilePath = path.resolve(rootDir, "examples", "nextjs", "src", "app", "page.tsx");
77
+ const pageCode = fs.readFileSync(pageFilePath, "utf-8").replace("React 18 Loaders", title);
78
+ fs.writeFileSync(pageFilePath, pageCode);
79
+
80
+ // Update TODO.md
81
+ const touchupTodo = content =>
82
+ content
83
+ .replace(
84
+ "[repo settings]",
85
+ `[repo settings](https://github.com/${owner}/${repo}/settings/pages)`,
86
+ )
87
+ .replace(
88
+ "[repository secret]",
89
+ `[repository secret]((https://github.com/${owner}/${repo}/settings/secrets/actions))`,
90
+ )
91
+ .replace(
92
+ "[private vulnerability reporting]",
93
+ `[private vulnerability reporting](https://github.com/${owner}/${repo}/security)`,
94
+ )
95
+ .replace("- [ ] Create a new GitHub repository", "- [x] Create a new GitHub repository");
96
+
97
+ const todoPath = path.resolve(rootDir, "TODO.md");
98
+ fs.writeFileSync(todoPath, touchupTodo(fs.readFileSync(todoPath, "utf-8")));
99
+
100
+ const tkbPath = path.resolve(rootDir, ".tkb");
101
+ fs.writeFileSync(tkbPath, touchupTodo(fs.readFileSync(tkbPath, "utf-8")));
102
+ fs.renameSync(tkbPath, tkbPath);
103
+
104
+ // Update Funding
105
+ const fundingPath = path.resolve(rootDir, ".github", "FUNDING.yml");
106
+ fs.writeFileSync(
107
+ fundingPath,
108
+ fs
109
+ .readFileSync(fundingPath, "utf-8")
110
+ .replace("github: [mayank1513]", `github: [${owner}, mayank1513]`),
111
+ );
112
+
113
+ // Update workflows
114
+ const workflowsPath = path.resolve(rootDir, ".github", "workflows");
115
+ /** Update publish and manual-publish workflows */
116
+ const updatePublishFlow = name => {
117
+ const publishWorkflowPath = path.resolve(workflowsPath, name);
118
+ const publishWorkflow = fs
119
+ .readFileSync(publishWorkflowPath, "utf-8")
120
+ .replace("# - name", "- name")
121
+ .replace("# run", " run")
122
+ .replace(oldOwner, owner);
123
+ fs.writeFileSync(publishWorkflowPath, publishWorkflow);
124
+ };
125
+
126
+ updatePublishFlow("publish.yml");
127
+ updatePublishFlow("manual-publish.yml");
128
+
129
+ try {
130
+ fs.unlinkSync(path.resolve(workflowsPath, "setup.yml"));
131
+ } catch {
132
+ // empty
133
+ }
134
+ const docsWorkflowPath = path.resolve(workflowsPath, "docs.yml");
135
+ fs.writeFileSync(
136
+ docsWorkflowPath,
137
+ fs.readFileSync(docsWorkflowPath, "utf-8").replace(oldOwner, owner),
138
+ );
139
+
140
+ // Update SECURITY.md
141
+ const secFile = path.resolve(rootDir, "SECURITY.md");
142
+ fs.writeFileSync(
143
+ secFile,
144
+ fs.readFileSync(secFile, "utf-8").replace(`${oldOwner}/${oldRepo}`, `${owner}/${repo}`),
145
+ );
146
+ // clean up
147
+ const rootPackageJSON = require("../package.json");
148
+ const { execSync } = require("child_process");
149
+ delete rootPackageJSON.scripts.postinstall;
150
+ try {
151
+ fs.writeFileSync(path.resolve(rootDir, "package.json"), JSON.stringify(rootPackageJSON, null, 2));
152
+ } catch (e) {
153
+ console.error(e);
154
+ }
155
+
156
+ // update typedoc config
157
+ execSync(`sed -i -e 's/name:.*/name: "${title.replace(/\//g, "\\/")}",/' typedoc.config.js`);
158
+
159
+ // reinstall dependencies --> this will update the pnpm-lock file as well which we need to add to commit
160
+ execSync("pnpm i");
161
+
162
+ // clean lib/src and craete commit
163
+ execSync(
164
+ 'rm -rf ./lib/src/ && git add . && git commit -m "Rebrand 💖 <a href="https://stackshift-ui.webriq.com" target="_blank">WebriQ</a> [skip ci]" && turbo telemetry disable',
165
+ );
@@ -0,0 +1,8 @@
1
+ /** @type {import("eslint").Linter.Config} */
2
+ module.exports = {
3
+ extends: ["@stackshift-ui/eslint-config/react.js"],
4
+ parser: "@typescript-eslint/parser",
5
+ parserOptions: {
6
+ project: true,
7
+ },
8
+ };
@@ -0,0 +1,24 @@
1
+ # @stackshift-ui/{{kebabCase componentName}}
2
+
3
+ {{description}}
4
+
5
+ Please refer to the [documentation](https://stackshift-ui.webriq.com/docs/components/{{kebabCase componentName}}) for more information.
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ yarn add @stackshift-ui/{{kebabCase componentName}}
11
+ # or
12
+ npm i @stackshift-ui/{{kebabCase componentName}}
13
+ ```
14
+
15
+ ## Contribution
16
+
17
+ Yes please! See the
18
+ [contributing guidelines](https://github.com/stackshift-ui/components/master/CONTRIBUTING.md)
19
+ for details.
20
+
21
+ ## License
22
+
23
+ This project is licensed under the terms of the
24
+ [MIT license](https://github.com/stackshift-ui/components/master/LICENSE).
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@stackshift-ui/{{kebabCase componentName}}",
3
+ "description": "{{ description }}",
4
+ "version": "0.0.0",
5
+ "private": false,
6
+ "sideEffects": false,
7
+ "main": "./dist/index.js",
8
+ "module": "./dist/index.mjs",
9
+ "types": "./dist/index.d.ts",
10
+ "files": [
11
+ "dist/**"
12
+ ],
13
+ "author": "WebriQ <info@webriq.com>",
14
+ "scripts": {
15
+ "build": "tsup && tsc -p tsconfig-build.json",
16
+ "clean": "rm -rf dist",
17
+ "dev": "tsup --watch && tsc -p tsconfig-build.json -w",
18
+ "typecheck": "tsc --noEmit",
19
+ "lint": "eslint src/",
20
+ "test": "vitest run --coverage"
21
+ },
22
+ "devDependencies": {
23
+ "@stackshift-ui/eslint-config": "workspace:*",
24
+ "@stackshift-ui/typescript-config": "workspace:*",
25
+ "@testing-library/react": "^16.0.1",
26
+ "@types/node": "^22.7.0",
27
+ "@types/react": "^18.3.9",
28
+ "@types/react-dom": "^18.3.0",
29
+ "@vitejs/plugin-react": "^4.3.1",
30
+ "@vitest/coverage-v8": "^2.1.1",
31
+ "esbuild-plugin-rdi": "^0.0.0",
32
+ "esbuild-plugin-react18": "^0.2.5",
33
+ "esbuild-plugin-react18-css": "^0.0.4",
34
+ "jsdom": "^25.0.1",
35
+ "react": "^18.3.1",
36
+ "react-dom": "^18.3.1",
37
+ "tsup": "^8.3.0",
38
+ "typescript": "^5.6.2",
39
+ "vite-tsconfig-paths": "^5.0.1",
40
+ "vitest": "^2.1.1"
41
+ },
42
+ "dependencies": {
43
+ "@stackshift-ui/scripts": "workspace:*",
44
+ "@stackshift-ui/system": "workspace:*",
45
+ "classnames": "^2.5.1"
46
+ },
47
+ "peerDependencies": {
48
+ "@types/react": "16.8 - 19",
49
+ "next": "10 - 14",
50
+ "react": "16.8 - 19",
51
+ "react-dom": "16.8 - 19",
52
+ "@stackshift-ui/system": ">=0.0.0"
53
+ },
54
+ "peerDependenciesMeta": {
55
+ "next": {
56
+ "optional": true
57
+ }
58
+ }
59
+ }
@@ -0,0 +1,4 @@
1
+ "use client";
2
+
3
+ // component exports
4
+ export * from "./{{kebabCase componentName}}";
@@ -0,0 +1,13 @@
1
+ import { cleanup, render, screen } from "@testing-library/react";
2
+ import { afterEach, describe, test } from "vitest";
3
+ import { {{capitalize componentName}} } from "./{{kebabCase componentName}}";
4
+
5
+ describe.concurrent("{{kebabCase componentName}}", () => {
6
+ afterEach(cleanup);
7
+
8
+ test("Dummy test - test if renders without errors", ({ expect }) => {
9
+ const clx = "my-class";
10
+ render(<{{capitalize componentName}} className={clx} />);
11
+ expect(screen.getByTestId("{ kebabCase name }}").classList).toContain(clx);
12
+ });
13
+ });
@@ -0,0 +1,27 @@
1
+ import { DefaultComponent, useStackShiftUIComponents } from "@stackshift-ui/system";
2
+ import type { ElementType, HTMLProps, ReactNode } from "react";
3
+
4
+ export interface {{capitalize componentName}}Props extends Omit<HTMLProps<HTMLElement>, "as"> {
5
+ children?: ReactNode;
6
+ className?: string;
7
+ as?: ElementType;
8
+ }
9
+
10
+ const displayName = "{{capitalize componentName}}";
11
+
12
+ export const {{capitalize componentName}}: React.FC<{{capitalize componentName}}Props> = ({
13
+ children,
14
+ className,
15
+ as,
16
+ ...props
17
+ }) => {
18
+ const { [displayName]: Component = DefaultComponent } = useStackShiftUIComponents();
19
+
20
+ return (
21
+ <Component as={as} className={className} {...props} data-testid={displayName}>
22
+ {children}
23
+ </Component>
24
+ );
25
+ };
26
+
27
+ {{capitalize componentName}}.displayName = displayName;
@@ -0,0 +1,12 @@
1
+ {
2
+ // using tsc for type declarations as "Note that declaration files generated by any tool other than tsc are not guaranteed to be error-free, so it's a good idea to test the output with tsc" - https://tsup.egoist.dev/#generate-declaration-file
3
+ "extends": "@stackshift-ui/typescript-config/react-library.json",
4
+ "compilerOptions": {
5
+ "outDir": "dist",
6
+ "noEmit": false,
7
+ "emitDeclarationOnly": true,
8
+ "declarationMap": false
9
+ },
10
+ "include": ["src"],
11
+ "exclude": ["dist", "node_modules", "**/*.test.*", "**/*.spec.*"]
12
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@stackshift-ui/typescript-config/react-library.json",
3
+ "compilerOptions": {
4
+ "lib": ["dom", "ES2015"],
5
+ "types": ["vitest", "node"]
6
+ },
7
+ "include": ["."],
8
+ "exclude": ["dist", "build", "node_modules"]
9
+ }
@@ -0,0 +1,24 @@
1
+ import { defineConfig, type Options } from "tsup";
2
+ import react18Plugin from "esbuild-plugin-react18";
3
+ import cssPlugin from "esbuild-plugin-react18-css";
4
+ import { rdiPlugin } from "esbuild-plugin-rdi";
5
+
6
+ export default defineConfig(
7
+ (options: Options) =>
8
+ ({
9
+ format: ["cjs", "esm"],
10
+ target: "es2019",
11
+ entry: ["./src/**"],
12
+ sourcemap: false,
13
+ clean: !options.watch,
14
+ bundle: true,
15
+ minify: !options.watch,
16
+ esbuildPlugins: [
17
+ react18Plugin(),
18
+ cssPlugin({ generateScopedName: "[folder]__[local]" }),
19
+ rdiPlugin(),
20
+ ],
21
+ external: ["react"],
22
+ ...options,
23
+ }) as Options,
24
+ );
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": ["//"],
3
+ "tasks": {
4
+ "build": {
5
+ "outputs": ["dist/**"],
6
+ "dependsOn": ["^build"]
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,18 @@
1
+ import { defineConfig } from "vitest/config";
2
+ import react from "@vitejs/plugin-react";
3
+ import tsconfigPaths from "vite-tsconfig-paths";
4
+
5
+ // https://vitejs.dev/config/
6
+ export default defineConfig({
7
+ plugins: [react(), tsconfigPaths()],
8
+ test: {
9
+ environment: "jsdom",
10
+ globals: true,
11
+ setupFiles: [],
12
+ coverage: {
13
+ include: ["src/**"],
14
+ exclude: ["src/**/index.ts", "src/**/declaration.d.ts"],
15
+ reporter: ["text", "json", "clover", "html"],
16
+ },
17
+ },
18
+ });
@@ -0,0 +1,25 @@
1
+ import { HTMLProps, ReactNode } from "react";
2
+ import styles from "./{{kebabCase componentName}}.module.scss";
3
+
4
+ export interface {{capitalize componentName}}Props extends HTMLProps<HTMLDivElement> {
5
+ children?: ReactNode;
6
+ }
7
+
8
+ /**
9
+ * {{ description }}
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * <{{capitalize componentName}} />
14
+ * ```
15
+ *
16
+ * @source - Source code
17
+ */
18
+ export const {{capitalize componentName}} = ({ children, ...props }: {{capitalize componentName}}Props) => {
19
+ const className = [props.className, styles["{{kebabCase componentName}}"]].filter(Boolean).join(" ");
20
+ return (
21
+ <div {...props} className={className} data-testid="{{kebabCase componentName}}">
22
+ {children}
23
+ </div>
24
+ );
25
+ }
@@ -0,0 +1,3 @@
1
+ .{{kebabCase componentName}} {
2
+ /* create your container styles here */
3
+ }
@@ -0,0 +1,13 @@
1
+ import { cleanup, render, screen } from "@testing-library/react";
2
+ import { afterEach, describe, test } from "vitest";
3
+ import { {{capitalize componentName}} } from "./{{kebabCase componentName}}";
4
+
5
+ describe.concurrent("{{kebabCase componentName}}", () => {
6
+ afterEach(cleanup);
7
+
8
+ test("Dummy test - test if renders without errors", ({ expect }) => {
9
+ const clx = "my-class";
10
+ render(<{{capitalize componentName}} className={clx} />);
11
+ expect(screen.getByTestId("{{kebabCase componentName}}").classList).toContain(clx);
12
+ });
13
+ });
@@ -0,0 +1,24 @@
1
+ import { useState } from "react";
2
+
3
+ export interface {{capitalize componentName}}Options {
4
+ /** this is a dummy option */
5
+ dummy?: string;
6
+ }
7
+
8
+ /**
9
+ * {{ description }}
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * const [] = {{ camelCase name }}(options);
14
+ * ```
15
+ *
16
+ * @source - Source code
17
+ */
18
+
19
+ export const {{ camelCase name }} = (options?: {{capitalize componentName}}Options) => {
20
+ const [value, setValue] = useState(0);
21
+ return {
22
+ value, setValue
23
+ }
24
+ }
@@ -0,0 +1,14 @@
1
+ import { cleanup, renderHook, act } from "@testing-library/react";
2
+ import { afterEach, describe, test } from "vitest";
3
+ import { {{ camelCase name }} } from "./{{kebabCase componentName}}";
4
+
5
+ describe.concurrent("{{ camelCase name }}", () => {
6
+ afterEach(cleanup);
7
+
8
+ test("Dummy test - test if renders without errors", ({ expect }) => {
9
+ const { result } = renderHook(() => {{ camelCase name }}());
10
+ act(() => result.current.setValue(10));
11
+ expect(result.current.value).toBe(10);
12
+ });
13
+ });
14
+
package/update-pm.js ADDED
@@ -0,0 +1,18 @@
1
+ const { execSync } = require("child_process");
2
+ const fs = require("fs");
3
+ const path = require("path");
4
+ const packageJSON = require("../package.json");
5
+
6
+ const PNPM_VERSION = execSync("pnpm -v").toString().trim();
7
+ packageJSON.packageManager = `pnpm@${PNPM_VERSION}`;
8
+
9
+ fs.writeFileSync(path.resolve(__dirname, "../package.json"), JSON.stringify(packageJSON, null, 2));
10
+
11
+ // commit to repo
12
+ try {
13
+ execSync(
14
+ "git add ./package.json && git commit -m 'chore: automated update of package.json with pnpm version'",
15
+ );
16
+ } catch {
17
+ // no changesets to be applied
18
+ }
@@ -0,0 +1,15 @@
1
+ const { execSync } = require("child_process");
2
+
3
+ module.exports = (newMajor_minor, oldMajor_minor) => {
4
+ /** Update SECURITY.md */
5
+ execSync(
6
+ `sed -i -e "s/.*| :white_check_mark:.*/| ${newMajor_minor}.x | :white_check_mark: |/" SECURITY.md`,
7
+ );
8
+ execSync(
9
+ `sed -i -e "s/.*| :warning:.*/| ${oldMajor_minor}.x | :warning: |/" SECURITY.md`,
10
+ );
11
+ execSync(`sed -i -e "s/.*| :x:.*/| < ${oldMajor_minor} | :x: |/" SECURITY.md`);
12
+ execSync(
13
+ `git add SECURITY.md && git commit -m 'Update SECURITY.md [skip ci]' && git push origin ${process.env.BRANCH}`,
14
+ );
15
+ };