makepack 1.5.24 → 1.6.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/README.md CHANGED
@@ -1,122 +1,122 @@
1
- <p align="center">
2
- <a href="https://github.com/devnax/makepack" rel="noopener" target="_blank"><img src="https://raw.githubusercontent.com/devnax/makepack/main/logo.png" alt="Makepack logo"></a>
3
- </p>
4
-
5
- <h1 align="center">Makepack</h1>
6
-
7
- **MakePack** is a command-line interface (CLI) tool that helps you to quickly set up, build, and manage JavaScript, TypeScript, React, and React-TypeScript libraries for use in npm projects. With just a few simple commands, you can generate your own libraries, start a development server, or build and publish your project to the npm repository.
8
-
9
-
10
- ## 📥 Installation
11
-
12
- Install `makepack` globally to get started:
13
-
14
- ```sh
15
- npm install -g makepack
16
- ```
17
-
18
- ---
19
-
20
- ## 🎯 Why Choose makepack?
21
- - **Zero-Config Setup** – Instantly scaffold a structured project.
22
- - **TypeScript Support** – Seamlessly work with modern JavaScript.
23
- - **Integrated Dev Server** – Run your package with Vite and Express.
24
- - **Efficient Build System** – Generate optimized ESM and CJS outputs.
25
- - **One-Command Publish** – Deploy your package to npm effortlessly.
26
- ---
27
-
28
- ## 📜 CLI Commands
29
-
30
- ### ✨ `makepack create` – Scaffold a New Project
31
- Quickly initialize a structured package with the following setup:
32
-
33
- ```
34
- src/index.ts or tsx or js or jsx
35
- .gitignore
36
- package.json
37
- README.md
38
- ```
39
-
40
- Run:
41
- ```sh
42
- makepack create
43
- ```
44
- Follow the interactive prompts to configure your project.
45
-
46
- ### 🚀 `makepack start` – Launch the Development Server
47
- Run a Vite + Express server to develop and test your package in real-time.
48
-
49
- ```sh
50
- makepack start
51
- ```
52
-
53
- ### 🏗️ `makepack build` – Compile Your Package
54
- Builds and optimizes your package into the `build` directory.
55
-
56
- ```sh
57
- makepack build
58
- ```
59
-
60
- ### 📦 `makepack publish` – Deploy to NPM
61
- Publish your package to the npm registry in one command.
62
-
63
- ```sh
64
- makepack publish
65
- ```
66
-
67
- ---
68
-
69
- ## ⚙️ Configuration
70
-
71
- Customize your project by creating a `makepack.js` file in the root directory. This file allows full control over the build and dev environment.
72
-
73
- ### 🔧 Default Configuration
74
-
75
- ```js
76
- module.exports = (prevConfig) => ({
77
- build: {
78
- outdir: "build",
79
- types: true,
80
- formatPackageJson: (p) => p,
81
- configs: [
82
- {
83
- entryPoints: "src/**/*.{tsx,ts,js,jsx}",
84
- outdir: "esm",
85
- format: "esm",
86
- sourcemap: true,
87
- jsx: 'automatic',
88
- loader: {
89
- '.ts': 'ts',
90
- '.tsx': 'tsx'
91
- },
92
- },
93
- {
94
- entryPoints: "src/**/*.{tsx,ts,js,jsx}",
95
- outdir: "",
96
- format: "cjs",
97
- sourcemap: true,
98
- jsx: 'automatic',
99
- loader: {
100
- '.ts': 'ts',
101
- '.tsx': 'tsx'
102
- },
103
- }
104
- ]
105
- },
106
- start: {
107
- port: 5000,
108
- entry: "App.tsx",
109
- }
110
- });
111
- ```
112
-
113
- ---
114
-
115
- ## 📜 License
116
-
117
- `makepack` is released under the **MIT License**, allowing free usage in both open-source and commercial projects.
118
-
119
- ---
120
-
121
- 🚀 **Start building your next NPM package with `makepack` today!**
122
-
1
+ <p align="center">
2
+ <a href="https://github.com/devnax/makepack" rel="noopener" target="_blank"><img src="https://raw.githubusercontent.com/devnax/makepack/main/logo.png" alt="Makepack logo"></a>
3
+ </p>
4
+
5
+ <h1 align="center">Makepack</h1>
6
+
7
+ **MakePack** is a command-line interface (CLI) tool that helps you to quickly set up, build, and manage JavaScript, TypeScript, React, and React-TypeScript libraries for use in npm projects. With just a few simple commands, you can generate your own libraries, start a development server, or build and publish your project to the npm repository.
8
+
9
+
10
+ ## 📥 Installation
11
+
12
+ Install `makepack` globally to get started:
13
+
14
+ ```sh
15
+ npm install -g makepack
16
+ ```
17
+
18
+ ---
19
+
20
+ ## 🎯 Why Choose makepack?
21
+ - **Zero-Config Setup** – Instantly scaffold a structured project.
22
+ - **TypeScript Support** – Seamlessly work with modern JavaScript.
23
+ - **Integrated Dev Server** – Run your package with Vite and Express.
24
+ - **Efficient Build System** – Generate optimized ESM and CJS outputs.
25
+ - **One-Command Publish** – Deploy your package to npm effortlessly.
26
+ ---
27
+
28
+ ## 📜 CLI Commands
29
+
30
+ ### ✨ `makepack create` – Scaffold a New Project
31
+ Quickly initialize a structured package with the following setup:
32
+
33
+ ```
34
+ src/index.ts or tsx or js or jsx
35
+ .gitignore
36
+ package.json
37
+ README.md
38
+ ```
39
+
40
+ Run:
41
+ ```sh
42
+ makepack create
43
+ ```
44
+ Follow the interactive prompts to configure your project.
45
+
46
+ ### 🚀 `makepack start` – Launch the Development Server
47
+ Run a Vite + Express server to develop and test your package in real-time.
48
+
49
+ ```sh
50
+ makepack start
51
+ ```
52
+
53
+ ### 🏗️ `makepack build` – Compile Your Package
54
+ Builds and optimizes your package into the `build` directory.
55
+
56
+ ```sh
57
+ makepack build
58
+ ```
59
+
60
+ ### 📦 `makepack publish` – Deploy to NPM
61
+ Publish your package to the npm registry in one command.
62
+
63
+ ```sh
64
+ makepack publish
65
+ ```
66
+
67
+ ---
68
+
69
+ ## ⚙️ Configuration
70
+
71
+ Customize your project by creating a `makepack.js` file in the root directory. This file allows full control over the build and dev environment.
72
+
73
+ ### 🔧 Default Configuration
74
+
75
+ ```js
76
+ module.exports = (prevConfig) => ({
77
+ build: {
78
+ outdir: "build",
79
+ types: true,
80
+ formatPackageJson: (p) => p,
81
+ configs: [
82
+ {
83
+ entryPoints: "src/**/*.{tsx,ts,js,jsx}",
84
+ outdir: "esm",
85
+ format: "esm",
86
+ sourcemap: true,
87
+ jsx: 'automatic',
88
+ loader: {
89
+ '.ts': 'ts',
90
+ '.tsx': 'tsx'
91
+ },
92
+ },
93
+ {
94
+ entryPoints: "src/**/*.{tsx,ts,js,jsx}",
95
+ outdir: "",
96
+ format: "cjs",
97
+ sourcemap: true,
98
+ jsx: 'automatic',
99
+ loader: {
100
+ '.ts': 'ts',
101
+ '.tsx': 'tsx'
102
+ },
103
+ }
104
+ ]
105
+ },
106
+ start: {
107
+ port: 5000,
108
+ entry: "App.tsx",
109
+ }
110
+ });
111
+ ```
112
+
113
+ ---
114
+
115
+ ## 📜 License
116
+
117
+ `makepack` is released under the **MIT License**, allowing free usage in both open-source and commercial projects.
118
+
119
+ ---
120
+
121
+ 🚀 **Start building your next NPM package with `makepack` today!**
122
+
package/package.json CHANGED
@@ -1,62 +1,62 @@
1
- {
2
- "name": "makepack",
3
- "version": "1.5.24",
4
- "type": "module",
5
- "description": "A CLI tool to create, build, and manage JavaScript, TypeScript, React, and React-TypeScript libraries for npm projects.",
6
- "files": [
7
- "src",
8
- "package.json",
9
- "README.md"
10
- ],
11
- "categories": [
12
- "Other"
13
- ],
14
- "author": {
15
- "name": "Devnax",
16
- "email": "devnaxrul@gmail.com"
17
- },
18
- "bin": "./src/index.js",
19
- "repository": {
20
- "type": "git",
21
- "url": "https://github.com/devnax/makepack"
22
- },
23
- "bugs": {
24
- "url": "https://github.com/devnax/makepack/issues"
25
- },
26
- "homepage": "https://github.com/devnax/makepack#readme",
27
- "scripts": {
28
- "start": "node ./src/index.js start",
29
- "create": "node ./src/index.js create",
30
- "build": "node ./src/index.js build"
31
- },
32
- "dependencies": {
33
- "chalk": "^5.4.1",
34
- "chokidar": "^4.0.3",
35
- "commander": "^12.1.0",
36
- "cosmiconfig": "^9.0.0",
37
- "esbuild": "^0.25.0",
38
- "express": "^4.21.1",
39
- "figlet": "^1.8.0",
40
- "figures": "^6.1.0",
41
- "fs-extra": "^11.2.0",
42
- "glob": "^11.0.0",
43
- "inquirer": "^12.1.0",
44
- "ora": "^8.1.1",
45
- "typescript": "^5.7.2",
46
- "vite": "^6.0.2"
47
- },
48
- "keywords": [
49
- "CLI",
50
- "npm",
51
- "library",
52
- "JavaScript",
53
- "TypeScript",
54
- "React",
55
- "npm-package"
56
- ],
57
- "devDependencies": {
58
- "@types/fs-extra": "^11.0.4",
59
- "react": "^19.0.0",
60
- "react-dom": "^19.0.0"
61
- }
1
+ {
2
+ "name": "makepack",
3
+ "version": "1.6.0",
4
+ "type": "module",
5
+ "description": "A CLI tool to create, build, and manage JavaScript, TypeScript, React, and React-TypeScript libraries for npm projects.",
6
+ "files": [
7
+ "src",
8
+ "package.json",
9
+ "README.md"
10
+ ],
11
+ "categories": [
12
+ "Other"
13
+ ],
14
+ "author": {
15
+ "name": "Devnax",
16
+ "email": "devnaxrul@gmail.com"
17
+ },
18
+ "bin": "./src/index.js",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/devnax/makepack"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/devnax/makepack/issues"
25
+ },
26
+ "homepage": "https://github.com/devnax/makepack#readme",
27
+ "scripts": {
28
+ "start": "node ./src/index.js start --port 3000",
29
+ "create": "node ./src/index.js create",
30
+ "build": "node ./src/index.js build"
31
+ },
32
+ "dependencies": {
33
+ "chalk": "^5.4.1",
34
+ "chokidar": "^4.0.3",
35
+ "commander": "^12.1.0",
36
+ "cosmiconfig": "^9.0.0",
37
+ "esbuild": "^0.25.0",
38
+ "express": "^4.21.1",
39
+ "figlet": "^1.8.0",
40
+ "figures": "^6.1.0",
41
+ "fs-extra": "^11.2.0",
42
+ "glob": "^11.0.0",
43
+ "inquirer": "^12.1.0",
44
+ "ora": "^8.1.1",
45
+ "typescript": "^5.7.2",
46
+ "vite": "^6.0.2"
47
+ },
48
+ "keywords": [
49
+ "CLI",
50
+ "npm",
51
+ "library",
52
+ "JavaScript",
53
+ "TypeScript",
54
+ "React",
55
+ "npm-package"
56
+ ],
57
+ "devDependencies": {
58
+ "@types/fs-extra": "^11.0.4",
59
+ "react": "^19.0.0",
60
+ "react-dom": "^19.0.0"
61
+ }
62
62
  }
