makepack 1.7.14 → 1.7.15

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,73 +1,73 @@
1
- // import react from '@vitejs/plugin-react'
2
- import { createServer as createViteServer } from 'vite';
3
- import { loadViteConfig, logger } from '../../helpers.js'
4
- import path from 'path';
5
- import fs from 'fs';
6
-
7
- const viteSetup = async (app) => {
8
- const config = await loadViteConfig() || {}
9
-
10
- // delete .vite directory if exists
11
- const viteDir = path.join(process.cwd(), 'node_modules/.vite');
12
- if (fs.existsSync(viteDir)) {
13
- fs.rmSync(viteDir, { recursive: true, force: true });
14
- }
15
-
16
- const viteConfig = {
17
- ...config,
18
- configFile: false,
19
- root: process.cwd(),
20
- base: "/",
21
- // plugins: [react()],
22
- server: {
23
- ...config?.server,
24
- middlewareMode: true,
25
- },
26
- customLogger: {
27
- info: (msg) => {
28
- logger.info(msg)
29
- },
30
- warn: (msg) => logger.warning(msg),
31
- error: (msg) => logger.error(msg),
32
- },
33
- appType: 'custom'
34
- }
35
-
36
- const vite = await createViteServer(viteConfig);
37
- app.use(vite.middlewares);
38
-
39
- // exists tsconfig.json in the root directory
40
- const isTs = fs.existsSync(path.resolve(process.cwd(), 'main.tsx'))
41
- let entry = `/main.${isTs ? "tsx" : "jsx"}`
42
-
43
- app.get('*', async (req, res, next) => {
44
- const url = req.originalUrl;
45
-
46
- try {
47
- let template = await vite.transformIndexHtml(url, `
48
- <!doctype html>
49
- <html lang="en">
50
- <head>
51
- <meta charset="UTF-8" />
52
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
53
- </head>
54
- <body>
55
- <div id="root"></div>
56
- <script type="module" src="${entry}"></script>
57
- </body>
58
- </html>
59
- `);
60
-
61
- res.status(200).set({
62
- 'Content-Type': 'text/html'
63
- }).end(template);
64
- } catch (e) {
65
- vite.ssrFixStacktrace(e);
66
- next(e);
67
- }
68
- });
69
- return vite;
70
- }
71
-
72
-
1
+ // import react from '@vitejs/plugin-react'
2
+ import { createServer as createViteServer } from 'vite';
3
+ import { loadViteConfig, logger } from '../../helpers.js'
4
+ import path from 'path';
5
+ import fs from 'fs';
6
+
7
+ const viteSetup = async (app) => {
8
+ const config = await loadViteConfig() || {}
9
+
10
+ // delete .vite directory if exists
11
+ const viteDir = path.join(process.cwd(), 'node_modules/.vite');
12
+ if (fs.existsSync(viteDir)) {
13
+ fs.rmSync(viteDir, { recursive: true, force: true });
14
+ }
15
+
16
+ const viteConfig = {
17
+ ...config,
18
+ configFile: false,
19
+ root: process.cwd(),
20
+ base: "/",
21
+ // plugins: [react()],
22
+ server: {
23
+ ...config?.server,
24
+ middlewareMode: true,
25
+ },
26
+ customLogger: {
27
+ info: (msg) => {
28
+ logger.info(msg)
29
+ },
30
+ warn: (msg) => logger.warning(msg),
31
+ error: (msg) => logger.error(msg),
32
+ },
33
+ appType: 'custom'
34
+ }
35
+
36
+ const vite = await createViteServer(viteConfig);
37
+ app.use(vite.middlewares);
38
+
39
+ // exists tsconfig.json in the root directory
40
+ const isTs = fs.existsSync(path.resolve(process.cwd(), 'main.tsx'))
41
+ let entry = `/main.${isTs ? "tsx" : "jsx"}`
42
+
43
+ app.get('*', async (req, res, next) => {
44
+ const url = req.originalUrl;
45
+
46
+ try {
47
+ let template = await vite.transformIndexHtml(url, `
48
+ <!doctype html>
49
+ <html lang="en">
50
+ <head>
51
+ <meta charset="UTF-8" />
52
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
53
+ </head>
54
+ <body>
55
+ <div id="root"></div>
56
+ <script type="module" src="${entry}"></script>
57
+ </body>
58
+ </html>
59
+ `);
60
+
61
+ res.status(200).set({
62
+ 'Content-Type': 'text/html'
63
+ }).end(template);
64
+ } catch (e) {
65
+ vite.ssrFixStacktrace(e);
66
+ next(e);
67
+ }
68
+ });
69
+ return vite;
70
+ }
71
+
72
+
73
73
  export default viteSetup
