makepack 1.3.8 → 1.4.0

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/src/helpers.js CHANGED
@@ -1,122 +1,122 @@
1
- import child_process from 'child_process'
2
- import chalk from 'chalk';
3
- import figures from 'figures';
4
- import { pathToFileURL } from 'url';
5
- import path from 'path';
6
- import fs from 'fs-extra';
7
- import react from '@vitejs/plugin-react'
8
- import ts from 'typescript'
9
-
10
-
11
- export const logLoader = (message = "") => {
12
- const spinner = ['|', '/', '-', '\\'];
13
- let i = 0;
14
- const interval = setInterval(() => {
15
- process.stdout.write(`\r${message} ${spinner[i]}`);
16
- i = (i + 1) % spinner.length;
17
- }, 100);
18
-
19
- return {
20
- stop: (msg) => {
21
- clearInterval(interval);
22
- !!msg && console.log(`\r${msg}`);
23
- process.stdout.write(`\r`);
24
- }
25
- }
26
- }
27
-
28
- export const execSync = (command, option = {}) => {
29
- try {
30
- const result = child_process.execSync(command, {
31
- encoding: "utf-8",
32
- stdio: 'inherit',
33
- ...option
34
- });
35
- result && console.log(result);
36
- } catch (error) {
37
- console.error(`Command failed: ${error.message}`);
38
- process.exit(1);
39
- }
40
- };
41
-
42
-
43
-
44
- export const logger = {
45
- info: (message, prefix = 'INFO', icon = true) => {
46
- console.log(`${icon ? chalk.blue(figures.info) + " " : ""}${chalk.cyan.bold(prefix)} ${message}`);
47
- },
48
- success: (message, prefix = 'SUCCESS:', icon = true) => {
49
- console.log(`${icon ? chalk.green(figures.tick) + " " : ""}${chalk.green.bold(prefix)} ${message}`);
50
- },
51
- warning: (message, prefix = 'WARNING:', icon = true) => {
52
- console.log(`${icon ? chalk.yellow(figures.warning) + " " : ""}${chalk.yellow.bold(prefix)} ${message}`);
53
- },
54
- error: (message, prefix = 'ERROR:', icon = true) => {
55
- console.log(`${icon ? chalk.red(figures.cross) + " " : ""}${chalk.red.bold(prefix)} ${message}`);
56
- },
57
- custom: (icon, color, label, message) => {
58
- console.log(`${chalk[color](icon)} ${chalk[color].bold(`${label}:`)} ${message}`);
59
- },
60
- };
61
-
62
-
63
- export const loadConfig = async (args) => {
64
- const makepack = path.resolve(process.cwd(), "makepack.js");
65
- let esbuild = {
66
- minify: true,
67
- sourcemap: true,
68
- jsx: 'automatic',
69
- loader: {
70
- '.ts': 'ts',
71
- '.tsx': 'tsx'
72
- },
73
- }
74
-
75
- const defaultConfig = {
76
- pack: {
77
- tsconfig: {
78
- declaration: true,
79
- emitDeclarationOnly: true,
80
- outDir: path.join(process.cwd(), args.outdir || "pack", 'types'),
81
- strict: true,
82
- allowJs: true,
83
- jsx: ts.JsxEmit.React,
84
- esModuleInterop: true,
85
- },
86
- esm: esbuild,
87
- cjs: esbuild,
88
- },
89
- serve: {
90
- express: () => { },
91
- vite: {
92
- root: process.cwd(),
93
- plugins: [react()],
94
- server: {
95
- middlewareMode: true,
96
- },
97
- customLogger: {
98
- info: (msg) => {
99
- logger.info(msg)
100
- },
101
- warn: (msg) => logger.warning(msg),
102
- error: (msg) => logger.error(msg),
103
- },
104
- appType: 'custom'
105
- }
106
- }
107
- }
108
-
109
- if (fs.existsSync(makepack)) {
110
- try {
111
- const c = await import(pathToFileURL(makepack).href)
112
- const configFn = c.default
113
- if (typeof configFn === 'function') {
114
- return configFn(defaultConfig)
115
- }
116
- } catch (error) {
117
- console.log(error);
118
-
119
- }
120
- }
121
- return defaultConfig
1
+ import child_process from 'child_process'
2
+ import chalk from 'chalk';
3
+ import figures from 'figures';
4
+ import { pathToFileURL } from 'url';
5
+ import path from 'path';
6
+ import fs from 'fs-extra';
7
+ import react from '@vitejs/plugin-react'
8
+ import ts from 'typescript'
9
+
10
+
11
+ export const logLoader = (message = "") => {
12
+ const spinner = ['|', '/', '-', '\\'];
13
+ let i = 0;
14
+ const interval = setInterval(() => {
15
+ process.stdout.write(`\r${message} ${spinner[i]}`);
16
+ i = (i + 1) % spinner.length;
17
+ }, 100);
18
+
19
+ return {
20
+ stop: (msg) => {
21
+ clearInterval(interval);
22
+ !!msg && console.log(`\r${msg}`);
23
+ process.stdout.write(`\r`);
24
+ }
25
+ }
26
+ }
27
+
28
+ export const execSync = (command, option = {}) => {
29
+ try {
30
+ const result = child_process.execSync(command, {
31
+ encoding: "utf-8",
32
+ stdio: 'inherit',
33
+ ...option
34
+ });
35
+ result && console.log(result);
36
+ } catch (error) {
37
+ console.error(`Command failed: ${error.message}`);
38
+ process.exit(1);
39
+ }
40
+ };
41
+
42
+
43
+
44
+ export const logger = {
45
+ info: (message, prefix = 'INFO', icon = true) => {
46
+ console.log(`${icon ? chalk.blue(figures.info) + " " : ""}${chalk.cyan.bold(prefix)} ${message}`);
47
+ },
48
+ success: (message, prefix = 'SUCCESS:', icon = true) => {
49
+ console.log(`${icon ? chalk.green(figures.tick) + " " : ""}${chalk.green.bold(prefix)} ${message}`);
50
+ },
51
+ warning: (message, prefix = 'WARNING:', icon = true) => {
52
+ console.log(`${icon ? chalk.yellow(figures.warning) + " " : ""}${chalk.yellow.bold(prefix)} ${message}`);
53
+ },
54
+ error: (message, prefix = 'ERROR:', icon = true) => {
55
+ console.log(`${icon ? chalk.red(figures.cross) + " " : ""}${chalk.red.bold(prefix)} ${message}`);
56
+ },
57
+ custom: (icon, color, label, message) => {
58
+ console.log(`${chalk[color](icon)} ${chalk[color].bold(`${label}:`)} ${message}`);
59
+ },
60
+ };
61
+
62
+
63
+ export const loadConfig = async (args) => {
64
+ const makepack = path.resolve(process.cwd(), "makepack.js");
65
+ let esbuild = {
66
+ minify: true,
67
+ sourcemap: true,
68
+ jsx: 'automatic',
69
+ loader: {
70
+ '.ts': 'ts',
71
+ '.tsx': 'tsx'
72
+ },
73
+ }
74
+
75
+ const defaultConfig = {
76
+ pack: {
77
+ tsconfig: {
78
+ declaration: true,
79
+ emitDeclarationOnly: true,
80
+ outDir: path.join(process.cwd(), args.outdir || "pack", 'types'),
81
+ strict: true,
82
+ allowJs: true,
83
+ jsx: ts.JsxEmit.React,
84
+ esModuleInterop: true,
85
+ },
86
+ esm: esbuild,
87
+ cjs: esbuild,
88
+ },
89
+ serve: {
90
+ express: () => { },
91
+ vite: {
92
+ root: process.cwd(),
93
+ plugins: [react()],
94
+ server: {
95
+ middlewareMode: true,
96
+ },
97
+ customLogger: {
98
+ info: (msg) => {
99
+ logger.info(msg)
100
+ },
101
+ warn: (msg) => logger.warning(msg),
102
+ error: (msg) => logger.error(msg),
103
+ },
104
+ appType: 'custom'
105
+ }
106
+ }
107
+ }
108
+
109
+ if (fs.existsSync(makepack)) {
110
+ try {
111
+ const c = await import(pathToFileURL(makepack).href)
112
+ const configFn = c.default
113
+ if (typeof configFn === 'function') {
114
+ return configFn(defaultConfig)
115
+ }
116
+ } catch (error) {
117
+ console.log(error);
118
+
119
+ }
120
+ }
121
+ return defaultConfig
122
122
  }
package/src/index.js CHANGED
@@ -1,30 +1,30 @@
1
- #!/usr/bin/env node
2
-
3
- import { Command } from "commander";
4
- import serve from "./actions/serve/index.js";
5
- import pack from "./actions/pack/index.js";
6
- import create from "./actions/create/index.js";
7
-
8
- const program = new Command();
9
-
10
- program.name("Make Pack").description("Usages");
11
-
12
- program
13
- .command("create")
14
- .description("create a new project")
15
- .action(create);
16
-
17
- program
18
- .command("serve")
19
- .option("-p, --port <number>", "Port number", "5000")
20
- .option("-r, --root <file>", "root file")
21
- .description("Start the server")
22
- .action(serve);
23
-
24
- program
25
- .command("pack")
26
- .option("-e, --entry <file>", "Entry file or directory (you can use a glob pattern)", "src/**/*.{tsx,ts,js,jsx}")
27
- .option("-p, --publish", "Publish the project to the npm repository", false)
28
- .description("Build the project and optionally publish it to the npm repository")
29
- .action(pack);
30
- program.parse();
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from "commander";
4
+ import serve from "./actions/serve/index.js";
5
+ import pack from "./actions/pack/index.js";
6
+ import create from "./actions/create/index.js";
7
+
8
+ const program = new Command();
9
+
10
+ program.name("Make Pack").description("Usages");
11
+
12
+ program
13
+ .command("create")
14
+ .description("create a new project")
15
+ .action(create);
16
+
17
+ program
18
+ .command("serve")
19
+ .option("-p, --port <number>", "Port number", "5000")
20
+ .option("-r, --root <file>", "root file")
21
+ .description("Start the server")
22
+ .action(serve);
23
+
24
+ program
25
+ .command("pack")
26
+ .option("-e, --entry <file>", "Entry file or directory (you can use a glob pattern)", "src/**/*.{tsx,ts,js,jsx}")
27
+ .option("-p, --publish", "Publish the project to the npm repository", false)
28
+ .description("Build the project and optionally publish it to the npm repository")
29
+ .action(pack);
30
+ program.parse();