makepack 1.7.21 → 1.7.22

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.
@@ -1,103 +1,103 @@
1
- import fs from 'fs-extra';
2
- import path from 'path';
3
- import ora from 'ora';
4
- import { concolor, logger } from '../../helpers.js';
5
- import bundler from './bundler.js';
6
-
7
- const build = async (args) => {
8
- /*
9
- args options:
10
- --format=both
11
- --bundle=true
12
- --minify=false
13
- --sourcemap=true
14
- --declaration=true
15
- */
16
-
17
- // Convert string "true"/"false" to boolean
18
- const beBool = (f) =>
19
- typeof args[f] === 'string' ? args[f].toLowerCase() === 'true' : !!args[f];
20
-
21
- const outdir = path.join(process.cwd(), '.mpack');
22
- const rootdir = path.join(process.cwd(), 'src');
23
- let entry = '';
24
- let entryts = path.join(rootdir, 'index.ts');
25
- let entryjs = path.join(rootdir, 'index.js');
26
- let entrytsx = path.join(rootdir, 'index.tsx');
27
- let entryjsx = path.join(rootdir, 'index.jsx');
28
-
29
- if (fs.existsSync(entryts)) {
30
- entry = "index.ts";
31
- } else if (fs.existsSync(entryjs)) {
32
- entry = "index.js";
33
- } else if (fs.existsSync(entrytsx)) {
34
- entry = "index.tsx";
35
- } else if (fs.existsSync(entryjsx)) {
36
- entry = "index.jsx";
37
- } else {
38
- throw new Error("No entry file found in src directory. Please provide an index.ts or index.js file.");
39
- }
40
-
41
- args = {
42
- format: args.format || 'both',
43
- bundle: beBool('bundle'),
44
- minify: beBool('minify'),
45
- sourcemap: beBool('sourcemap'),
46
- declaration: beBool('declaration'),
47
- outdir,
48
- rootdir,
49
- entry: path.join(rootdir, entry),
50
- };
51
-
52
- const spinner = ora('✨ Building your package...\n').start();
53
-
54
- try {
55
- // Remove old build folder
56
- await fs.remove(outdir);
57
- await fs.mkdirp(outdir);
58
-
59
- // Run bundler
60
- await bundler(args, spinner);
61
-
62
- spinner.text = '📦 Copying package.json and readme.md files...';
63
-
64
- // Copy package.json
65
- const pkgPath = path.join(process.cwd(), 'package.json');
66
- if (await fs.pathExists(pkgPath)) {
67
- const pkgjson = await fs.readJson(pkgPath);
68
- delete pkgjson.scripts;
69
- delete pkgjson.type;
70
- delete pkgjson.devDependencies;
71
- delete pkgjson.jest;
72
- delete pkgjson.prettier;
73
- delete pkgjson.eslintConfig;
74
- delete pkgjson.vite;
75
- delete pkgjson.rollup;
76
- await fs.writeJson(path.join(outdir, 'package.json'), pkgjson, { spaces: 2 });
77
- } else {
78
- spinner.fail(concolor.red('package.json not found!'));
79
- return;
80
- }
81
-
82
- // Copy readme.md if exists
83
- const readmePath = path.join(process.cwd(), 'readme.md');
84
- if (await fs.pathExists(readmePath)) {
85
- await fs.copy(readmePath, path.join(outdir, 'readme.md'));
86
- }
87
-
88
- spinner.succeed(concolor.bold(concolor.green('Build successfully completed!\n')));
89
- console.log(concolor.bold('To publish your package, run:'));
90
- console.log(
91
- `${concolor.yellow('`npm run release`')} or navigate to \`.mpack\` and run: ${concolor.yellow(
92
- '`npm publish`\n'
93
- )}`
94
- );
95
- } catch (err) {
96
- spinner.fail(concolor.red('Build failed!'));
97
- logger.error(err);
98
- } finally {
99
- spinner.stop();
100
- }
101
- };
102
-
103
- export default build;
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import ora from 'ora';
4
+ import { concolor, logger } from '../../helpers.js';
5
+ import bundler from './bundler.js';
6
+
7
+ const build = async (args) => {
8
+ /*
9
+ args options:
10
+ --format=both
11
+ --bundle=true
12
+ --minify=false
13
+ --sourcemap=true
14
+ --declaration=true
15
+ */
16
+
17
+ // Convert string "true"/"false" to boolean
18
+ const beBool = (f) =>
19
+ typeof args[f] === 'string' ? args[f].toLowerCase() === 'true' : !!args[f];
20
+
21
+ const outdir = path.join(process.cwd(), '.mpack');
22
+ const rootdir = path.join(process.cwd(), 'src');
23
+ let entry = '';
24
+ let entryts = path.join(rootdir, 'index.ts');
25
+ let entryjs = path.join(rootdir, 'index.js');
26
+ let entrytsx = path.join(rootdir, 'index.tsx');
27
+ let entryjsx = path.join(rootdir, 'index.jsx');
28
+
29
+ if (fs.existsSync(entryts)) {
30
+ entry = "index.ts";
31
+ } else if (fs.existsSync(entryjs)) {
32
+ entry = "index.js";
33
+ } else if (fs.existsSync(entrytsx)) {
34
+ entry = "index.tsx";
35
+ } else if (fs.existsSync(entryjsx)) {
36
+ entry = "index.jsx";
37
+ } else {
38
+ throw new Error("No entry file found in src directory. Please provide an index.ts or index.js file.");
39
+ }
40
+
41
+ args = {
42
+ format: args.format || 'both',
43
+ bundle: beBool('bundle'),
44
+ minify: beBool('minify'),
45
+ sourcemap: beBool('sourcemap'),
46
+ declaration: beBool('declaration'),
47
+ outdir,
48
+ rootdir,
49
+ entry: path.join(rootdir, entry),
50
+ };
51
+
52
+ const spinner = ora('✨ Building your package...\n').start();
53
+
54
+ try {
55
+ // Remove old build folder
56
+ await fs.remove(outdir);
57
+ await fs.mkdirp(outdir);
58
+
59
+ // Run bundler
60
+ await bundler(args, spinner);
61
+
62
+ spinner.text = '📦 Copying package.json and readme.md files...';
63
+
64
+ // Copy package.json
65
+ const pkgPath = path.join(process.cwd(), 'package.json');
66
+ if (await fs.pathExists(pkgPath)) {
67
+ const pkgjson = await fs.readJson(pkgPath);
68
+ delete pkgjson.scripts;
69
+ delete pkgjson.type;
70
+ delete pkgjson.devDependencies;
71
+ delete pkgjson.jest;
72
+ delete pkgjson.prettier;
73
+ delete pkgjson.eslintConfig;
74
+ delete pkgjson.vite;
75
+ delete pkgjson.rollup;
76
+ await fs.writeJson(path.join(outdir, 'package.json'), pkgjson, { spaces: 2 });
77
+ } else {
78
+ spinner.fail(concolor.red('package.json not found!'));
79
+ return;
80
+ }
81
+
82
+ // Copy readme.md if exists
83
+ const readmePath = path.join(process.cwd(), 'readme.md');
84
+ if (await fs.pathExists(readmePath)) {
85
+ await fs.copy(readmePath, path.join(outdir, 'readme.md'));
86
+ }
87
+
88
+ spinner.succeed(concolor.bold(concolor.green('Build successfully completed!\n')));
89
+ console.log(concolor.bold('To publish your package, run:'));
90
+ console.log(
91
+ `${concolor.yellow('`npm run release`')} or navigate to \`.mpack\` and run: ${concolor.yellow(
92
+ '`npm publish`\n'
93
+ )}`
94
+ );
95
+ } catch (err) {
96
+ spinner.fail(concolor.red('Build failed!'));
97
+ logger.error(err);
98
+ } finally {
99
+ spinner.stop();
100
+ }
101
+ };
102
+
103
+ export default build;
@@ -1,10 +1,10 @@
1
-
2
- export default async () => {
3
- return {
4
- content: `
5
- node_modules
6
- .mpack
7
- `,
8
- filename: ".gitignore"
9
- }
1
+
2
+ export default async () => {
3
+ return {
4
+ content: `
5
+ node_modules
6
+ .mpack
7
+ `,
8
+ filename: ".gitignore"
9
+ }
10
10
  }
@@ -1,37 +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
- }
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
37
  }
