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 CHANGED
@@ -46,11 +46,11 @@ makepack serve [options]
46
46
 
47
47
  #### Options
48
48
 
49
- - `-p, --port <type>`
50
- _Port number_ (default is `3000`).
49
+ - `-p, --port <number>`
50
+ _Port number_ (optional) (default is `5000`).
51
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.
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 --entry src/index.ts
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 <type>`
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 --entry src/index.ts
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,6 +1,6 @@
1
1
  {
2
2
  "name": "makepack",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "type": "module",
5
5
  "description": "A CLI tool to create, build, and manage JavaScript, TypeScript, React, and React-TypeScript libraries for npm projects.",
6
6
  "categories": [
@@ -28,7 +28,7 @@ export default (args) => {
28
28
  scripts: {
29
29
  "start": "makepack serve",
30
30
  "pack": "makepack pack",
31
- "publish": "makepack pack -p",
31
+ "publish:pack": "makepack pack -p",
32
32
  },
33
33
  dependencies,
34
34
  devDependencies,
@@ -3,7 +3,7 @@ export default args => {
3
3
  function add(a: number, b: number): number {
4
4
  return a + b;
5
5
  }
6
- console.log(add(5, 3)); `
6
+ console.log(add(5, 3));`
7
7
  return {
8
8
  content,
9
9
  filename: `${args.rootdir}/${args.entry}`
@@ -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: React.FC = () => {
11
+ const App = () => {
6
12
  return (
7
- <div style={{ textAlign: 'center', marginTop: '50px' }}>
8
- <h1>Welcome to React Typescript with makepack CLI!</h1>
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: `${args.rootdir}/${args.entry}`
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(projectReactJs(args))
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
  }
@@ -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: "cjs",
23
+ format: "esm",
24
24
  platform: 'node',
25
25
  loader: { '.ts': 'ts' },
26
26
  // tsconfig: path.join(process.cwd(), 'tsconfig.json'),
@@ -9,24 +9,23 @@ const app = express();
9
9
 
10
10
  const serve = async (args) => {
11
11
 
12
- if (args.entry === undefined) {
13
- const indexes = await glob('src/index.{ts,js,tsx,jsx}', {
12
+ if (args.root === undefined) {
13
+ const serveFile = await glob('serve.{ts,js,tsx,jsx}', {
14
14
  cwd: process.cwd()
15
15
  })
16
- if (!indexes.length) {
17
- let { entry } = await inquirer.prompt([{
16
+ if (!serveFile.length) {
17
+ let { root } = await inquirer.prompt([{
18
18
  type: 'input',
19
- name: 'entry',
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(), entry))) {
25
- throw new Error(`invalid entry: ${entry}`);
23
+ if (!fs.existsSync(path.join(process.cwd(), root))) {
24
+ throw new Error(`invalid root: ${root}`);
26
25
  }
27
- args.entry = entry;
26
+ args.root = root;
28
27
  } else {
29
- args.entry = indexes[0];
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.entry}"></script>
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 <type>", "Port number", "5000")
20
- .option("-e, --entry <type>", "entry file")
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 <type>", "Entry file or directory (you can use a glob pattern)", "src/**/*.{tsx,ts,js,jsx}")
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
- }