makepack 1.6.1 → 1.6.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "makepack",
3
- "version": "1.6.1",
3
+ "version": "1.6.3",
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
  "files": [
@@ -145,9 +145,12 @@ const build = async (args) => {
145
145
  }
146
146
 
147
147
  if (args.declaration) {
148
- pkgjson.types = `index.d.ts`;
148
+ pkgjson.types = `./index.d.ts`;
149
149
  }
150
150
 
151
+ delete pkgjson.scripts
152
+ delete pkgjson.type
153
+
151
154
  fs.writeFileSync(path.join(outdir, 'package.json'), JSON.stringify(pkgjson, null, 2));
152
155
  } else {
153
156
  spinner.fail("package.json not found!");
@@ -0,0 +1,37 @@
1
+ export default async ({ template }) => {
2
+
3
+ let ext = 'jsx'
4
+ if (template === 'react with typescript') {
5
+ ext = 'tsx'
6
+ } else if (template === 'typescript') {
7
+ ext = 'ts'
8
+ }
9
+ else if (template === 'javascript') {
10
+ ext = 'js'
11
+ }
12
+
13
+ const content = `import React from 'react';
14
+ import { createRoot } from 'react-dom/client';
15
+ import ${ext.includes("sx") ? "Count" : "sum"} from './src/index.${ext}';
16
+
17
+ const Main = () => {
18
+ return (
19
+ <div>
20
+ <h1>Welcome to makepack CLI!</h1>
21
+ <p>Edit <code>index.${ext}</code> and save to reload.</p>
22
+ ${ext.includes("sx") ? "<Count />" : "<p>The sum is: {sum(5, 5)}</p>"}
23
+ </div>
24
+ );
25
+ };
26
+
27
+ const rootEle = document.getElementById('root')
28
+ if (rootEle) {
29
+ const root = createRoot(rootEle);
30
+ root.render(<Main />);
31
+ }
32
+ `
33
+ return {
34
+ content,
35
+ filename: `main.${ext.includes('ts') ? "tsx" : 'jsx'}`
36
+ }
37
+ }
@@ -1,10 +1,10 @@
1
1
  export default async () => {
2
2
  const content = `
3
- function add(a, b) {
3
+ function sum(a, b) {
4
4
  return a + b;
5
5
  }
6
6
 
7
- export default add
7
+ export default sum
8
8
  `
9
9
  return {
10
10
  content,
@@ -1,8 +1,7 @@
1
1
  export default async () => {
2
2
  const content = `import React, { useState } from 'react';
3
- import { createRoot } from 'react-dom/client';
4
3
 
5
- const App = () => {
4
+ const Index = () => {
6
5
  const [count, setCount] = useState(0);
7
6
  const increment = () => setCount(prevCount => prevCount + 1);
8
7
  const decrement = () => setCount(prevCount => prevCount - 1);
@@ -43,11 +42,7 @@ const styles = {
43
42
  },
44
43
  };
45
44
 
46
- const rootEle = document.getElementById('root')
47
- if (rootEle) {
48
- const root = createRoot(rootEle);
49
- root.render(<App />);
50
- }
45
+ export default Index;
51
46
  `
52
47
  return {
53
48
  content,
@@ -1,9 +1,9 @@
1
1
  export default async () => {
2
2
  const content = `
3
- function add(a: number, b: number): number {
3
+ function sum(a: number, b: number): number {
4
4
  return a + b;
5
5
  }
6
- export default add`
6
+ export default sum`
7
7
  return {
8
8
  content,
9
9
  filename: `src/index.ts`
@@ -1,8 +1,7 @@
1
1
  export default async () => {
2
2
  const content = `import React, { useState } from 'react';
3
- import { createRoot } from 'react-dom/client';
4
3
 
5
- const App: React.FC = () => {
4
+ const Index: React.FC = () => {
6
5
  const [count, setCount] = useState<number>(0);
7
6
  const increment = (): void => setCount(prevCount => prevCount + 1);
8
7
  const decrement = (): void => setCount(prevCount => prevCount - 1);
@@ -43,11 +42,7 @@ const styles: { [key: string]: React.CSSProperties } = {
43
42
  },
44
43
  };
45
44
 
46
- const rootEle = document.getElementById('root')
47
- if (rootEle) {
48
- const root = createRoot(rootEle);
49
- root.render(<App />);
50
- }
45
+ export default Index;
51
46
  `
52
47
  return {
53
48
  content,
@@ -6,7 +6,7 @@ import projectJs from "./files/project-js.js";
6
6
  import projectJsx from "./files/project-jsx.js";
7
7
  import projectTs from "./files/project-ts.js";
8
8
  import projectTsx from "./files/project-tsx.js";
9
-
9
+ import mainjs from "./files/main.js";
10
10
  import inquirer from 'inquirer'
11
11
  import fs from "fs-extra"
12
12
  import path from "path"
@@ -16,7 +16,8 @@ export default async (info) => {
16
16
  const files = [
17
17
  await packageJson(info),
18
18
  await gitignore(info),
19
- await readmeMd(info)
19
+ await readmeMd(info),
20
+ await mainjs(info),
20
21
  ];
21
22
 
22
23
  switch (info.template) {
@@ -26,9 +26,8 @@ const viteSetup = async (app) => {
26
26
  app.use(vite.middlewares);
27
27
 
28
28
  // exists tsconfig.json in the root directory
29
- const isTs = fs.existsSync(path.resolve(process.cwd(), 'tsconfig.json'))
30
-
31
- let entry = isTs ? '/src/index.ts' : '/src/index.js';
29
+ const isTs = fs.existsSync(path.resolve(process.cwd(), 'main.tsx'))
30
+ let entry = `/main.${isTs ? "tsx" : "jsx"}`
32
31
 
33
32
  app.get('*', async (req, res, next) => {
34
33
  const url = req.originalUrl;