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 +122 -167
- package/package.json +58 -56
- package/src/actions/build/index.js +91 -0
- package/src/actions/create/files/{serve.js → App.js} +51 -51
- package/src/actions/create/files/config.js +55 -0
- package/src/actions/create/files/gitignore.js +8 -5
- package/src/actions/create/files/package-json.js +54 -59
- package/src/actions/create/files/project-js.js +12 -12
- package/src/actions/create/files/project-jsx.js +50 -50
- package/src/actions/create/files/project-ts.js +10 -10
- package/src/actions/create/files/project-tsx.js +50 -50
- package/src/actions/create/files/readme.md.js +13 -13
- package/src/actions/create/files/tsconfig.js +32 -32
- package/src/actions/create/index.js +108 -29
- package/src/actions/create/makeFiles.js +64 -64
- package/src/actions/publish/index.js +19 -0
- package/src/actions/{serve → start}/index.js +92 -97
- package/src/helpers.js +37 -122
- package/src/index.js +33 -30
- package/src/makepack-config.js +66 -0
- package/src/actions/create/files/makepack.js +0 -19
- package/src/actions/create/makeProjectDirectory.js +0 -42
- package/src/actions/create/makeProjectInformation.js +0 -68
- package/src/actions/pack/index.js +0 -112
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
"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
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"
|
|
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
|
|
2
|
-
let ext =
|
|
3
|
-
let _import = ''
|
|
4
|
-
let _code = ''
|
|
5
|
-
|
|
6
|
-
switch (
|
|
7
|
-
case "typescript":
|
|
8
|
-
case "javascript":
|
|
9
|
-
_import = `import add from './${
|
|
10
|
-
_code = `<code>{add(5,5)}</code>`
|
|
11
|
-
break
|
|
12
|
-
case "react with typescript":
|
|
13
|
-
case "react with javascript":
|
|
14
|
-
_import = `import Count from './${
|
|
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: `
|
|
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
|
+
}
|