makepack 1.4.0 → 1.5.1

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,167 +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
- ## Installation
10
-
11
- To install **MakePack** globally, run the following command:
12
-
13
- ```bash
14
- npm install -g makepack
15
- ```
16
-
17
- This will allow you to use the `makepack` command anywhere in your terminal.
18
-
19
- ## Configuration Files
20
-
21
- Previously, the project used separate configuration files for Vite and esbuild:
22
- - `vite.config.js`
23
- - `esbuild.config.js`
24
-
25
- These files have been removed and replaced with a single configuration file: `makepack.js`.
26
-
27
- ## makepack.js
28
-
29
- The `makepack.js` file exports a function that takes the previous configuration (`prevConfig`) and returns a new configuration (`newConfig`). This allows you to configure both esbuild and Vite in one place.
30
-
31
- ### Example Usage
32
-
33
- ```javascript
34
- // filepath: /Volumes/Work Space/makepack/makepack.js
35
- module.exports = function(prevConfig) {
36
- const newConfig = {
37
- // ...your new configuration here...
38
- };
39
- return newConfig;
40
- };
41
- ```
42
-
43
- This approach simplifies the configuration process by consolidating it into a single file.
44
-
45
- ## Commands
46
-
47
- ### `create`
48
-
49
- The `create` command is used to create a new library project. It initializes the project structure, configures essential files, and sets up the environment for you to start working on your library.
50
-
51
- #### Usage
52
-
53
- ```bash
54
- makepack create
55
- ```
56
-
57
- #### Description
58
-
59
- - Creates a new library project by setting up the necessary configurations and boilerplate files.
60
-
61
- This command will guide you through the initial setup for your library.
62
-
63
- ---
64
-
65
- ### `serve`
66
-
67
- The `serve` command starts a development server for your library, providing you with a live-reload environment where you can test and iterate on your library in real-time. It will load `vite.config.js` if it exists in the root of the project.
68
-
69
- #### Usage
70
-
71
- ```bash
72
- makepack serve [options]
73
- ```
74
-
75
- #### Options
76
-
77
- - `-p, --port <number>`
78
- _Port number_ (optional) (default is `5000`).
79
-
80
- - `-e, --root <file>`
81
- _Root file_ (optional) (default is `serve.jsx` or `serve.tsx`). The entry point for your application. Specify the main JavaScript/TypeScript file to start the server.
82
-
83
- #### Description
84
-
85
- - Starts a local development server for testing and debugging your library.
86
-
87
- Example:
88
-
89
- ```bash
90
- makepack serve --port 4000 --root src/index.ts
91
- ```
92
-
93
- ---
94
-
95
- ### `pack`
96
-
97
- The `pack` command is used to build your library and optionally publish it to the npm repository. This command compiles your code into a distributable format and prepares it for sharing with others. It will load `esbuild.config.js` if it exists in the root of the project.
98
-
99
- #### Usage
100
-
101
- ```bash
102
- makepack pack [options]
103
- ```
104
-
105
- #### Options
106
-
107
- - `-e, --entry <file>`
108
- _Entry file or directory_ (default is `src/**/*.{tsx,ts,js,jsx}`).
109
- Specify the entry file or use a glob pattern to select the files to include in your library.
110
-
111
- - `-p, --publish`
112
- _Publish the project to the npm repository_ (default is `false`).
113
- Add this flag if you want to publish the library to npm after building it.
114
-
115
- #### Description
116
-
117
- - Builds the project by compiling and bundling your library.
118
- - Optionally publishes the library to the npm repository.
119
-
120
- Example:
121
-
122
- ```bash
123
- makepack pack --entry src/index.ts --publish
124
- ```
125
-
126
- This will compile the project from `src/index.ts` and then publish the library to npm.
127
-
128
- ---
129
-
130
- ## Example Workflow
131
-
132
- 1. Create a new project:
133
-
134
- ```bash
135
- makepack create
136
- ```
137
-
138
- 2. Start the server for development:
139
-
140
- ```bash
141
- makepack serve --port 4000 --root index.tsx
142
- ```
143
-
144
- 3. Once you're ready to build and publish your library:
145
-
146
- ```bash
147
- makepack pack --entry src/**/*.{tsx,ts,js,jsx} --publish
148
- ```
149
-
150
- This will build your library and publish it to npm.
151
-
152
-
153
- ## 🤝 Contributing
154
-
155
- Contributions are welcome! Please check out the [contribution guidelines](https://github.com/devnax/makepack).
156
-
157
- ---
158
-
159
- ## 📄 License
160
-
161
- This project is licensed under the [MIT License](https://opensource.org/licenses/MIT).
162
-
163
- ---
164
-
165
- ## 📞 Support
166
-
167
- For help or suggestions, feel free to open an issue on [GitHub](https://github.com/devnax/makepack/issues) or contact us via [devnaxrul@gmail.com](mailto:devnaxrul@gmail.com).
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,57 +1,59 @@
1
- {
2
- "name": "makepack",
3
- "version": "1.4.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"
29
- },
30
- "dependencies": {
31
- "chalk": "^5.4.1",
32
- "commander": "^12.1.0",
33
- "esbuild": "^0.24.2",
34
- "express": "^4.21.1",
35
- "figlet": "^1.8.0",
36
- "figures": "^6.1.0",
37
- "fs-extra": "^11.2.0",
38
- "glob": "^11.0.0",
39
- "inquirer": "^12.1.0",
40
- "typescript": "^5.7.2",
41
- "vite": "^6.0.2",
42
- "@vitejs/plugin-react": "^4.3.4"
43
- },
44
- "keywords": [
45
- "CLI",
46
- "npm",
47
- "library",
48
- "JavaScript",
49
- "TypeScript",
50
- "React",
51
- "npm-package"
52
- ],
53
- "devDependencies": {
54
- "react": "^19.0.0",
55
- "react-dom": "^19.0.0"
56
- }
1
+ {
2
+ "name": "makepack",
3
+ "version": "1.5.1",
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"
29
+ },
30
+ "dependencies": {
31
+ "@vitejs/plugin-react": "^4.3.4",
32
+ "chalk": "^5.4.1",
33
+ "commander": "^12.1.0",
34
+ "esbuild": "^0.24.2",
35
+ "express": "^4.21.1",
36
+ "figlet": "^1.8.0",
37
+ "figures": "^6.1.0",
38
+ "fs-extra": "^11.2.0",
39
+ "glob": "^11.0.0",
40
+ "inquirer": "^12.1.0",
41
+ "ora": "^8.1.1",
42
+ "typescript": "^5.7.2",
43
+ "vite": "^6.0.2"
44
+ },
45
+ "keywords": [
46
+ "CLI",
47
+ "npm",
48
+ "library",
49
+ "JavaScript",
50
+ "TypeScript",
51
+ "React",
52
+ "npm-package"
53
+ ],
54
+ "devDependencies": {
55
+ "@types/fs-extra": "^11.0.4",
56
+ "react": "^19.0.0",
57
+ "react-dom": "^19.0.0"
58
+ }
57
59
  }
@@ -0,0 +1,91 @@
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 { execSync } from '../../helpers.js'
9
+ import makepackConfig from '../../makepack-config.js'
10
+
11
+ const build = async (args) => {
12
+
13
+ const spinner = ora("Generating a production build for the package...").start();
14
+
15
+ try {
16
+ const { build } = await makepackConfig()
17
+ const configs = build.configs
18
+ if (!configs || !configs.length) process.exit("Invalid configuration");
19
+ const outdir = path.join(process.cwd(), build.outdir)
20
+
21
+ try {
22
+ fs.removeSync(outdir);
23
+ fs.mkdirSync(outdir);
24
+ } catch (err) { }
25
+
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
+ esbuild.buildSync({
30
+ ...ebconfig,
31
+ entryPoints,
32
+ outdir: path.join(outdir, ebconfig.outdir || ''),
33
+ });
34
+ }
35
+
36
+ if (build.types) {
37
+ let tsconfig = {
38
+ outDir: path.join(outdir, 'types'),
39
+ declaration: true,
40
+ emitDeclarationOnly: true,
41
+ strict: true,
42
+ allowJs: true,
43
+ jsx: ts.JsxEmit.React,
44
+ esModuleInterop: true,
45
+ }
46
+ spinner.text = "Generating TypeScript declarations..."
47
+ const files = await glob("src/**/*.{tsx,ts,js,jsx}") || []
48
+ const program = ts.createProgram(files, tsconfig);
49
+ const emitResult = program.emit();
50
+ const diagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
51
+
52
+ if (diagnostics.length > 0) {
53
+ diagnostics.forEach(diagnostic => {
54
+ const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
55
+ if (diagnostic.file) {
56
+ const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
57
+ spinner.fail(`Error at ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
58
+ } else {
59
+ spinner.fail(`Error: ${message}`);
60
+ }
61
+ });
62
+ } else {
63
+ spinner.succeed("TypeScript declaration files generated successfully!")
64
+ }
65
+ }
66
+
67
+ spinner.text = "Copying package.json and readme.md files..."
68
+ let packageJson = JSON.parse(fs.readFileSync(path.join(process.cwd(), '/package.json'), 'utf8'));
69
+ const formatPackageJson = build.formatPackageJson || ((p) => p)
70
+ packageJson = formatPackageJson(packageJson)
71
+
72
+ fs.writeFileSync(path.join(process.cwd(), outdir, '/package.json'), JSON.stringify(packageJson, null, 2));
73
+ fs.copyFileSync(path.join(process.cwd(), '/readme.md'), path.join(process.cwd(), outdir, `/readme.md`))
74
+ spinner.succeed('Production build generated successfully! The package is ready for deployment.')
75
+
76
+ if (args.publish) {
77
+ console.log("Publishing the production build to the npm repository...")
78
+ execSync(`npm publish`, {
79
+ cwd: path.join(process.cwd(), outdir)
80
+ })
81
+ } else {
82
+ console.log(`\nTo publish your package:`);
83
+ console.log(`${chalk.yellow(`1. Navigate to the ${outdir} directory:`)}\n ${chalk.green(`cd ./${outdir}`)}\n${chalk.yellow(`2. Publish the buildage to npm:`)}\n${chalk.green(`npm publish`)}\nYour buildage is ready to share with the world! 🚀`);
84
+ }
85
+ } catch (error) {
86
+ spinner.fail("An error occurred while generating the production build.")
87
+ console.error(error);
88
+ }
89
+ }
90
+
91
+ export default build
@@ -1,52 +1,52 @@
1
- export default args => {
2
- let ext = args.template === 'react with typescript' ? ".tsx" : ".jsx"
3
- let _import = ''
4
- let _code = ''
5
-
6
- switch (args.template) {
7
- case "typescript":
8
- case "javascript":
9
- _import = `import add from './${args.rootdir}'`
10
- _code = `<code>{add(5,5)}</code>`
11
- break
12
- case "react with typescript":
13
- case "react with javascript":
14
- _import = `import Count from './${args.rootdir}'`
15
- _code = `<Count />`
16
- break;
17
- }
18
-
19
- const content = `import React from 'react';
20
- import { createRoot } from 'react-dom/client';
21
- ${_import}
22
-
23
- const App = () => {
24
- return (
25
- <div style={{fontFamily: 'monospace,math, sans-serif', textAlign: 'center', marginTop: '50px' }}>
26
- <h1>Welcome to makepack CLI!</h1>
27
- <p>Edit <code>index.tsx</code> and save to reload.</p>
28
- <a
29
- href="https://reactjs.org"
30
- target="_blank"
31
- rel="noopener noreferrer"
32
- style={{ color: '#61dafb', textDecoration: 'none' }}
33
- >
34
- Learn React
35
- </a>
36
- <div style={{marginTop: "50px"}}>
37
- ${_code}
38
- </div>
39
- </div>
40
- );
41
- }
42
- const rootEle = document.getElementById('root')
43
- if (rootEle) {
44
- const root = createRoot(rootEle);
45
- root.render(<App />);
46
- }
47
- `
48
- return {
49
- content,
50
- filename: `serve${ext}`
51
- }
1
+ export default async (info) => {
2
+ let ext = info.template.includes('typescript') ? ".tsx" : ".jsx"
3
+ let _import = ''
4
+ let _code = ''
5
+
6
+ switch (info.template) {
7
+ case "typescript":
8
+ case "javascript":
9
+ _import = `import add from './${info.sourceDir}'`
10
+ _code = `<code>{add(5,5)}</code>`
11
+ break
12
+ case "react with typescript":
13
+ case "react with javascript":
14
+ _import = `import Count from './${info.sourceDir}'`
15
+ _code = `<Count />`
16
+ break;
17
+ }
18
+
19
+ const content = `import React from 'react';
20
+ import { createRoot } from 'react-dom/client';
21
+ ${_import}
22
+
23
+ const App = () => {
24
+ return (
25
+ <div style={{fontFamily: 'monospace,math, sans-serif', textAlign: 'center', marginTop: '50px' }}>
26
+ <h1>Welcome to makepack CLI!</h1>
27
+ <p>Edit <code>index.tsx</code> and save to reload.</p>
28
+ <a
29
+ href="https://reactjs.org"
30
+ target="_blank"
31
+ rel="noopener noreferrer"
32
+ style={{ color: '#61dafb', textDecoration: 'none' }}
33
+ >
34
+ Learn React
35
+ </a>
36
+ <div style={{marginTop: "50px"}}>
37
+ ${_code}
38
+ </div>
39
+ </div>
40
+ );
41
+ }
42
+ const rootEle = document.getElementById('root')
43
+ if (rootEle) {
44
+ const root = createRoot(rootEle);
45
+ root.render(<App />);
46
+ }
47
+ `
48
+ return {
49
+ content,
50
+ filename: `App${ext}`
51
+ }
52
52
  }
@@ -0,0 +1,55 @@
1
+ import { loadConfig } from "../../../helpers.js"
2
+
3
+ export default async (info) => {
4
+ const config = await loadConfig()
5
+ let dependencies = {}
6
+ let devDependencies = {
7
+ "makepack": "latest",
8
+ "react": "^19.0.0",
9
+ "react-dom": "^19.0.0",
10
+ "express": "latest"
11
+ }
12
+
13
+ if (args.template.includes("typescript")) {
14
+ devDependencies["typescript"] = "^4.4.2"
15
+ devDependencies["@types/react"] = "^19.0.2"
16
+ devDependencies["@types/react-dom"] = "^19.0.2"
17
+ devDependencies["@types/express"] = "latest"
18
+ }
19
+
20
+ let main = args.entry.split('.')
21
+ main.pop()
22
+
23
+ const json = {
24
+ name: args.dirname,
25
+ version: "1.0.0",
26
+ main: `./${config.build.outdir}/cjs/index.js`,
27
+ module: `./${config.build.outdir}/index.js`,
28
+ types: `./${config.build.outdir}/index.d.ts`,
29
+ description: "",
30
+ keywords: [],
31
+ exports: {
32
+ ".": {
33
+ "types": `./${config.build.outdir}/index.d.ts`,
34
+ "import": `./${config.build.outdir}/index.js`,
35
+ "require": `./${config.build.outdir}/cjs/index.js`
36
+ },
37
+ "./*": {
38
+ "import": `./${config.build.outdir}/*.js`,
39
+ "require": `./${config.build.outdir}/cjs/*.js`
40
+ }
41
+ },
42
+ scripts: {
43
+ "start": "makepack serve",
44
+ "build": "makepack build",
45
+ "prepare": "npm run build",
46
+ },
47
+ dependencies,
48
+ devDependencies
49
+ }
50
+
51
+ return {
52
+ content: JSON.stringify(json, null, 3),
53
+ filename: "package.json"
54
+ }
55
+ }