@@ -1,50 +1,50 @@
1
-
2
- export default async (info) => {
3
- let dependencies = {}
4
- let devDependencies = {
5
- "makepack": "latest",
6
- "express": "latest"
7
- }
8
-
9
- if (info.template.includes("react")) {
10
- devDependencies["react"] = "^19.0.0"
11
- devDependencies["react-dom"] = "^19.0.0"
12
- }
13
-
14
- if (info.template.includes("typescript")) {
15
- devDependencies["typescript"] = "^4.4.2"
16
- devDependencies["@types/react"] = "^19.0.2"
17
- devDependencies["@types/react-dom"] = "^19.0.2"
18
- devDependencies["@types/express"] = "latest"
19
- }
20
-
21
- const json = {
22
- name: info.pdir,
23
- version: "1.0.0",
24
- main: `./index.js`,
25
- module: `./index.mjs`,
26
- types: `./index.d.ts`,
27
- description: "",
28
- keywords: [],
29
- sideEffects: false,
30
- scripts: {
31
- "start": "makepack start",
32
- "build": "makepack build",
33
- "release": "makepack release"
34
- },
35
- "exports": {
36
- ".": {
37
- "import": "./index.mjs",
38
- "require": "./index.js",
39
- "types": "./index.d.ts"
40
- }
41
- },
42
- dependencies,
43
- devDependencies
44
- }
45
-
46
- return {
47
- content: JSON.stringify(json, null, 3),
48
- filename: "package.json"
49
- }
1
+
2
+ export default async (info) => {
3
+ let dependencies = {}
4
+ let devDependencies = {
5
+ "makepack": "latest",
6
+ "express": "latest"
7
+ }
8
+
9
+ if (info.template.includes("react")) {
10
+ devDependencies["react"] = "^19.0.0"
11
+ devDependencies["react-dom"] = "^19.0.0"
12
+ }
13
+
14
+ if (info.template.includes("typescript")) {
15
+ devDependencies["typescript"] = "^4.4.2"
16
+ devDependencies["@types/react"] = "^19.0.2"
17
+ devDependencies["@types/react-dom"] = "^19.0.2"
18
+ devDependencies["@types/express"] = "latest"
19
+ }
20
+
21
+ const json = {
22
+ name: info.pdir,
23
+ version: "1.0.0",
24
+ main: `./index.js`,
25
+ module: `./index.mjs`,
26
+ types: `./index.d.ts`,
27
+ description: "",
28
+ keywords: [],
29
+ sideEffects: false,
30
+ scripts: {
31
+ "start": "makepack start",
32
+ "build": "makepack build",
33
+ "release": "makepack release"
34
+ },
35
+ "exports": {
36
+ ".": {
37
+ "import": "./index.mjs",
38
+ "require": "./index.js",
39
+ "types": "./index.d.ts"
40
+ }
41
+ },
42
+ dependencies,
43
+ devDependencies
44
+ }
45
+
46
+ return {
47
+ content: JSON.stringify(json, null, 3),
48
+ filename: "package.json"
49
+ }
50
50
  }
@@ -1,13 +1,13 @@
1
- export default async () => {
2
- const content = `
3
- function sum(a, b) {
4
- return a + b;
5
- }
6
-
7
- export default sum
8
- `
9
- return {
10
- content,
11
- filename: `src/index.js`
12
- }
1
+ export default async () => {
2
+ const content = `
3
+ function sum(a, b) {
4
+ return a + b;
5
+ }
6
+
7
+ export default sum
8
+ `
9
+ return {
10
+ content,
11
+ filename: `src/index.js`
12
+ }
13
13
  }
@@ -1,51 +1,51 @@
1
- export default async () => {
2
- const content = `import React, { useState } from 'react';
3
-
4
- const Index = () => {
5
- const [count, setCount] = useState(0);
6
- const increment = () => setCount(prevCount => prevCount + 1);
7
- const decrement = () => setCount(prevCount => prevCount - 1);
8
- const reset = () => setCount(0);
9
-
10
- return (
11
- <div style={styles.container}>
12
- <h1>Count App</h1>
13
- <div style={styles.counter}>{count}</div>
14
- <div style={styles.buttonContainer}>
15
- <button style={styles.button} onClick={increment}>Increment</button>
16
- <button style={styles.button} onClick={decrement}>Decrement</button>
17
- <button style={styles.button} onClick={reset}>Reset</button>
18
- </div>
19
- </div>
20
- );
21
- };
22
-
23
- const styles = {
24
- container: {
25
- textAlign: 'center',
26
- padding: '20px',
27
- fontFamily: 'Arial, sans-serif'
28
- },
29
- counter: {
30
- fontSize: '2rem',
31
- margin: '20px 0',
32
- },
33
- buttonContainer: {
34
- display: 'flex',
35
- justifyContent: 'center',
36
- gap: '10px',
37
- },
38
- button: {
39
- padding: '10px 20px',
40
- fontSize: '1rem',
41
- cursor: 'pointer',
42
- },
43
- };
44
-
45
- export default Index;
46
- `
47
- return {
48
- content,
49
- filename: `src/index.jsx`
50
- }
1
+ export default async () => {
2
+ const content = `import React, { useState } from 'react';
3
+
4
+ const Index = () => {
5
+ const [count, setCount] = useState(0);
6
+ const increment = () => setCount(prevCount => prevCount + 1);
7
+ const decrement = () => setCount(prevCount => prevCount - 1);
8
+ const reset = () => setCount(0);
9
+
10
+ return (
11
+ <div style={styles.container}>
12
+ <h1>Count App</h1>
13
+ <div style={styles.counter}>{count}</div>
14
+ <div style={styles.buttonContainer}>
15
+ <button style={styles.button} onClick={increment}>Increment</button>
16
+ <button style={styles.button} onClick={decrement}>Decrement</button>
17
+ <button style={styles.button} onClick={reset}>Reset</button>
18
+ </div>
19
+ </div>
20
+ );
21
+ };
22
+
23
+ const styles = {
24
+ container: {
25
+ textAlign: 'center',
26
+ padding: '20px',
27
+ fontFamily: 'Arial, sans-serif'
28
+ },
29
+ counter: {
30
+ fontSize: '2rem',
31
+ margin: '20px 0',
32
+ },
33
+ buttonContainer: {
34
+ display: 'flex',
35
+ justifyContent: 'center',
36
+ gap: '10px',
37
+ },
38
+ button: {
39
+ padding: '10px 20px',
40
+ fontSize: '1rem',
41
+ cursor: 'pointer',
42
+ },
43
+ };
44
+
45
+ export default Index;
46
+ `
47
+ return {
48
+ content,
49
+ filename: `src/index.jsx`
50
+ }
51
51
  }
@@ -1,11 +1,11 @@
1
- export default async () => {
2
- const content = `
3
- function sum(a: number, b: number): number {
4
- return a + b;
5
- }
6
- export default sum`
7
- return {
8
- content,
9
- filename: `src/index.ts`
10
- }
1
+ export default async () => {
2
+ const content = `
3
+ function sum(a: number, b: number): number {
4
+ return a + b;
5
+ }
6
+ export default sum`
7
+ return {
8
+ content,
9
+ filename: `src/index.ts`
10
+ }
11
11
  }
@@ -1,51 +1,51 @@
1
- export default async () => {
2
- const content = `import React, { useState } from 'react';
3
-
4
- const Index: React.FC = () => {
5
- const [count, setCount] = useState<number>(0);
6
- const increment = (): void => setCount(prevCount => prevCount + 1);
7
- const decrement = (): void => setCount(prevCount => prevCount - 1);
8
- const reset = (): void => setCount(0);
9
-
10
- return (
11
- <div style={styles.container}>
12
- <h1>Count App</h1>
13
- <div style={styles.counter}>{count}</div>
14
- <div style={styles.buttonContainer}>
15
- <button style={styles.button} onClick={increment}>Increment</button>
16
- <button style={styles.button} onClick={decrement}>Decrement</button>
17
- <button style={styles.button} onClick={reset}>Reset</button>
18
- </div>
19
- </div>
20
- );
21
- };
22
-
23
- const styles: { [key: string]: React.CSSProperties } = {
24
- container: {
25
- textAlign: 'center',
26
- padding: '20px',
27
- fontFamily: 'Arial, sans-serif',
28
- },
29
- counter: {
30
- fontSize: '2rem',
31
- margin: '20px 0',
32
- },
33
- buttonContainer: {
34
- display: 'flex',
35
- justifyContent: 'center',
36
- gap: '10px',
37
- },
38
- button: {
39
- padding: '10px 20px',
40
- fontSize: '1rem',
41
- cursor: 'pointer',
42
- },
43
- };
44
-
45
- export default Index;
46
- `
47
- return {
48
- content,
49
- filename: `src/index.tsx`
50
- }
1
+ export default async () => {
2
+ const content = `import React, { useState } from 'react';
3
+
4
+ const Index: React.FC = () => {
5
+ const [count, setCount] = useState<number>(0);
6
+ const increment = (): void => setCount(prevCount => prevCount + 1);
7
+ const decrement = (): void => setCount(prevCount => prevCount - 1);
8
+ const reset = (): void => setCount(0);
9
+
10
+ return (
11
+ <div style={styles.container}>
12
+ <h1>Count App</h1>
13
+ <div style={styles.counter}>{count}</div>
14
+ <div style={styles.buttonContainer}>
15
+ <button style={styles.button} onClick={increment}>Increment</button>
16
+ <button style={styles.button} onClick={decrement}>Decrement</button>
17
+ <button style={styles.button} onClick={reset}>Reset</button>
18
+ </div>
19
+ </div>
20
+ );
21
+ };
22
+
23
+ const styles: { [key: string]: React.CSSProperties } = {
24
+ container: {
25
+ textAlign: 'center',
26
+ padding: '20px',
27
+ fontFamily: 'Arial, sans-serif',
28
+ },
29
+ counter: {
30
+ fontSize: '2rem',
31
+ margin: '20px 0',
32
+ },
33
+ buttonContainer: {
34
+ display: 'flex',
35
+ justifyContent: 'center',
36
+ gap: '10px',
37
+ },
38
+ button: {
39
+ padding: '10px 20px',
40
+ fontSize: '1rem',
41
+ cursor: 'pointer',
42
+ },
43
+ };
44
+
45
+ export default Index;
46
+ `
47
+ return {
48
+ content,
49
+ filename: `src/index.tsx`
50
+ }
51
51
  }