Skip to content

Commit 465f55c

Browse files
⚙️ Chore(commitsmile2): implement basic command version and setup tsup + format package.json
1 parent 3c7fb51 commit 465f55c

9 files changed

Lines changed: 175 additions & 125 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { defineConfig } from "tsup";
2+
3+
//----------------------
4+
// Internals
5+
//----------------------
6+
7+
/**
8+
* Basic optimization/minification settings for the bundler
9+
* @internal
10+
*/
11+
export const PROD_OPTIMIZE = {
12+
splitting: false,
13+
minify: true,
14+
shims: true,
15+
16+
bundle: true,
17+
18+
minifyIdentifiers: true,
19+
minifySyntax: true,
20+
minifyWhitespace: true,
21+
22+
metafile: false,
23+
treeshake: true
24+
} as const satisfies Parameters<typeof defineConfig>[number];
25+
26+
//TODO: FIX TYPE
27+
/**
28+
* Adds a Node.js require shim for ESM modules
29+
* This fixes dynamic imports by creating a require function
30+
* using Node's module.createRequire() for ESM compatibility
31+
* @internal
32+
*/
33+
export const addNodeRequireShim = ({ format }: Parameters<typeof defineConfig>[number]["banner"]) => {
34+
if (format === "esm") {
35+
const banner = `
36+
import { createRequire } from "node:module";
37+
const require = createRequire(import.meta.url);
38+
`;
39+
40+
return { js: banner };
41+
}
42+
};
Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,50 @@
1-
// import { copy } from "esbuild-plugin-copy";
21
import { defineConfig } from "tsup";
3-
// import typiaPlug from "@ryoppippi/unplugin-typia/esbuild";
2+
import copy from "esbuild-plugin-copy";
3+
import { addNodeRequireShim } from "./internals";
44