package/src/helpers.js CHANGED
@@ -1,120 +1,120 @@
1
- import child_process from 'child_process'
2
-
3
- export const execSync = (command, option = {}) => {
4
- try {
5
- const result = child_process.execSync(command, {
6
- encoding: "utf-8",
7
- stdio: 'inherit',
8
- ...option
9
- });
10
- result && console.log(result);
11
- } catch (error) {
12
- console.error(`Command failed: ${error.message}`);
13
- process.exit(1);
14
- }
15
- };
16
-
17
-
18
- export const conicon = {
19
- info: 'ℹ',
20
- success: '✔',
21
- warning: '⚠',
22
- error: '✖',
23
- };
24
-
25
- export const concolor = {
26
- red: (str) => `\x1b[31m${str}\x1b[0m`,
27
- green: (str) => `\x1b[32m${str}\x1b[0m`,
28
- yellow: (str) => `\x1b[33m${str}\x1b[0m`,
29
- blue: (str) => `\x1b[34m${str}\x1b[0m`,
30
- bold: (str) => `\x1b[1m${str}\x1b[0m`,
31
- dim: (str) => `\x1b[2m${str}\x1b[0m`,
32
- };
33
-
34
-
35
- export const logger = {
36
- log: (message, prefix, icon, color) => {
37
- let _color = concolor[color] || concolor.reset;
38
- let _icon = conicon[icon] || '';
39
- prefix = prefix ? _color(concolor.bold(prefix)) : "";
40
- console.log(`${_icon ? _color(_icon) + " " : ""}${prefix} ${message}`);
41
- },
42
- info: (message, prefix = 'INFO', icon = true) => {
43
- logger.log(message, prefix, icon ? 'info' : '', 'blue');
44
- },
45
- success: (message, prefix = 'SUCCESS:', icon = true) => {
46
- logger.log(message, prefix, icon ? 'success' : '', 'green');
47
- },
48
- warning: (message, prefix = 'WARNING:', icon = true) => {
49
- logger.log(message, prefix, icon ? 'warning' : '', 'yellow');
50
- },
51
- error: (message, prefix = 'ERROR:', icon = true) => {
52
- logger.log(message, prefix, icon ? 'error' : '', 'red');
53
- }
54
- };
55
-
56
- import fs from 'fs/promises';
57
- import path from 'path';
58
- import { pathToFileURL } from 'url';
59
-
60
- /**
61
- * Load full Vite config object from root
62
- */
63
- export async function loadViteConfig() {
64
- // List of common Vite config files
65
- const possibleFiles = [
66
- 'vite.config.js',
67
- 'vite.config.ts',
68
- 'vite.config.mjs',
69
- 'vite.config.cjs',
70
- ];
71
-
72
- for (const file of possibleFiles) {
73
- const configPath = path.resolve(process.cwd(), file);
74
-
75
- try {
76
- await fs.access(configPath); // check if file exists
77
- } catch {
78
- continue; // file doesn't exist, try next
79
- }
80
-
81
- try {
82
- const imported = await import(pathToFileURL(configPath).href);
83
- return imported.default || imported; // return full config object
84
- } catch (err) {
85
- console.error(`Failed to load ${file}:`, err);
86
- return null;
87
- }
88
- }
89
-
90
- return null; // no config found
91
- }
92
-
93
-
94
- export async function loadRollupConfig() {
95
- const possibleFiles = [
96
- 'rollup.config.js',
97
- 'rollup.config.mjs',
98
- 'rollup.config.cjs',
99
- ];
100
-
101
- for (const file of possibleFiles) {
102
- const configPath = path.resolve(process.cwd(), file);
103
-
104
- try {
105
- await fs.access(configPath); // check if file exists
106
- } catch {
107
- continue; // file doesn't exist, try next
108
- }
109
-
110
- try {
111
- const imported = await import(pathToFileURL(configPath).href);
112
- return imported.default || imported; // return full config object
113
- } catch (err) {
114
- console.error(`Failed to load ${file}:`, err);
115
- return null;
116
- }
117
- }
118
-
119
- return null;
120
- }
1
+ import child_process from 'child_process'
2
+
3
+ export const execSync = (command, option = {}) => {
4
+ try {
5
+ const result = child_process.execSync(command, {
6
+ encoding: "utf-8",
7
+ stdio: 'inherit',
8
+ ...option
9
+ });
10
+ result && console.log(result);
11
+ } catch (error) {
12
+ console.error(`Command failed: ${error.message}`);
13
+ process.exit(1);
14
+ }
15
+ };
16
+
17
+
18
+ export const conicon = {
19
+ info: 'ℹ',
20
+ success: '✔',
21
+ warning: '⚠',
22
+ error: '✖',
23
+ };
24
+
25
+ export const concolor = {
26
+ red: (str) => `\x1b[31m${str}\x1b[0m`,
27
+ green: (str) => `\x1b[32m${str}\x1b[0m`,
28
+ yellow: (str) => `\x1b[33m${str}\x1b[0m`,
29
+ blue: (str) => `\x1b[34m${str}\x1b[0m`,
30
+ bold: (str) => `\x1b[1m${str}\x1b[0m`,
31
+ dim: (str) => `\x1b[2m${str}\x1b[0m`,
32
+ };
33
+
34
+
35
+ export const logger = {
36
+ log: (message, prefix, icon, color) => {
37
+ let _color = concolor[color] || concolor.reset;
38
+ let _icon = conicon[icon] || '';
39
+ prefix = prefix ? _color(concolor.bold(prefix)) : "";
40
+ console.log(`${_icon ? _color(_icon) + " " : ""}${prefix} ${message}`);
41
+ },
42
+ info: (message, prefix = 'INFO', icon = true) => {
43
+ logger.log(message, prefix, icon ? 'info' : '', 'blue');
44
+ },
45
+ success: (message, prefix = 'SUCCESS:', icon = true) => {
46
+ logger.log(message, prefix, icon ? 'success' : '', 'green');
47
+ },
48
+ warning: (message, prefix = 'WARNING:', icon = true) => {
49
+ logger.log(message, prefix, icon ? 'warning' : '', 'yellow');
50
+ },
51
+ error: (message, prefix = 'ERROR:', icon = true) => {
52
+ logger.log(message, prefix, icon ? 'error' : '', 'red');
53
+ }
54
+ };
55
+
56
+ import fs from 'fs/promises';
57
+ import path from 'path';
58
+ import { pathToFileURL } from 'url';
59
+
60
+ /**
61
+ * Load full Vite config object from root
62
+ */
63
+ export async function loadViteConfig() {
64
+ // List of common Vite config files
65
+ const possibleFiles = [
66
+ 'vite.config.js',
67
+ 'vite.config.ts',
68
+ 'vite.config.mjs',
69
+ 'vite.config.cjs',
70
+ ];
71
+
72
+ for (const file of possibleFiles) {
73
+ const configPath = path.resolve(process.cwd(), file);
74
+
75
+ try {
76
+ await fs.access(configPath); // check if file exists
77
+ } catch {
78
+ continue; // file doesn't exist, try next
79
+ }
80
+
81
+ try {
82
+ const imported = await import(pathToFileURL(configPath).href);
83
+ return imported.default || imported; // return full config object
84
+ } catch (err) {
85
+ console.error(`Failed to load ${file}:`, err);
86
+ return null;
87
+ }
88
+ }
89
+
90
+ return null; // no config found
91
+ }
92
+
93
+
94
+ export async function loadRollupConfig() {
95
+ const possibleFiles = [
96
+ 'rollup.config.js',
97
+ 'rollup.config.mjs',
98
+ 'rollup.config.cjs',
99
+ ];
100
+
101
+ for (const file of possibleFiles) {
102
+ const configPath = path.resolve(process.cwd(), file);
103
+
104
+ try {
105
+ await fs.access(configPath); // check if file exists
106
+ } catch {
107
+ continue; // file doesn't exist, try next
108
+ }
109
+
110
+ try {
111
+ const imported = await import(pathToFileURL(configPath).href);
112
+ return imported.default || imported; // return full config object
113
+ } catch (err) {
114
+ console.error(`Failed to load ${file}:`, err);
115
+ return null;
116
+ }
117
+ }
118
+
119
+ return null;
120
+ }
package/src/index.js CHANGED
@@ -1,39 +1,39 @@
1
- #!/usr/bin/env node
2
-
3
- import { Command } from "commander";
4
- import start from "./actions/start/index.js";
5
- import build from "./actions/build/index.js";
6
- import create from "./actions/create/index.js";
7
- import release from "./actions/release/index.js";
8
-
9
- const program = new Command();
10
-
11
- program.name("Makepack").description("Usages");
12
-
13
- program
14
- .command("create")
15
- .description("Create a new project")
16
- .action(create);
17
-
18
- program
19
- .command("start")
20
- .option("-p, --port <port>", "Port to run the server")
21
- .description("Start the server")
22
- .action(start);
23
-
24
- program
25
- .command("build")
26
- .description("Build the project")
27
- .option("-f, --format <format>", "Output format (cjs, esm, both)", "both")
28
- .option("-b, --bundle <bundle>", "Bundle the project", false)
29
- .option("-m, --minify <minify>", "Minify the output", false)
30
- .option("-s, --sourcemap <sourcemap>", "Generate sourcemaps", true)
31
- .option("-d, --declaration <declaration>", "Generate TypeScript declaration files", true)
32
- .action(build);
33
-
34
- program
35
- .command("release")
36
- .description("Release it to the npm repository")
37
- .action(release);
38
-
39
- program.parse();
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from "commander";
4
+ import start from "./actions/start/index.js";
5
+ import build from "./actions/build/index.js";
6
+ import create from "./actions/create/index.js";
7
+ import release from "./actions/release/index.js";
8
+
9
+ const program = new Command();
10
+
11
+ program.name("Makepack").description("Usages");
12
+
13
+ program
14
+ .command("create")
15
+ .description("Create a new project")
16
+ .action(create);
17
+
18
+ program
19
+ .command("start")
20
+ .option("-p, --port <port>", "Port to run the server")
21
+ .description("Start the server")
22
+ .action(start);
23
+
24
+ program
25
+ .command("build")
26
+ .description("Build the project")
27
+ .option("-f, --format <format>", "Output format (cjs, esm, both)", "both")
28
+ .option("-b, --bundle <bundle>", "Bundle the project", false)
29
+ .option("-m, --minify <minify>", "Minify the output", false)
30
+ .option("-s, --sourcemap <sourcemap>", "Generate sourcemaps", true)
31
+ .option("-d, --declaration <declaration>", "Generate TypeScript declaration files", true)
32
+ .action(build);
33
+
34
+ program
35
+ .command("release")
36
+ .description("Release it to the npm repository")
37
+ .action(release);
38
+
39
+ program.parse();