makepack 1.0.5 → 1.0.6
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 +7 -7
- package/package.json +1 -1
- package/src/actions/create/files/package-json.js +1 -1
- package/src/actions/create/files/project-ts.js +1 -1
- package/src/actions/create/files/{project-react-ts.js → serve.js} +10 -4
- package/src/actions/create/makeFiles.js +4 -8
- package/src/actions/create/makeProjectInformation.js +2 -3
- package/src/actions/pack.js +1 -1
- package/src/actions/serve.js +10 -11
- package/src/index.js +4 -3
- package/src/actions/create/files/project-react-js.js +0 -31
package/README.md
CHANGED
|
@@ -46,11 +46,11 @@ makepack serve [options]
|
|
|
46
46
|
|
|
47
47
|
#### Options
|
|
48
48
|
|
|
49
|
-
- `-p, --port <
|
|
50
|
-
_Port number_ (default is `
|
|
49
|
+
- `-p, --port <number>`
|
|
50
|
+
_Port number_ (optional) (default is `5000`).
|
|
51
51
|
|
|
52
|
-
- `-e, --
|
|
53
|
-
|
|
52
|
+
- `-e, --root <file>`
|
|
53
|
+
_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.
|
|
54
54
|
|
|
55
55
|
#### Description
|
|
56
56
|
|
|
@@ -59,7 +59,7 @@ makepack serve [options]
|
|
|
59
59
|
Example:
|
|
60
60
|
|
|
61
61
|
```bash
|
|
62
|
-
makepack serve --port 4000 --
|
|
62
|
+
makepack serve --port 4000 --root src/index.ts
|
|
63
63
|
```
|
|
64
64
|
|
|
65
65
|
---
|
|
@@ -76,7 +76,7 @@ makepack pack [options]
|
|
|
76
76
|
|
|
77
77
|
#### Options
|
|
78
78
|
|
|
79
|
-
- `-e, --entry <
|
|
79
|
+
- `-e, --entry <file>`
|
|
80
80
|
_Entry file or directory_ (default is `src/**/*.{tsx,ts,js,jsx}`).
|
|
81
81
|
Specify the entry file or use a glob pattern to select the files to include in your library.
|
|
82
82
|
|
|
@@ -110,7 +110,7 @@ makepack create
|
|
|
110
110
|
2. Start the server for development:
|
|
111
111
|
|
|
112
112
|
```bash
|
|
113
|
-
makepack serve --port 4000 --
|
|
113
|
+
makepack serve --port 4000 --root index.tsx
|
|
114
114
|
```
|
|
115
115
|
|
|
116
116
|
3. Once you're ready to build and publish your library:
|
package/package.json
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
export default args => {
|
|
2
|
+
let ext = ".jsx"
|
|
3
|
+
switch (args.template) {
|
|
4
|
+
case "react with typescript":
|
|
5
|
+
ext = ".tsx"
|
|
6
|
+
}
|
|
7
|
+
|
|
2
8
|
const content = `import React from 'react';
|
|
3
9
|
import { createRoot } from 'react-dom/client';
|
|
4
10
|
|
|
5
|
-
const App
|
|
11
|
+
const App = () => {
|
|
6
12
|
return (
|
|
7
|
-
<div style={{ textAlign: 'center', marginTop: '50px' }}>
|
|
8
|
-
<h1>Welcome to
|
|
13
|
+
<div style={{fontFamily: 'vardana', textAlign: 'center', marginTop: '50px' }}>
|
|
14
|
+
<h1>Welcome to makepack CLI!</h1>
|
|
9
15
|
<p>Edit <code>index.tsx</code> and save to reload.</p>
|
|
10
16
|
<a
|
|
11
17
|
href="https://reactjs.org"
|
|
@@ -26,6 +32,6 @@ if (rootEle) {
|
|
|
26
32
|
`
|
|
27
33
|
return {
|
|
28
34
|
content,
|
|
29
|
-
filename:
|
|
35
|
+
filename: `serve${ext}`
|
|
30
36
|
}
|
|
31
37
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// import makepack from "./files/makepack.js";
|
|
2
2
|
import packageJson from "./files/package-json.js";
|
|
3
3
|
import gitignore from "./files/gitignore.js";
|
|
4
|
+
import serve from "./files/serve.js";
|
|
4
5
|
import tsconfig from "./files/tsconfig.js";
|
|
5
6
|
import projectJs from "./files/project-js.js";
|
|
6
7
|
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
8
|
|
|
10
9
|
import fs from "fs-extra"
|
|
11
10
|
import path from "path"
|
|
@@ -14,20 +13,17 @@ export default async (args) => {
|
|
|
14
13
|
const files = [
|
|
15
14
|
packageJson(args),
|
|
16
15
|
gitignore(args),
|
|
16
|
+
serve(args),
|
|
17
17
|
];
|
|
18
18
|
|
|
19
19
|
switch (args.template) {
|
|
20
20
|
case "typescript":
|
|
21
|
+
case "react with typescript":
|
|
21
22
|
files.push(projectTs(args))
|
|
22
23
|
break;
|
|
23
24
|
case "javascript":
|
|
24
|
-
files.push(projectJs(args))
|
|
25
|
-
break;
|
|
26
|
-
case "react with typescript":
|
|
27
|
-
files.push(projectReactTs(args))
|
|
28
|
-
break;
|
|
29
25
|
case "react with javascript":
|
|
30
|
-
files.push(
|
|
26
|
+
files.push(projectJs(args))
|
|
31
27
|
break;
|
|
32
28
|
}
|
|
33
29
|
|
|
@@ -14,7 +14,7 @@ const makeProjectInformation = async () => {
|
|
|
14
14
|
message: 'Select a template',
|
|
15
15
|
choices: ['typescript', 'javascript', 'react with typescript', 'react with javascript'],
|
|
16
16
|
default: 'typeScript'
|
|
17
|
-
}
|
|
17
|
+
}
|
|
18
18
|
])
|
|
19
19
|
|
|
20
20
|
if (projectDir.diraname !== cwdFolder) {
|
|
@@ -55,9 +55,8 @@ const makeProjectInformation = async () => {
|
|
|
55
55
|
*/
|
|
56
56
|
|
|
57
57
|
return {
|
|
58
|
-
port: 3000,
|
|
58
|
+
// port: 3000,
|
|
59
59
|
outdir: "pack",
|
|
60
|
-
rootdir: "src",
|
|
61
60
|
...projectDir,
|
|
62
61
|
...information
|
|
63
62
|
}
|
package/src/actions/pack.js
CHANGED
|
@@ -20,7 +20,7 @@ const pack = async (args) => {
|
|
|
20
20
|
outdir: path.join(process.cwd(), args.outdir),
|
|
21
21
|
minify: true,
|
|
22
22
|
sourcemap: true,
|
|
23
|
-
format: "
|
|
23
|
+
format: "esm",
|
|
24
24
|
platform: 'node',
|
|
25
25
|
loader: { '.ts': 'ts' },
|
|
26
26
|
// tsconfig: path.join(process.cwd(), 'tsconfig.json'),
|
package/src/actions/serve.js
CHANGED
|
@@ -9,24 +9,23 @@ const app = express();
|
|
|
9
9
|
|
|
10
10
|
const serve = async (args) => {
|
|
11
11
|
|
|
12
|
-
if (args.
|
|
13
|
-
const
|
|
12
|
+
if (args.root === undefined) {
|
|
13
|
+
const serveFile = await glob('serve.{ts,js,tsx,jsx}', {
|
|
14
14
|
cwd: process.cwd()
|
|
15
15
|
})
|
|
16
|
-
if (!
|
|
17
|
-
let {
|
|
16
|
+
if (!serveFile.length) {
|
|
17
|
+
let { root } = await inquirer.prompt([{
|
|
18
18
|
type: 'input',
|
|
19
|
-
name: '
|
|
19
|
+
name: 'root',
|
|
20
20
|
message: 'Enter the root file',
|
|
21
21
|
}]);
|
|
22
|
-
entry = "src/" + entry
|
|
23
22
|
|
|
24
|
-
if (!fs.existsSync(path.join(process.cwd(),
|
|
25
|
-
throw new Error(`invalid
|
|
23
|
+
if (!fs.existsSync(path.join(process.cwd(), root))) {
|
|
24
|
+
throw new Error(`invalid root: ${root}`);
|
|
26
25
|
}
|
|
27
|
-
args.
|
|
26
|
+
args.root = root;
|
|
28
27
|
} else {
|
|
29
|
-
args.
|
|
28
|
+
args.root = serveFile[0];
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
|
|
@@ -39,7 +38,7 @@ const serve = async (args) => {
|
|
|
39
38
|
</head>
|
|
40
39
|
<body>
|
|
41
40
|
<div id="root"></div>
|
|
42
|
-
<script type="module" src="${args.
|
|
41
|
+
<script type="module" src="${args.root}"></script>
|
|
43
42
|
</body>
|
|
44
43
|
</html>
|
|
45
44
|
`;
|
package/src/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { Command } from "commander";
|
|
|
4
4
|
import serve from "./actions/serve.js";
|
|
5
5
|
import pack from "./actions/pack.js";
|
|
6
6
|
import create from "./actions/create/index.js";
|
|
7
|
+
import path from 'path'
|
|
7
8
|
|
|
8
9
|
const program = new Command();
|
|
9
10
|
|
|
@@ -16,14 +17,14 @@ program
|
|
|
16
17
|
|
|
17
18
|
program
|
|
18
19
|
.command("serve")
|
|
19
|
-
.option("-p, --port <
|
|
20
|
-
.option("-
|
|
20
|
+
.option("-p, --port <number>", "Port number", "5000")
|
|
21
|
+
.option("-r, --root <file>", "root file", path.join(process.cwd(), "/serve"))
|
|
21
22
|
.description("Start the server")
|
|
22
23
|
.action(serve);
|
|
23
24
|
|
|
24
25
|
program
|
|
25
26
|
.command("pack")
|
|
26
|
-
.option("-e, --entry <
|
|
27
|
+
.option("-e, --entry <file>", "Entry file or directory (you can use a glob pattern)", "src/**/*.{tsx,ts,js,jsx}")
|
|
27
28
|
.option("-p, --publish", "Publish the project to the npm repository", false)
|
|
28
29
|
.description("Build the project and optionally publish it to the npm repository")
|
|
29
30
|
.action(pack);
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export default (args) => {
|
|
2
|
-
const content = `import React from 'react';
|
|
3
|
-
import { createRoot } from 'react-dom/client';
|
|
4
|
-
|
|
5
|
-
const App = () => {
|
|
6
|
-
return (
|
|
7
|
-
<div style={{ textAlign: 'center', marginTop: '50px' }}>
|
|
8
|
-
<h1>Welcome to React JS with makepack CLI!</h1>
|
|
9
|
-
<p>Edit <code>index.tsx</code> and save to reload.</p>
|
|
10
|
-
<a
|
|
11
|
-
href="https://reactjs.org"
|
|
12
|
-
target="_blank"
|
|
13
|
-
rel="noopener noreferrer"
|
|
14
|
-
style={{ color: '#61dafb', textDecoration: 'none' }}
|
|
15
|
-
>
|
|
16
|
-
Learn React
|
|
17
|
-
</a>
|
|
18
|
-
</div>
|
|
19
|
-
);
|
|
20
|
-
};
|
|
21
|
-
const rootEle = document.getElementById('root')
|
|
22
|
-
if (rootEle) {
|
|
23
|
-
const root = createRoot(rootEle);
|
|
24
|
-
root.render(<App />);
|
|
25
|
-
}
|
|
26
|
-
`
|
|
27
|
-
return {
|
|
28
|
-
content,
|
|
29
|
-
filename: `${args.rootdir}/${args.entry}`
|
|
30
|
-
}
|
|
31
|
-
}
|