@@ -1,110 +1,164 @@
1
- import esbuild from 'esbuild'
2
- import fs from 'fs-extra'
3
- import path from 'path'
4
- import chalk from 'chalk'
5
- import ora from 'ora'
6
- import { glob } from 'glob'
7
- import ts from 'typescript'
8
- import makepackConfig from '../../makepack-config.js'
9
-
10
- const build = async () => {
11
-
12
- const spinner = ora("Generating a production build for the package...").start();
13
-
14
- try {
15
- const { build } = await makepackConfig()
16
- const configs = build.configs
17
- if (!configs || !configs.length) process.exit("Invalid configuration");
18
- const outdir = path.join(process.cwd(), build.outdir)
19
-
20
- try {
21
- fs.removeSync(outdir);
22
- fs.mkdirSync(outdir);
23
- } catch (err) { }
24
-
25
- const batchSize = 500;
26
- for (let ebconfig of configs) {
27
- const files = await glob(ebconfig.entryPoints) || [];
28
- const entryPoints = files.map(entry => path.join(process.cwd(), entry));
29
- for (let i = 0; i < entryPoints.length; i += batchSize) {
30
- const batch = entryPoints.slice(i, i + batchSize);
31
- await esbuild.build({
32
- ...ebconfig,
33
- entryPoints: batch,
34
- outdir: path.join(outdir, ebconfig.outdir || ''),
35
- });
36
- }
37
- }
38
-
39
- if (build.types) {
40
- const tsconfigPath = path.resolve(process.cwd(), "tsconfig.json");
41
- let tsconfig = {};
42
- if (fs.existsSync(tsconfigPath)) {
43
- const parsedConfig = ts.getParsedCommandLineOfConfigFile(
44
- tsconfigPath,
45
- {},
46
- ts.sys
47
- );
48
-
49
- if (!parsedConfig) {
50
- console.error("❌ Error parsing tsconfig.json");
51
- process.exit(1);
52
- } else {
53
- tsconfig = parsedConfig.options;
54
- }
55
- }
56
-
57
- tsconfig = {
58
- allowJs: true,
59
- target: ts.ScriptTarget.ESNext, // Ensure it's an enum
60
- skipLibCheck: true,
61
- moduleResolution: ts.ModuleResolutionKind.Node10,
62
- ...tsconfig, // Preserve root tsconfig settings
63
- outDir: path.join(outdir, "types"),
64
- declaration: true,
65
- emitDeclarationOnly: true,
66
- noEmit: false,
67
- };
68
-
69
- spinner.text = "Generating TypeScript declarations..."
70
- const files = await glob("src/**/*.{tsx,ts,js,jsx}") || []
71
- const program = ts.createProgram(files, tsconfig);
72
- const emitResult = program.emit();
73
- const diagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
74
-
75
- if (diagnostics.length > 0) {
76
- diagnostics.forEach(diagnostic => {
77
- const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
78
- if (diagnostic.file) {
79
- const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
80
- spinner.fail(`Error at ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
81
- } else {
82
- spinner.fail(`Error: ${message}`);
83
- }
84
- });
85
- } else {
86
- spinner.succeed("TypeScript declaration files generated successfully!")
87
- }
88
- }
89
-
90
- spinner.text = "Copying package.json and readme.md files..."
91
- let packageJson = JSON.parse(fs.readFileSync(path.join(process.cwd(), '/package.json'), 'utf8'));
92
- const formatPackageJson = build.formatPackageJson || ((p) => p)
93
- packageJson = formatPackageJson(packageJson)
94
-
95
- fs.writeFileSync(path.join(process.cwd(), build.outdir, '/package.json'), JSON.stringify(packageJson, null, 2));
96
- fs.copyFileSync(path.join(process.cwd(), '/readme.md'), path.join(process.cwd(), build.outdir, `/readme.md`))
97
- spinner.succeed('Production build generated successfully! The package is ready for deployment.')
98
-
99
- console.log(`\nTo publish your package:`);
100
- console.log(`run: ${chalk.green(`makepack publish`)} to publish the package directly from the current project.`);
101
- console.log(chalk.yellow(`OR`));
102
- console.log(`${chalk.yellow(`Navigate to the ${build.outdir} directory:`)} ${chalk.green(`cd ./${build.outdir}`)} and run ${chalk.green(`npm publish`)}`);
103
-
104
- } catch (error) {
105
- spinner.fail("An error occurred while generating the production build.")
106
- console.error(error);
107
- }
108
- }
109
-
1
+ import esbuild from 'esbuild'
2
+ import fs from 'fs-extra'
3
+ import path from 'path'
4
+ import chalk from 'chalk'
5
+ import ora from 'ora'
6
+ import { glob } from 'glob'
7
+ import ts from 'typescript'
8
+
9
+ const eBuild = async (ebconfig) => {
10
+
11
+ await esbuild.build({
12
+ jsx: 'automatic',
13
+ ...ebconfig,
14
+ outExtension: { '.js': ebconfig.format === "esm" ? '.mjs' : ".cjs" },
15
+ loader: {
16
+ '.ts': 'ts',
17
+ '.tsx': 'tsx'
18
+ },
19
+ outdir: path.join(process.cwd(), '.mpack'),
20
+ })
21
+ }
22
+
23
+ const build = async (args) => {
24
+ /* args
25
+ --format=default
26
+ --bundle=true,
27
+ --minify=false,
28
+ --sourcemap=true,
29
+ --platform=node,
30
+ --target=es2020,
31
+ */
32
+
33
+
34
+ let printBool = (f) => typeof args[f] === 'string' ? (args[f] === 'true') : args[f];
35
+
36
+ args = {
37
+ format: args.format || "default",
38
+ bundle: printBool('bundle'),
39
+ minify: printBool('minify'),
40
+ sourcemap: printBool('sourcemap'),
41
+ platform: args.platform || "",
42
+ target: args.target || "es2020",
43
+ declaration: printBool('declaration'),
44
+ }
45
+
46
+ const outdir = path.join(process.cwd(), '.mpack');
47
+ if (fs.existsSync(outdir)) {
48
+ fs.rmSync(outdir, { recursive: true, force: true });
49
+ }
50
+ fs.mkdirSync(outdir)
51
+
52
+ const spinner = ora("Generating a production build for the package...").start();
53
+ const files = await glob("src/**/*.{tsx,ts,js,jsx}") || [];
54
+ const entryPoints = files.map(entry => path.join(process.cwd(), entry));
55
+ let batchSize = args.format === 'default' ? 300 : 500;
56
+
57
+ let ebconfig = {
58
+ bundle: args.bundle,
59
+ minify: args.minify,
60
+ sourcemap: args.sourcemap,
61
+ platform: args.platform,
62
+ target: args.target,
63
+ }
64
+
65
+ for (let i = 0; i < entryPoints.length; i += batchSize) {
66
+ const batch = entryPoints.slice(i, i + batchSize);
67
+ let config = {
68
+ ...ebconfig,
69
+ entryPoints: batch,
70
+ }
71
+ if (args.format === 'default') {
72
+ await eBuild({ ...config, format: "esm" });
73
+ spinner.succeed('ESM build generated successfully!');
74
+ await eBuild({ ...config, format: "cjs" });
75
+ spinner.succeed('CJS build generated successfully!');
76
+ } else {
77
+ await eBuild({ ...config, format: args.format });
78
+ spinner.succeed(`${args.format} build generated successfully!`);
79
+ }
80
+ }
81
+
82
+
83
+ if (args.declaration) {
84
+ const tsconfigPath = path.resolve(process.cwd(), "tsconfig.json");
85
+ let tsconfig = {};
86
+ if (fs.existsSync(tsconfigPath)) {
87
+ const parsedConfig = ts.getParsedCommandLineOfConfigFile(
88
+ tsconfigPath,
89
+ {},
90
+ ts.sys
91
+ );
92
+
93
+ if (!parsedConfig) {
94
+ console.error("❌ Error parsing tsconfig.json");
95
+ process.exit(1);
96
+ } else {
97
+ tsconfig = parsedConfig.options;
98
+ }
99
+ }
100
+
101
+ tsconfig = {
102
+ allowJs: true,
103
+ target: ts.ScriptTarget.ESNext, // Ensure it's an enum
104
+ skipLibCheck: true,
105
+ moduleResolution: ts.ModuleResolutionKind.Node10,
106
+ ...tsconfig, // Preserve root tsconfig settings
107
+ outDir: outdir,
108
+ declaration: true,
109
+ emitDeclarationOnly: true,
110
+ noEmit: false,
111
+ };
112
+
113
+ spinner.text = "Generating TypeScript declarations..."
114
+ const program = ts.createProgram(files, tsconfig);
115
+ const emitResult = program.emit();
116
+ const diagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
117
+
118
+ if (diagnostics.length > 0) {
119
+ diagnostics.forEach(diagnostic => {
120
+ const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
121
+ if (diagnostic.file) {
122
+ const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
123
+ spinner.fail(`Error at ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
124
+ } else {
125
+ spinner.fail(`Error: ${message}`);
126
+ }
127
+ });
128
+ } else {
129
+ spinner.succeed("TypeScript declaration files generated successfully!")
130
+ }
131
+ }
132
+ spinner.text = "Copying package.json and readme.md files..."
133
+
134
+ // update package.json to include the .mpack directory
135
+ const pkgPath = path.join(process.cwd(), 'package.json');
136
+ if (fs.existsSync(pkgPath)) {
137
+ const pkgjson = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
138
+ if (args.format === 'default') {
139
+ pkgjson.main = "./index.cjs";
140
+ pkgjson.module = "./index.mjs";
141
+ pkgjson.types = './index.d.ts'
142
+ } else {
143
+ let t = args.format === 'mjs' ? 'module' : 'main';
144
+ pkgjson[t] = `./index.${args.format}`;
145
+ }
146
+
147
+ if (args.declaration) {
148
+ pkgjson.types = `index.${args.format}.d.ts`;
149
+ }
150
+
151
+ fs.writeFileSync(path.join(outdir, 'package.json'), JSON.stringify(pkgjson, null, 2));
152
+ } else {
153
+ spinner.fail("package.json not found!");
154
+ return;
155
+ }
156
+
157
+ fs.copyFileSync(path.join(process.cwd(), '/readme.md'), path.join(outdir, `/readme.md`))
158
+ spinner.succeed("package.json and readme.md files copied successfully!")
159
+ console.log(chalk.green(`\nBuild completed successfully!`));
160
+ console.log(`\nTo publish your package to npm:`);
161
+ console.log(`${chalk.green(`npm run publish`)} or navigate to the ${chalk.green(`.mpack`)} directory and run ${chalk.green(`npm publish`)}`);
162
+ }
163
+
110
164
  export default build
@@ -1,9 +1,10 @@
1
- import makepackConfig from "../../../makepack-config.js"
2
-
3
- export default async () => {
4
- const config = await makepackConfig()
5
- return {
6
- content: `node_modules\n${config.build.outdir}`,
7
- filename: ".gitignore"
8
- }
1
+
2
+ export default async () => {
3
+ return {
4
+ content: `
5
+ node_modules
6
+ .mpack
7
+ `,
8
+ filename: ".gitignore"
9
+ }
9
10
  }