5-
export default defineConfig({
6-
// entry: ["src/index.ts", "src/bin/app.ts"],
7-
entry: ["src/index.ts"],
8-
target: "es2020",
9-
clean: true,
10-
format: ["esm"],
11-
// noExternal: ["typia"],
5+
//----------------------
6+
// Functions
7+
//----------------------
128

13-
// esbuildPlugins: [
14-
// typiaPlug({ tsconfig: "./tsconfig.json", cache: false }),
15-
// copy({
16-
// assets: [
17-
// { from: "./package.json", to: "./package.json" },
18-
// { from: "./.npmrc", to: "./.npmrc" },
19-
// { from: "./.npmignore", to: "./.npmignore" },
20-
// { from: "./README.md", to: "./README.md" },
21-
// { from: "./src/templates/configs/*", to: "./templates/configs" }
22-
// ]
23-
// })
24-
// ],
25-
banner: ({ format }) => {
26-
if (format === "esm") {
27-
const banner = `
28-
import { createRequire } from "node:module";
29-
const require = createRequire(import.meta.url);
30-
`;
31-
32-
return { js: banner };
9+
/** @internal */
10+
export const BasicConfig = (isDev: boolean) =>
11+
({
12+
METAFILES_TO_COPY: isDev
13+
? {}
14+
: {
15+
entry: ["src/index.ts"],
16+
plugins: [
17+
copy({
18+
assets: [
19+
{ from: "./package.json", to: "./package.json" },
20+
{ from: "./.npmrc", to: "./.npmrc" },
21+
{ from: "./.npmignore", to: "./.npmignore" },
22+
{ from: "./README.md", to: "./README.md" }
23+
// { from: "./src/templates/configs/*", to: "./templates/configs" }
24+
]
25+
})
26+
]
27+
},
28+
CLI_APP: {
29+
entry: ["src/bin/app.ts"],
30+
outDir: `${isDev ? "lib" : "dist"}/bin`,
31+
target: "esnext",
32+
banner: addNodeRequireShim,
33+
watch: isDev ? ["src"] : false
34+
},
35+
PACKAGE: {
36+
entry: ["src/index.ts"],
37+
outDir: isDev ? "lib" : "dist",
38+
target: "es2020",
39+
banner: addNodeRequireShim,
40+
watch: isDev ? ["src"] : false
3341
}
34-
}
35-
});
42+
}) as const satisfies Record<string, Parameters<typeof defineConfig>[number]>;
43+
44+
/** @internal */
45+
export const devConfigs = BasicConfig(true);
46+
47+
/** @internal */
48+
export const prodConfigs = BasicConfig(false);
49+
50+
export default BasicConfig;
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import config from "./tsup.base";
21
import { defineConfig } from "tsup";
2+
import { devConfigs } from "./tsup.base";
33

4-
export default defineConfig({
5-
...config,
6-
outDir: "lib",
7-
watch: ["src"]
8-
});
4+
//----------------------
5+
// Functions
6+
//----------------------
7+
8+
export default defineConfig(Object.values(devConfigs));
Lines changed: 18 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,24 @@
1-
import config from "./tsup.base";
2-
// import typiaPlug from "@ryoppippi/unplugin-typia/esbuild";
3-
// import { copy } from "esbuild-plugin-copy";
41
import { defineConfig } from "tsup";
2+
import { prodConfigs } from "./tsup.base";
3+
import { PROD_OPTIMIZE } from "./internals";
4+
5+
//----------------------
6+
// Functions
7+
//----------------------
58

69
export default defineConfig([
710
{
8-
...config,
9-
entry: ["src/index.ts"],
10-
11-
splitting: false,
12-
minify: true,
13-
shims: true,
14-
15-
bundle: true,
16-
17-
minifyIdentifiers: true,
18-
minifySyntax: true,
19-
minifyWhitespace: true,
20-
21-
metafile: false,
22-
treeshake: true,
23-
24-
outDir: "dist",
25-
// external: ["node:stream", "@types/node"],
26-
// noExternal: ["@clack/prompts", "c12", "commander", "oh-my-error", "typia", "yaml"],
27-
28-
format: ["cjs", "esm"]
29-
30-
// esbuildPlugins: [
31-
// copy({
32-
// assets: [
33-
// { from: "./package.json", to: "./package.json" },
34-
// { from: "./.npmrc", to: "./.npmrc" },
35-
// { from: "./.npmignore", to: "./.npmignore" },
36-
// { from: "./README.md", to: "./README.md" },
37-
// { from: "./src/templates/configs/*", to: "./templates/configs" }
38-
// ]
39-
// }),
40-
// typiaPlug({ tsconfig: "./tsconfig.json", cache: false })
41-
// ]
11+
...prodConfigs.METAFILES_TO_COPY,
12+
clean: true
13+
},
14+
{
15+
...prodConfigs.CLI_APP,
16+
...PROD_OPTIMIZE
17+
},
18+
{
19+
...prodConfigs.PACKAGE,
20+
...PROD_OPTIMIZE,
21+
format: ["esm", "cjs"],
22+
dts: true
4223
}
43-
// {
44-
// entry: ["src/index.ts"],
45-
// dts: {
46-
// entry: "./src/index.ts",
47-
// resolve: true,
48-
// only: true
49-
// },
50-
// format: ["esm", "cjs"],
51-
// external: ["node:stream"]
52-
// },
53-
// {
54-
// ...config,
55-
// entry: ["src/bin/app.ts"],
56-
// splitting: true,
57-
// minify: true,
58-
// shims: true,
59-
60-
// bundle: true,
61-
62-
// minifyIdentifiers: true,
63-
// minifySyntax: true,
64-
// minifyWhitespace: true,
65-
66-
// metafile: false,
67-
// treeshake: true,
68-
69-
// outDir: "dist/bin",
70-
71-
// noExternal: ["@clack/prompts", "c12", "commander", "oh-my-error", "typia", "yaml"],
72-
// // noExternal: ["@clack/prompts", "commander", "oh-my-error", "typia", "jiti"],
73-
// format: ["esm"],
74-
// esbuildPlugins: [typiaPlug({ tsconfig: "./tsconfig.json", cache: false })]
75-
// }
7624
]);

packages/commitsmile2/package.json

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,35 @@
44
"private": true,
55
"type": "module",
66
"scripts": {
7-
"------------------------BUILDS-------------------------": "",
8-
"------------------------DEPLOYS------------------------": "",
97
"------------------------INSTALLATION-------------------": "",
10-
"------------------------NPM--------------------------": "",
11-
"------------------------TESTS--------------------------": "",
8+
"prepare": "",
9+
"pre": "git add . && npx lint-staged",
1210
"------------------------UTILS--------------------------": "",
13-
"build:dev": "pnpm tsup --config ./config/tsuprc/tsup.dev.ts",
14-
"build:npm": "pnpm npm:prepack && pnpm tsup --config ./config/tsuprc/tsup.prod.ts && pnpm npm:postpack",
15-
"build:prod": "pnpm tsup --config ./config/tsuprc/tsup.prod.ts",
16-
"clean": "",
11+
"lint": "eslint .",
12+
"lint:fix": "eslint . --fix",
1713
"format": "pnpm prettier . --write && pnpm prettier . --check",
14+
"clean": "",
1815
"link-cli": "pnpm unlink --global && pnpm link --global",
1916
"link-cli:dev": "cd lib && pnpm unlink --global && pnpm link --global",
20-
"lint": "eslint .",
21-
"lint:fix": "eslint . --fix",
22-
"npm:postpack": "clean-package restore",
17+
"------------------------BUILDS-------------------------": "",
18+
"build:dev": "pnpm tsup --config ./config/tsuprc/tsup.dev.ts",
19+
"build:prod": "pnpm tsup --config ./config/tsuprc/tsup.prod.ts",
20+
"build:npm": "pnpm npm:prepack && pnpm tsup --config ./config/tsuprc/tsup.prod.ts && pnpm npm:postpack",
21+
"------------------------DEPLOYS------------------------": "",
2322
"npm:prepack": "clean-package",
24-
"pre": "git add . && npx lint-staged",
25-
"prepare": "",
26-
"prepublishOnly": "pnpm build:npm",
27-
"test": "echo \"Error: no test specified\""
23+
"npm:postpack": "clean-package restore",
24+
"------------------------TESTS--------------------------": "",
25+
"test": "echo \"Error: no test specified\"",
26+
"------------------------NPM--------------------------": "",
27+
"prepublishOnly": "pnpm build:npm"
2828
},
2929
"devDependencies": {
3030
"@ineedj/eslintrc": "1.2.3",
31-
"@ineedj/prettierrc": "^2.0.0",
31+
"@ineedj/prettierrc": "3.0.0",
3232
"@ineedj/tsconfig": "^1.0.0",
33+
"@types/node": "^22.10.2",
3334
"clean-package": "^2.2.0",
35+
"esbuild-plugin-copy": "^2.1.1",
3436
"eslint": "^8.57.1",
3537
"prettier": "^3.4.2",
3638
"tsup": "^8.3.5",
@@ -41,5 +43,8 @@
4143
"directory": "dist",
4244
"provenance": true,
4345
"tag": "latest"
46+
},
47+
"dependencies": {
48+
"commander": "^12.1.0"
4449
}
4550
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import "@/cli";
2+
import { program } from "commander";
3+
4+
program.parse(process.argv);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./version";
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { version } from "@/../package.json";
2+
import { program } from "commander";
3+
4+
//----------------------
5+
// CLI APP
6+
//----------------------
7+
8+
program.version(version);

pnpm-lock.yaml

Lines changed: 29 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)