makepack 1.0.0 → 1.0.2
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 +132 -0
- package/package.json +20 -22
- package/src/actions/create/files/gitignore.js +6 -0
- package/src/actions/create/files/makepack.js +19 -0
- package/src/actions/create/files/package-json.js +38 -0
- package/src/actions/create/files/project-js.js +13 -0
- package/src/actions/create/files/project-react-js.js +25 -0
- package/src/actions/create/files/project-react-ts.js +25 -0
- package/src/actions/create/files/project-ts.js +11 -0
- package/src/actions/create/files/tsconfig.js +32 -0
- package/src/actions/create/index.js +26 -0
- package/src/actions/create/makeFiles.js +42 -0
- package/src/actions/create/makeProjectDirectory.js +42 -0
- package/src/actions/create/makeProjectInformation.js +66 -0
- package/src/actions/{build.js → pack.js} +33 -11
- package/src/actions/serve.js +21 -7
- package/src/helpers.js +3 -3
- package/src/index.js +8 -8
- package/index.html +0 -16
- package/src/actions/create.js +0 -195
- package/test/browser.js +0 -5
- package/test/client.tsx +0 -10
- package/test/index.ts +0 -8
- package/test/math.ts +0 -0
- package/tsconfig.json +0 -29
package/README.md
CHANGED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# MakePack CLI Documentation
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
**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.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
To install **MakePack** globally, run the following command:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install -g makepack
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
This will allow you to use the `makepack` command anywhere in your terminal.
|
|
16
|
+
|
|
17
|
+
## Commands
|
|
18
|
+
|
|
19
|
+
### `create`
|
|
20
|
+
|
|
21
|
+
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.
|
|
22
|
+
|
|
23
|
+
#### Usage
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
makepack create
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
#### Description
|
|
30
|
+
|
|
31
|
+
- Creates a new library project by setting up the necessary configurations and boilerplate files.
|
|
32
|
+
|
|
33
|
+
This command will guide you through the initial setup for your library.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
### `serve`
|
|
38
|
+
|
|
39
|
+
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.
|
|
40
|
+
|
|
41
|
+
#### Usage
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
makepack serve [options]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
#### Options
|
|
48
|
+
|
|
49
|
+
- `-p, --port <type>`
|
|
50
|
+
_Port number_ (default is `3000`).
|
|
51
|
+
|
|
52
|
+
- `-e, --entry <type>`
|
|
53
|
+
_Entry file_ (optional). The entry point for your application. Specify the main JavaScript/TypeScript file to start the server.
|
|
54
|
+
|
|
55
|
+
#### Description
|
|
56
|
+
|
|
57
|
+
- Starts a local development server for testing and debugging your library.
|
|
58
|
+
|
|
59
|
+
Example:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
makepack serve --port 4000 --entry src/index.ts
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
### `pack`
|
|
68
|
+
|
|
69
|
+
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.
|
|
70
|
+
|
|
71
|
+
#### Usage
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
makepack pack [options]
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### Options
|
|
78
|
+
|
|
79
|
+
- `-e, --entry <type>`
|
|
80
|
+
_Entry file or directory_ (default is `src/**/*.{tsx,ts,js,jsx}`).
|
|
81
|
+
Specify the entry file or use a glob pattern to select the files to include in your library.
|
|
82
|
+
|
|
83
|
+
- `-p, --publish`
|
|
84
|
+
_Publish the project to the npm repository_ (default is `false`).
|
|
85
|
+
Add this flag if you want to publish the library to npm after building it.
|
|
86
|
+
|
|
87
|
+
#### Description
|
|
88
|
+
|
|
89
|
+
- Builds the project by compiling and bundling your library.
|
|
90
|
+
- Optionally publishes the library to the npm repository.
|
|
91
|
+
|
|
92
|
+
Example:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
makepack pack --entry src/index.ts --publish
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
This will compile the project from `src/index.ts` and then publish the library to npm.
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Example Workflow
|
|
103
|
+
|
|
104
|
+
1. Create a new project:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
makepack create
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
2. Start the server for development:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
makepack serve --port 4000 --entry src/index.ts
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
3. Once you're ready to build and publish your library:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
makepack pack --entry src/**/*.{tsx,ts,js,jsx} --publish
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
This will build your library and publish it to npm.
|
|
123
|
+
|
|
124
|
+
## GitHub Repository
|
|
125
|
+
|
|
126
|
+
For more details, open issues, or contribute to the project, visit the [MakePack GitHub Repository](https://github.com/devnax/makepack).
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## License
|
|
131
|
+
|
|
132
|
+
This project is licensed under the MIT License. See the LICENSE file for more information.
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "makepack",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "A
|
|
5
|
+
"description": "A CLI tool to create, build, and manage JavaScript, TypeScript, React, and React-TypeScript libraries for npm projects.",
|
|
6
6
|
"categories": [
|
|
7
7
|
"Other"
|
|
8
8
|
],
|
|
@@ -15,31 +15,29 @@
|
|
|
15
15
|
"type": "git",
|
|
16
16
|
"url": "https://github.com/devnax/makepack"
|
|
17
17
|
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/devnax/makepack/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/devnax/makepack#readme",
|
|
18
22
|
"scripts": {},
|
|
19
|
-
"devDependencies": {
|
|
20
|
-
|
|
21
|
-
"@types/express": "^5.0.0",
|
|
22
|
-
"@types/node": "^22.10.1",
|
|
23
|
-
"@types/react": "^18.3.12",
|
|
24
|
-
"@types/react-dom": "^18.3.1",
|
|
25
|
-
"@vitejs/plugin-react": "^4.3.4",
|
|
23
|
+
"devDependencies": {},
|
|
24
|
+
"dependencies": {
|
|
26
25
|
"commander": "^12.1.0",
|
|
26
|
+
"inquirer": "^12.1.0",
|
|
27
27
|
"esbuild": "^0.24.2",
|
|
28
|
-
"eslint": "^9.15.0",
|
|
29
|
-
"eslint-plugin-react-hooks": "^5.0.0",
|
|
30
|
-
"eslint-plugin-react-refresh": "^0.4.14",
|
|
31
28
|
"express": "^4.21.1",
|
|
32
29
|
"fs-extra": "^11.2.0",
|
|
33
|
-
"globals": "^15.12.0",
|
|
34
|
-
"inquirer": "^12.1.0",
|
|
35
|
-
"tsx": "^4.19.2",
|
|
36
30
|
"typescript": "^5.7.2",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
31
|
+
"vite": "^6.0.2",
|
|
32
|
+
"glob": "^11.0.0"
|
|
39
33
|
},
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
|
|
34
|
+
"keywords": [
|
|
35
|
+
"CLI",
|
|
36
|
+
"npm",
|
|
37
|
+
"library",
|
|
38
|
+
"JavaScript",
|
|
39
|
+
"TypeScript",
|
|
40
|
+
"React",
|
|
41
|
+
"npm-package"
|
|
42
|
+
]
|
|
45
43
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export default (args) => {
|
|
2
|
+
const makepack = {
|
|
3
|
+
"template": `${args.template}`,
|
|
4
|
+
"serve": {
|
|
5
|
+
"port": 3000,
|
|
6
|
+
"entry": `${args.rootdir}/${args.entry}`
|
|
7
|
+
},
|
|
8
|
+
"build": {
|
|
9
|
+
"entry": `${args.rootdir}/**/*.{tsx,ts,js,jsx}`,
|
|
10
|
+
"outdir": `${args.outdir}`,
|
|
11
|
+
"esbuild": {
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
content: `const makepack = ${JSON.stringify(makepack, null, 2)}\nexport default makepack\n`,
|
|
17
|
+
filename: "makepack.js"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export default (args) => {
|
|
2
|
+
let dependencies = {}
|
|
3
|
+
let devDependencies = {
|
|
4
|
+
"makepack": "latest"
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
if (args.template.includes("react")) {
|
|
8
|
+
dependencies = {
|
|
9
|
+
"react": "^17.0.2",
|
|
10
|
+
"react-dom": "^17.0.2"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (args.template.includes("typescript")) {
|
|
15
|
+
devDependencies["typescript"] = "^4.4.2"
|
|
16
|
+
devDependencies["@types/react"] = "^18.3.12"
|
|
17
|
+
devDependencies["@types/react-dom"] = "^18.3.1"
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const json = {
|
|
21
|
+
name: args.diraname,
|
|
22
|
+
version: "1.0.0",
|
|
23
|
+
description: "",
|
|
24
|
+
main: `${args.outdir}/${args.entry}`,
|
|
25
|
+
scripts: {
|
|
26
|
+
"start": "makepack serve",
|
|
27
|
+
"build": "makepack build",
|
|
28
|
+
},
|
|
29
|
+
dependencies,
|
|
30
|
+
devDependencies,
|
|
31
|
+
keywords: [],
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
content: JSON.stringify(json, null, 3),
|
|
36
|
+
filename: "package.json"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export default (args) => {
|
|
2
|
+
const content = `import React from 'react';
|
|
3
|
+
const App = () => {
|
|
4
|
+
return (
|
|
5
|
+
<div style={{ textAlign: 'center', marginTop: '50px' }}>
|
|
6
|
+
<h1>Welcome to React JS with makepack CLI!</h1>
|
|
7
|
+
<p>Edit <code>index.tsx</code> and save to reload.</p>
|
|
8
|
+
<a
|
|
9
|
+
href="https://reactjs.org"
|
|
10
|
+
target="_blank"
|
|
11
|
+
rel="noopener noreferrer"
|
|
12
|
+
style={{ color: '#61dafb', textDecoration: 'none' }}
|
|
13
|
+
>
|
|
14
|
+
Learn React
|
|
15
|
+
</a>
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
};
|
|
19
|
+
export default App;
|
|
20
|
+
`
|
|
21
|
+
return {
|
|
22
|
+
content,
|
|
23
|
+
filename: `${args.rootdir}/${args.entry}`
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export default args => {
|
|
2
|
+
const content = `import React from 'react';
|
|
3
|
+
const App: React.FC = () => {
|
|
4
|
+
return (
|
|
5
|
+
<div style={{ textAlign: 'center', marginTop: '50px' }}>
|
|
6
|
+
<h1>Welcome to React Typescript with makepack CLI!</h1>
|
|
7
|
+
<p>Edit <code>index.tsx</code> and save to reload.</p>
|
|
8
|
+
<a
|
|
9
|
+
href="https://reactjs.org"
|
|
10
|
+
target="_blank"
|
|
11
|
+
rel="noopener noreferrer"
|
|
12
|
+
style={{ color: '#61dafb', textDecoration: 'none' }}
|
|
13
|
+
>
|
|
14
|
+
Learn React
|
|
15
|
+
</a>
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
export default App;
|
|
20
|
+
`
|
|
21
|
+
return {
|
|
22
|
+
content,
|
|
23
|
+
filename: `${args.rootdir}/${args.entry}`
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export default args => {
|
|
2
|
+
const content = {
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es5",
|
|
5
|
+
"lib": [
|
|
6
|
+
"dom",
|
|
7
|
+
"dom.iterable",
|
|
8
|
+
"esnext"
|
|
9
|
+
],
|
|
10
|
+
"allowJs": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
"allowSyntheticDefaultImports": true,
|
|
14
|
+
"strict": true,
|
|
15
|
+
"forceConsistentCasingInFileNames": true,
|
|
16
|
+
"module": "esnext",
|
|
17
|
+
"moduleResolution": "node",
|
|
18
|
+
"resolveJsonModule": true,
|
|
19
|
+
"isolatedModules": true,
|
|
20
|
+
"noEmit": true,
|
|
21
|
+
},
|
|
22
|
+
"include": [args.rootdir],
|
|
23
|
+
"exclude": [
|
|
24
|
+
"node_modules"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
content: JSON.stringify(content, null, 2),
|
|
30
|
+
filename: "tsconfig.json"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { execSync, logLoader, __dirname } from "../../helpers.js"
|
|
2
|
+
import makeProjectInformation from "./makeProjectInformation.js"
|
|
3
|
+
import makeFiles from "./makeFiles.js"
|
|
4
|
+
|
|
5
|
+
const create = async () => {
|
|
6
|
+
let projectInformation = await makeProjectInformation()
|
|
7
|
+
let loader = logLoader("Creating project...")
|
|
8
|
+
await makeFiles(projectInformation)
|
|
9
|
+
loader.stop("")
|
|
10
|
+
|
|
11
|
+
loader = logLoader("Installing dependencies...")
|
|
12
|
+
execSync("npm install", {
|
|
13
|
+
cwd: projectInformation.cwd,
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
loader.stop("Project setup complete!")
|
|
17
|
+
if (projectInformation.isCurrentDir) {
|
|
18
|
+
console.log(`Run the development server: \n makepack serve\nEnjoy your new project! 😊`);
|
|
19
|
+
} else {
|
|
20
|
+
console.log(`To start working with your project:\n1. Navigate to your project directory:\ncd ${projectInformation.dirname}\n2. Run the development server:\nmakepack serve\nEnjoy your new project! 😊`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default create
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// import makepack from "./files/makepack.js";
|
|
2
|
+
import packageJson from "./files/package-json.js";
|
|
3
|
+
import gitignore from "./files/gitignore.js";
|
|
4
|
+
import tsconfig from "./files/tsconfig.js";
|
|
5
|
+
import projectJs from "./files/project-js.js";
|
|
6
|
+
import projectTs from "./files/project-ts.js";
|
|
7
|
+
import projectReactJs from "./files/project-react-js.js";
|
|
8
|
+
import projectReactTs from "./files/project-react-ts.js";
|
|
9
|
+
|
|
10
|
+
import fs from "fs-extra"
|
|
11
|
+
import path from "path"
|
|
12
|
+
|
|
13
|
+
export default async (args) => {
|
|
14
|
+
const files = [
|
|
15
|
+
packageJson(args),
|
|
16
|
+
gitignore(args),
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
switch (args.template) {
|
|
20
|
+
case "typescript":
|
|
21
|
+
files.push(projectTs(args))
|
|
22
|
+
break;
|
|
23
|
+
case "javascript":
|
|
24
|
+
files.push(projectJs(args))
|
|
25
|
+
break;
|
|
26
|
+
case "react with typescript":
|
|
27
|
+
files.push(projectReactTs(args))
|
|
28
|
+
break;
|
|
29
|
+
case "react with javascript":
|
|
30
|
+
files.push(projectReactJs(args))
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// push ts config
|
|
35
|
+
if (args.template.includes("typescript")) {
|
|
36
|
+
files.push(tsconfig(args))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
for (let file of files) {
|
|
40
|
+
fs.writeFileSync(path.join(args.cwd, file.filename), file.content)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import path from "path"
|
|
2
|
+
import fs from "fs-extra"
|
|
3
|
+
import inquirer from "inquirer"
|
|
4
|
+
const cwd = process.cwd()
|
|
5
|
+
const cwdFolder = cwd.split(path.sep).pop()
|
|
6
|
+
|
|
7
|
+
export default async () => {
|
|
8
|
+
const { projectDirName } = await inquirer.prompt([
|
|
9
|
+
{
|
|
10
|
+
type: 'input',
|
|
11
|
+
name: 'projectDirName',
|
|
12
|
+
message: 'Enter the project name',
|
|
13
|
+
default: cwdFolder
|
|
14
|
+
}
|
|
15
|
+
])
|
|
16
|
+
|
|
17
|
+
let projectDir = cwd
|
|
18
|
+
|
|
19
|
+
if (projectDirName !== cwdFolder) {
|
|
20
|
+
projectDir = path.join(cwd, projectDirName);
|
|
21
|
+
if (fs.existsSync(projectDir)) {
|
|
22
|
+
const { proceed } = await inquirer.prompt([
|
|
23
|
+
{
|
|
24
|
+
type: "confirm",
|
|
25
|
+
name: 'proceed',
|
|
26
|
+
message: "The directory already exists, do you want to overwrite it?",
|
|
27
|
+
default: cwdFolder
|
|
28
|
+
}
|
|
29
|
+
])
|
|
30
|
+
if (!proceed) {
|
|
31
|
+
console.log('Project creation canceled.');
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
cwd: projectDir,
|
|
39
|
+
diraname: path.basename(projectDir),
|
|
40
|
+
isCurrentDir: projectDirName === cwdFolder
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import inquirer from "inquirer"
|
|
2
|
+
import makeProjectDirectory from "./makeProjectDirectory.js"
|
|
3
|
+
import fs from "fs-extra"
|
|
4
|
+
import path from "path"
|
|
5
|
+
const cwd = process.cwd()
|
|
6
|
+
const cwdFolder = cwd.split(path.sep).pop()
|
|
7
|
+
|
|
8
|
+
const makeProjectInformation = async () => {
|
|
9
|
+
const projectDir = await makeProjectDirectory()
|
|
10
|
+
const information = await inquirer.prompt([
|
|
11
|
+
{
|
|
12
|
+
type: 'list',
|
|
13
|
+
name: 'template',
|
|
14
|
+
message: 'Select a template',
|
|
15
|
+
choices: ['typescript', 'javascript', 'react with typescript', 'react with javascript'],
|
|
16
|
+
default: 'typeScript'
|
|
17
|
+
},
|
|
18
|
+
])
|
|
19
|
+
|
|
20
|
+
if (projectDir.diraname !== cwdFolder) {
|
|
21
|
+
fs.removeSync(projectDir.cwd)
|
|
22
|
+
fs.mkdirSync(projectDir.cwd)
|
|
23
|
+
}
|
|
24
|
+
information.entry = "index"
|
|
25
|
+
information.rootdir = "src"
|
|
26
|
+
|
|
27
|
+
switch (information.template) {
|
|
28
|
+
case "typescript":
|
|
29
|
+
information.entry = information.entry + ".ts"
|
|
30
|
+
break;
|
|
31
|
+
case "javascript":
|
|
32
|
+
information.entry = information.entry + ".js"
|
|
33
|
+
break;
|
|
34
|
+
case "react with typescript":
|
|
35
|
+
information.entry = information.entry + ".tsx"
|
|
36
|
+
break;
|
|
37
|
+
case "react with javascript":
|
|
38
|
+
information.entry = information.entry + ".jsx"
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
fs.mkdirSync(path.join(projectDir.cwd, information.rootdir))
|
|
43
|
+
|
|
44
|
+
/*
|
|
45
|
+
{
|
|
46
|
+
port: 3000,
|
|
47
|
+
outdir: "pack",
|
|
48
|
+
cwd: 'C:\xampp\htdocs\makepack\asd',
|
|
49
|
+
diraname: 'asd',
|
|
50
|
+
isCurrentDir: false,
|
|
51
|
+
template: 'typescript',
|
|
52
|
+
rootdir: 'src',
|
|
53
|
+
entry: 'index'
|
|
54
|
+
}
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
port: 3000,
|
|
59
|
+
outdir: "pack",
|
|
60
|
+
rootdir: "src",
|
|
61
|
+
...projectDir,
|
|
62
|
+
...information
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default makeProjectInformation
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import inquirer from 'inquirer'
|
|
2
1
|
import esbuild from 'esbuild';
|
|
3
2
|
import fs from 'fs-extra';
|
|
4
3
|
import path from 'path';
|
|
5
4
|
import { glob } from 'glob'
|
|
6
5
|
import ts from 'typescript'
|
|
6
|
+
import { execSync, logLoader } from '../helpers';
|
|
7
7
|
|
|
8
8
|
const pack = async (args) => {
|
|
9
|
+
args.outdir = 'pack'
|
|
9
10
|
try {
|
|
10
11
|
fs.removeSync(path.join(process.cwd(), args.outdir));
|
|
11
12
|
} catch (err) { }
|
|
12
13
|
|
|
13
|
-
const files = await glob('
|
|
14
|
+
const files = await glob('src/**/*.{tsx,ts,js,jsx}') || []
|
|
14
15
|
const entries = files.map(entry => path.join(process.cwd(), entry))
|
|
16
|
+
let loader = logLoader("Generating a production build for the package...")
|
|
15
17
|
|
|
16
|
-
esbuild.
|
|
18
|
+
esbuild.buildSync({
|
|
17
19
|
entryPoints: entries,
|
|
18
20
|
outdir: path.join(process.cwd(), args.outdir),
|
|
19
21
|
minify: true,
|
|
@@ -21,13 +23,18 @@ const pack = async (args) => {
|
|
|
21
23
|
format: "esm",
|
|
22
24
|
platform: 'node',
|
|
23
25
|
loader: { '.ts': 'ts' },
|
|
24
|
-
tsconfig: path.join(process.cwd(), 'tsconfig.json'),
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
// tsconfig: path.join(process.cwd(), 'tsconfig.json'),
|
|
27
|
+
// tsconfigRaw: `{
|
|
28
|
+
// "compilerOptions": {
|
|
29
|
+
// "declaration": true,
|
|
30
|
+
// "emitDeclarationOnly": true,
|
|
31
|
+
// "jsx": "react",
|
|
32
|
+
// "module": "esnext",
|
|
33
|
+
// }
|
|
34
|
+
// }`
|
|
35
|
+
})
|
|
36
|
+
loader.stop()
|
|
37
|
+
loader = logLoader("🔄 Generating TypeScript declarations...")
|
|
31
38
|
const options = {
|
|
32
39
|
declaration: true,
|
|
33
40
|
emitDeclarationOnly: true,
|
|
@@ -53,8 +60,23 @@ const pack = async (args) => {
|
|
|
53
60
|
}
|
|
54
61
|
});
|
|
55
62
|
} else {
|
|
56
|
-
console.log('
|
|
63
|
+
console.log('✅ TypeScript declaration files generated successfully!');
|
|
57
64
|
}
|
|
65
|
+
loader.stop()
|
|
66
|
+
|
|
67
|
+
fs.copyFileSync(path.join(process.cwd(), '/package.json'), path.join(process.cwd(), args.outdir, `/package.json`))
|
|
68
|
+
console.log('✅ Production build generated successfully! The package is ready for deployment.');
|
|
69
|
+
|
|
70
|
+
if (args.publish) {
|
|
71
|
+
console.log("Publishing the production build to the npm repository...")
|
|
72
|
+
execSync(`npm publish`, {
|
|
73
|
+
cwd: path.join(process.cwd(), args.outdir)
|
|
74
|
+
})
|
|
75
|
+
} else {
|
|
76
|
+
console.log(`To publish your package:\n1. Navigate to the ${args.outdir} directory:\ncd ./${args.outdir}\n2. Publish the package to npm:\nnpm publish\nYour package is ready to share with the world! 🚀`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
58
80
|
}
|
|
59
81
|
|
|
60
82
|
export default pack
|
package/src/actions/serve.js
CHANGED
|
@@ -1,19 +1,33 @@
|
|
|
1
1
|
import inquirer from 'inquirer'
|
|
2
|
+
import fs from 'fs-extra'
|
|
3
|
+
import path from 'path'
|
|
2
4
|
import { createServer as createViteServer } from 'vite';
|
|
3
5
|
import express from 'express';
|
|
6
|
+
import { glob } from 'glob'
|
|
4
7
|
|
|
5
8
|
const app = express();
|
|
6
9
|
|
|
7
10
|
const serve = async (args) => {
|
|
8
11
|
|
|
9
12
|
if (args.entry === undefined) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
const indexes = await glob('src/index.{ts,js,tsx,jsx}', {
|
|
14
|
+
cwd: process.cwd()
|
|
15
|
+
})
|
|
16
|
+
if (!indexes.length) {
|
|
17
|
+
let { entry } = await inquirer.prompt([{
|
|
18
|
+
type: 'input',
|
|
19
|
+
name: 'entry',
|
|
20
|
+
message: 'Enter the root file',
|
|
21
|
+
}]);
|
|
22
|
+
entry = "src/" + entry
|
|
23
|
+
|
|
24
|
+
if (!fs.existsSync(path.join(process.cwd(), entry))) {
|
|
25
|
+
throw new Error(`invalid entry: ${entry}`);
|
|
26
|
+
}
|
|
27
|
+
args.entry = entry;
|
|
28
|
+
} else {
|
|
29
|
+
args.entry = indexes[0];
|
|
30
|
+
}
|
|
17
31
|
}
|
|
18
32
|
|
|
19
33
|
let template = `
|
package/src/helpers.js
CHANGED
|
@@ -2,9 +2,8 @@ import child_process from 'child_process'
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import { fileURLToPath } from 'url'
|
|
5
|
-
|
|
6
5
|
export const packageDir = process.cwd() + "/node_modules/xanos"
|
|
7
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
6
|
+
export const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
8
7
|
|
|
9
8
|
|
|
10
9
|
export const logLoader = (message = "") => {
|
|
@@ -57,4 +56,5 @@ export const packageJson = () => {
|
|
|
57
56
|
} catch (error) {
|
|
58
57
|
console.error('Error reading package.json', error);
|
|
59
58
|
}
|
|
60
|
-
}
|
|
59
|
+
}
|
|
60
|
+
|
package/src/index.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
import { Command } from "commander";
|
|
4
4
|
import serve from "./actions/serve.js";
|
|
5
|
-
import
|
|
6
|
-
import create from "./actions/create.js";
|
|
5
|
+
import pack from "./actions/pack.js";
|
|
6
|
+
import create from "./actions/create/index.js";
|
|
7
|
+
|
|
7
8
|
const program = new Command();
|
|
8
9
|
|
|
9
10
|
program.name("Make Pack").description("Usages");
|
|
@@ -21,10 +22,9 @@ program
|
|
|
21
22
|
.action(serve);
|
|
22
23
|
|
|
23
24
|
program
|
|
24
|
-
.command("
|
|
25
|
-
.option("-e, --entry <type>", "
|
|
26
|
-
.option("-
|
|
27
|
-
.description("
|
|
28
|
-
.action(
|
|
29
|
-
|
|
25
|
+
.command("pack")
|
|
26
|
+
.option("-e, --entry <type>", "Entry file or directory (you can use a glob pattern)", "src/**/*.{tsx,ts,js,jsx}")
|
|
27
|
+
.option("-p, --publish", "Publish the project to the npm repository", false)
|
|
28
|
+
.description("Build the project and optionally publish it to the npm repository")
|
|
29
|
+
.action(pack);
|
|
30
30
|
program.parse();
|
package/index.html
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<meta charset="UTF-8" />
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
-
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
|
8
|
-
<title>Playground</title>
|
|
9
|
-
</head>
|
|
10
|
-
|
|
11
|
-
<body>
|
|
12
|
-
<div id="root"></div>
|
|
13
|
-
<script type="module" src="./index.tsx"></script>
|
|
14
|
-
</body>
|
|
15
|
-
|
|
16
|
-
</html>
|
package/src/actions/create.js
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import path from "path"
|
|
2
|
-
import fs from "fs-extra"
|
|
3
|
-
import inquirer from "inquirer"
|
|
4
|
-
import { execSync, logLoader } from "../helpers.js"
|
|
5
|
-
const cwd = process.cwd()
|
|
6
|
-
const cwdFolder = cwd.split(path.sep).pop()
|
|
7
|
-
|
|
8
|
-
const create = async (args) => {
|
|
9
|
-
const { projectDirName } = await inquirer.prompt([
|
|
10
|
-
{
|
|
11
|
-
type: 'input',
|
|
12
|
-
name: 'projectDirName',
|
|
13
|
-
message: 'Enter the project name',
|
|
14
|
-
default: cwdFolder
|
|
15
|
-
}
|
|
16
|
-
])
|
|
17
|
-
|
|
18
|
-
let projectDir = cwd
|
|
19
|
-
|
|
20
|
-
if (projectDirName !== cwdFolder) {
|
|
21
|
-
projectDir = path.join(cwd, projectDirName);
|
|
22
|
-
if (fs.existsSync(projectDir)) {
|
|
23
|
-
const { proceed } = await inquirer.prompt([
|
|
24
|
-
{
|
|
25
|
-
type: "confirm",
|
|
26
|
-
name: 'proceed',
|
|
27
|
-
message: "The directory already exists, do you want to overwrite it?",
|
|
28
|
-
default: cwdFolder
|
|
29
|
-
}
|
|
30
|
-
])
|
|
31
|
-
if (!proceed) {
|
|
32
|
-
console.log('Project creation canceled.');
|
|
33
|
-
return
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
let { template } = await inquirer.prompt([
|
|
40
|
-
{
|
|
41
|
-
type: 'list',
|
|
42
|
-
name: 'template',
|
|
43
|
-
message: 'Select a template',
|
|
44
|
-
choices: ['typescript', 'javascript', 'react with typescript', 'react with javascript'],
|
|
45
|
-
default: 'typeScript'
|
|
46
|
-
}
|
|
47
|
-
])
|
|
48
|
-
|
|
49
|
-
if (projectDirName !== cwdFolder) {
|
|
50
|
-
fs.removeSync(projectDir)
|
|
51
|
-
fs.mkdirSync(projectDir)
|
|
52
|
-
}
|
|
53
|
-
let dependencies = {}
|
|
54
|
-
let devDependencies = {
|
|
55
|
-
// "make-pack": "@latest"
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (template.includes("react")) {
|
|
59
|
-
dependencies = {
|
|
60
|
-
"react": "^17.0.2",
|
|
61
|
-
"react-dom": "^17.0.2"
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (template.includes("typescript")) {
|
|
66
|
-
devDependencies["typescript"] = "^4.4.2"
|
|
67
|
-
devDependencies["@types/react"] = "^18.3.12"
|
|
68
|
-
devDependencies["@types/react-dom"] = "^18.3.1"
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
let loader = logLoader("Creating project...")
|
|
72
|
-
fs.mkdirSync(path.join(projectDir, "src"))
|
|
73
|
-
fs.writeFileSync(path.join(projectDir, "package.json"), JSON.stringify({
|
|
74
|
-
name: projectDirName,
|
|
75
|
-
version: "1.0.0",
|
|
76
|
-
description: "",
|
|
77
|
-
main: "index.js",
|
|
78
|
-
scripts: {
|
|
79
|
-
"start": "makepack serve",
|
|
80
|
-
"build": "makepack build",
|
|
81
|
-
},
|
|
82
|
-
dependencies,
|
|
83
|
-
devDependencies,
|
|
84
|
-
keywords: [],
|
|
85
|
-
}, null, 2), "utf-8")
|
|
86
|
-
|
|
87
|
-
switch (template) {
|
|
88
|
-
case "typescript":
|
|
89
|
-
fs.writeFileSync(path.join(projectDir, "src/index.ts"), `console.log("Hello, World!")`, "utf-8")
|
|
90
|
-
break;
|
|
91
|
-
case "react with typescript":
|
|
92
|
-
fs.writeFileSync(path.join(projectDir, "src/index.tsx"), `import React from 'react';
|
|
93
|
-
|
|
94
|
-
const App: React.FC = () => {
|
|
95
|
-
return (
|
|
96
|
-
<div style={{ textAlign: 'center', marginTop: '50px' }}>
|
|
97
|
-
<h1>Welcome to React Typescript with make-pack CLI!</h1>
|
|
98
|
-
<p>Edit <code>index.tsx</code> and save to reload.</p>
|
|
99
|
-
<a
|
|
100
|
-
href="https://reactjs.org"
|
|
101
|
-
target="_blank"
|
|
102
|
-
rel="noopener noreferrer"
|
|
103
|
-
style={{ color: '#61dafb', textDecoration: 'none' }}
|
|
104
|
-
>
|
|
105
|
-
Learn React
|
|
106
|
-
</a>
|
|
107
|
-
</div>
|
|
108
|
-
);
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
export default App;
|
|
112
|
-
`)
|
|
113
|
-
|
|
114
|
-
break;
|
|
115
|
-
case "javascript":
|
|
116
|
-
fs.writeFileSync(path.join(projectDir, "src/index.js"), `console.log("Hello, World!")`, "utf-8")
|
|
117
|
-
break;
|
|
118
|
-
case "react with javascript":
|
|
119
|
-
fs.writeFileSync(path.join(projectDir, "src/index.jsx"), `import React from 'react';
|
|
120
|
-
|
|
121
|
-
const App: React.FC = () => {
|
|
122
|
-
return (
|
|
123
|
-
<div style={{ textAlign: 'center', marginTop: '50px' }}>
|
|
124
|
-
<h1>Welcome to React JS with make-pack CLI!</h1>
|
|
125
|
-
<p>Edit <code>index.jsx</code> and save to reload.</p>
|
|
126
|
-
<a
|
|
127
|
-
href="https://reactjs.org"
|
|
128
|
-
target="_blank"
|
|
129
|
-
rel="noopener noreferrer"
|
|
130
|
-
style={{ color: '#61dafb', textDecoration: 'none' }}
|
|
131
|
-
>
|
|
132
|
-
Learn React
|
|
133
|
-
</a>
|
|
134
|
-
</div>
|
|
135
|
-
);
|
|
136
|
-
};
|
|
137
|
-
export default App;
|
|
138
|
-
`)
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// generate tsconfig.json
|
|
143
|
-
if (template.includes("typescript")) {
|
|
144
|
-
let config = {
|
|
145
|
-
"compilerOptions": {
|
|
146
|
-
"target": "es5",
|
|
147
|
-
"lib": ["dom", "dom.iterable", "esnext"],
|
|
148
|
-
"allowJs": true,
|
|
149
|
-
"skipLibCheck": true,
|
|
150
|
-
"esModuleInterop": true,
|
|
151
|
-
"allowSyntheticDefaultImports": true,
|
|
152
|
-
"strict": true,
|
|
153
|
-
"forceConsistentCasingInFileNames": true,
|
|
154
|
-
"module": "esnext",
|
|
155
|
-
"moduleResolution": "node",
|
|
156
|
-
"resolveJsonModule": true,
|
|
157
|
-
"isolatedModules": true,
|
|
158
|
-
"noEmit": true,
|
|
159
|
-
},
|
|
160
|
-
"include": ["src"]
|
|
161
|
-
}
|
|
162
|
-
// config for react
|
|
163
|
-
if (template.includes("react")) {
|
|
164
|
-
config.compilerOptions["jsx"] = "react-jsx"
|
|
165
|
-
config.compilerOptions["jsxImportSource"] = "react"
|
|
166
|
-
}
|
|
167
|
-
fs.writeFileSync(path.join(projectDir, "tsconfig.json"), JSON.stringify(config, null, 2), "utf-8")
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// generate .gitignore
|
|
171
|
-
fs.writeFileSync(path.join(projectDir, ".gitignore"), "node_modules\n", "utf-8")
|
|
172
|
-
|
|
173
|
-
loader.stop("")
|
|
174
|
-
|
|
175
|
-
loader = logLoader("Installing dependencies...")
|
|
176
|
-
execSync("npm install", {
|
|
177
|
-
cwd: projectDir,
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
loader.stop("Project setup complete!")
|
|
181
|
-
|
|
182
|
-
console.log(`
|
|
183
|
-
|
|
184
|
-
To start working with your project:
|
|
185
|
-
1. Navigate to your project directory:
|
|
186
|
-
cd ${projectDirName}
|
|
187
|
-
|
|
188
|
-
2. Run the development server:
|
|
189
|
-
makepack serve
|
|
190
|
-
|
|
191
|
-
Enjoy your new project! 😊`);
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
export default create
|
package/test/browser.js
DELETED
package/test/client.tsx
DELETED
package/test/index.ts
DELETED
package/test/math.ts
DELETED
|
File without changes
|
package/tsconfig.json
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"declaration": true,
|
|
4
|
-
"emitDeclarationOnly": true,
|
|
5
|
-
"jsx": "react",
|
|
6
|
-
"module": "esnext",
|
|
7
|
-
"lib": [
|
|
8
|
-
"dom",
|
|
9
|
-
"esnext"
|
|
10
|
-
],
|
|
11
|
-
"target": "ESNext",
|
|
12
|
-
"importHelpers": true,
|
|
13
|
-
"sourceMap": true,
|
|
14
|
-
"strict": true,
|
|
15
|
-
"noFallthroughCasesInSwitch": true,
|
|
16
|
-
"noUnusedLocals": true,
|
|
17
|
-
"noUnusedParameters": true,
|
|
18
|
-
"moduleResolution": "node",
|
|
19
|
-
"esModuleInterop": true,
|
|
20
|
-
"skipLibCheck": true,
|
|
21
|
-
"forceConsistentCasingInFileNames": true,
|
|
22
|
-
},
|
|
23
|
-
"include": [
|
|
24
|
-
"test/**/*"
|
|
25
|
-
],
|
|
26
|
-
"exclude": [
|
|
27
|
-
"node_modules"
|
|
28
|
-
]
|
|
29
|
-
}
|