makepack 1.6.7 → 1.6.9
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 +1 -2
- package/src/actions/build/index.js +14 -28
- package/src/actions/create/files/package-json.js +1 -1
- package/src/actions/create/index.js +3 -11
- package/src/actions/start/express.js +18 -16
- package/src/actions/start/index.js +34 -35
- package/src/helpers.js +46 -11
- package/src/index.js +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "makepack",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.9",
|
|
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": [
|
|
@@ -36,7 +36,6 @@
|
|
|
36
36
|
"cosmiconfig": "^9.0.0",
|
|
37
37
|
"esbuild": "^0.25.0",
|
|
38
38
|
"express": "^4.21.1",
|
|
39
|
-
"figlet": "^1.8.0",
|
|
40
39
|
"figures": "^6.1.0",
|
|
41
40
|
"fs-extra": "^11.2.0",
|
|
42
41
|
"glob": "^11.0.0",
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import esbuild from 'esbuild'
|
|
2
2
|
import fs from 'fs-extra'
|
|
3
3
|
import path from 'path'
|
|
4
|
-
import chalk from 'chalk'
|
|
5
4
|
import ora from 'ora'
|
|
6
5
|
import { glob } from 'glob'
|
|
7
6
|
import ts from 'typescript'
|
|
7
|
+
import { concolor, logger } from '../../helpers.js'
|
|
8
8
|
|
|
9
9
|
const eBuild = async (conf) => {
|
|
10
10
|
|
|
11
11
|
await esbuild.build({
|
|
12
12
|
jsx: 'automatic',
|
|
13
13
|
...conf,
|
|
14
|
-
// outExtension: { '.js': ebconfig.format === 'esm' ? '.mjs' : '.cjs' },
|
|
15
14
|
loader: {
|
|
16
15
|
'.ts': 'ts',
|
|
17
16
|
'.tsx': 'tsx'
|
|
@@ -70,12 +69,12 @@ const build = async (args) => {
|
|
|
70
69
|
}
|
|
71
70
|
if (args.format === 'default') {
|
|
72
71
|
await eBuild({ ...config, format: "esm" });
|
|
73
|
-
|
|
72
|
+
logger.success('ESM build generated successfully!');
|
|
74
73
|
await eBuild({ ...config, format: "cjs" });
|
|
75
|
-
|
|
74
|
+
logger.success('CJS build generated successfully!');
|
|
76
75
|
} else {
|
|
77
76
|
await eBuild({ ...config, format: args.format });
|
|
78
|
-
|
|
77
|
+
logger.success(`${args.format} build generated successfully!`);
|
|
79
78
|
}
|
|
80
79
|
}
|
|
81
80
|
|
|
@@ -91,7 +90,7 @@ const build = async (args) => {
|
|
|
91
90
|
);
|
|
92
91
|
|
|
93
92
|
if (!parsedConfig) {
|
|
94
|
-
|
|
93
|
+
logger.error("Error parsing tsconfig.json");
|
|
95
94
|
process.exit(1);
|
|
96
95
|
} else {
|
|
97
96
|
tsconfig = parsedConfig.options;
|
|
@@ -120,13 +119,13 @@ const build = async (args) => {
|
|
|
120
119
|
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
|
|
121
120
|
if (diagnostic.file) {
|
|
122
121
|
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
|
|
123
|
-
|
|
122
|
+
logger.error(`Error at ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
|
|
124
123
|
} else {
|
|
125
|
-
|
|
124
|
+
logger.error(`${message}`);
|
|
126
125
|
}
|
|
127
126
|
});
|
|
128
127
|
} else {
|
|
129
|
-
|
|
128
|
+
logger.success("TypeScript declaration files generated successfully!")
|
|
130
129
|
}
|
|
131
130
|
}
|
|
132
131
|
spinner.text = "Copying package.json and readme.md files..."
|
|
@@ -135,33 +134,20 @@ const build = async (args) => {
|
|
|
135
134
|
const pkgPath = path.join(process.cwd(), 'package.json');
|
|
136
135
|
if (fs.existsSync(pkgPath)) {
|
|
137
136
|
const pkgjson = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
138
|
-
if (args.format === 'default') {
|
|
139
|
-
pkgjson.main = "./index.cjs";
|
|
140
|
-
pkgjson.module = "./index.mjs";
|
|
141
|
-
pkgjson.types = './index.d.ts'
|
|
142
|
-
} else {
|
|
143
|
-
let t = args.format === 'mjs' ? 'module' : 'main';
|
|
144
|
-
pkgjson[t] = `./index.${args.format}`;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (args.declaration) {
|
|
148
|
-
pkgjson.types = `./index.d.ts`;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
137
|
delete pkgjson.scripts
|
|
152
138
|
delete pkgjson.type
|
|
153
|
-
|
|
154
139
|
fs.writeFileSync(path.join(outdir, 'package.json'), JSON.stringify(pkgjson, null, 2));
|
|
155
140
|
} else {
|
|
156
|
-
|
|
141
|
+
logger.error("package.json not found!");
|
|
157
142
|
return;
|
|
158
143
|
}
|
|
159
144
|
|
|
160
145
|
fs.copyFileSync(path.join(process.cwd(), '/readme.md'), path.join(outdir, `/readme.md`))
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
146
|
+
logger.success("package.json and readme.md files copied successfully!")
|
|
147
|
+
logger.success(`completed successfully!`, 'BUILD:', true);
|
|
148
|
+
logger.info(`To publish your package to npm:`, 'INFO:', true);
|
|
149
|
+
logger.info(`${concolor.yellow(`npm run release`)} or navigate to the ${concolor.yellow(`.mpack`)} directory and run ${concolor.yellow(`npm publish`)}`, 'RELEASE:', true)
|
|
150
|
+
spinner.stop();
|
|
165
151
|
}
|
|
166
152
|
|
|
167
153
|
export default build
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { execSync, logger } from "../../helpers.js"
|
|
1
|
+
import { execSync, concolor, logger } from "../../helpers.js"
|
|
2
2
|
import makeFiles from "./makeFiles.js"
|
|
3
3
|
import path from 'path'
|
|
4
4
|
import inquirer from 'inquirer'
|
|
5
|
-
import figlet from 'figlet'
|
|
6
5
|
import fs from "fs-extra"
|
|
7
|
-
import chalk from 'chalk';
|
|
8
6
|
const cwd = process.cwd()
|
|
9
7
|
const cwdFolder = cwd.split(path.sep).pop()
|
|
10
8
|
|
|
@@ -89,16 +87,10 @@ const create = async () => {
|
|
|
89
87
|
|
|
90
88
|
logger.success("Project setup complete!", "")
|
|
91
89
|
if (isCurrentDir) {
|
|
92
|
-
|
|
90
|
+
logger.info(`Run the development server: ${concolor.yellow("npm start")}\nEnjoy your new project! 😊`);
|
|
93
91
|
} else {
|
|
94
|
-
|
|
92
|
+
logger.info(`Navigate to your project directory:\n${concolor.yellow("cd " + info.pdir, false)} and Run the development server: ${concolor.yellow("npm start")}\nEnjoy your new project! 😊`);
|
|
95
93
|
}
|
|
96
|
-
|
|
97
|
-
figlet("Makepack CLI", function (err, data) {
|
|
98
|
-
if (!err) {
|
|
99
|
-
console.log(data);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
94
|
}
|
|
103
95
|
|
|
104
96
|
export default create
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
|
-
import { logger } from '../../helpers.js'
|
|
3
|
-
import chalk from 'chalk';
|
|
4
2
|
import path from 'path'
|
|
5
3
|
import fs from 'fs'
|
|
6
4
|
import viteSetup from './vite.js';
|
|
7
5
|
const port = process.env.PORT || 3000;
|
|
8
6
|
const app = express();
|
|
9
|
-
const server = async () => {
|
|
7
|
+
const server = async (cb) => {
|
|
10
8
|
|
|
11
9
|
// get type from package.json
|
|
12
10
|
const pkg = path.join(process.cwd(), 'package.json');
|
|
@@ -16,19 +14,23 @@ const server = async () => {
|
|
|
16
14
|
type = pkgjson.type || 'module';
|
|
17
15
|
}
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (fs.existsSync(uxp)) {
|
|
22
|
-
// load user-express.js based on type
|
|
23
|
-
if (type === 'module') {
|
|
24
|
-
const { default: userExpress } = await import(uxp);
|
|
25
|
-
userExpress(app);
|
|
26
|
-
} else {
|
|
27
|
-
const userExpress = require(uxp).default;
|
|
28
|
-
userExpress(app);
|
|
29
|
-
}
|
|
17
|
+
if (cb) {
|
|
18
|
+
cb(app)
|
|
30
19
|
}
|
|
31
20
|
|
|
21
|
+
// const mpack = path.join(process.cwd(), '.mpack');
|
|
22
|
+
// const uxp = path.join(mpack, 'uxp.js')
|
|
23
|
+
// if (fs.existsSync(uxp)) {
|
|
24
|
+
// // load user-express.js based on type
|
|
25
|
+
// if (type === 'module') {
|
|
26
|
+
// const { default: userExpress } = await import(uxp);
|
|
27
|
+
// userExpress(app);
|
|
28
|
+
// } else {
|
|
29
|
+
// const userExpress = require(uxp).default;
|
|
30
|
+
// userExpress(app);
|
|
31
|
+
// }
|
|
32
|
+
// }
|
|
33
|
+
|
|
32
34
|
|
|
33
35
|
await viteSetup(app)
|
|
34
36
|
app.use((_req, res) => {
|
|
@@ -36,8 +38,8 @@ const server = async () => {
|
|
|
36
38
|
});
|
|
37
39
|
|
|
38
40
|
app.listen(port, () => {
|
|
39
|
-
|
|
41
|
+
console.log(`Server is running on: http://localhost:${port}`);
|
|
40
42
|
});
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
server
|
|
45
|
+
export default server;
|
|
@@ -15,7 +15,6 @@ if (typeof import.meta.url !== 'undefined') {
|
|
|
15
15
|
__dirname = __dirname;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
19
18
|
const startServer = () => {
|
|
20
19
|
const mpack = path.join(process.cwd(), '.mpack')
|
|
21
20
|
const server = spawn('node', [path.resolve(mpack, 'index.js')], {
|
|
@@ -29,11 +28,8 @@ const startServer = () => {
|
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
const start = async (args) => {
|
|
32
|
-
let
|
|
31
|
+
let port = args.port || 4000
|
|
33
32
|
|
|
34
|
-
if (!port) {
|
|
35
|
-
port = 4000;
|
|
36
|
-
}
|
|
37
33
|
// create a folder call .mpack
|
|
38
34
|
const mpack = path.join(process.cwd(), '.mpack')
|
|
39
35
|
if (fs.existsSync(mpack)) {
|
|
@@ -41,10 +37,7 @@ const start = async (args) => {
|
|
|
41
37
|
}
|
|
42
38
|
fs.mkdirSync(mpack)
|
|
43
39
|
|
|
44
|
-
|
|
45
|
-
// build ./express.js to .mpack/index.js with esbuild
|
|
46
40
|
let format = 'esm'
|
|
47
|
-
// get format from package.json
|
|
48
41
|
const pkg = path.join(process.cwd(), 'package.json')
|
|
49
42
|
if (fs.existsSync(pkg)) {
|
|
50
43
|
const pkgjson = JSON.parse(fs.readFileSync(pkg, 'utf-8'))
|
|
@@ -53,28 +46,11 @@ const start = async (args) => {
|
|
|
53
46
|
}
|
|
54
47
|
}
|
|
55
48
|
|
|
56
|
-
const uxpjs = path.join(process.cwd(), 'express.js')
|
|
57
|
-
const uxpts = path.join(process.cwd(), 'express.ts')
|
|
58
|
-
|
|
59
|
-
if (fs.existsSync(uxpjs) || fs.existsSync(uxpts)) {
|
|
60
|
-
let filename = fs.existsSync(uxpjs) ? "express.js" : "express.ts";
|
|
61
|
-
let outfile = path.join(mpack, 'uxp.js');
|
|
62
|
-
|
|
63
|
-
const ctx = await esbuild.context({
|
|
64
|
-
entryPoints: [filename],
|
|
65
|
-
outfile,
|
|
66
|
-
bundle: true,
|
|
67
|
-
format: 'esm',
|
|
68
|
-
platform: 'node',
|
|
69
|
-
packages: 'external',
|
|
70
|
-
})
|
|
71
|
-
ctx.watch()
|
|
72
|
-
}
|
|
73
|
-
|
|
74
49
|
await esbuild.build({
|
|
75
50
|
entryPoints: [path.resolve(__dirname, 'express.js')],
|
|
76
|
-
outfile: path.join(mpack, '
|
|
51
|
+
outfile: path.join(mpack, 'core.js'),
|
|
77
52
|
bundle: true,
|
|
53
|
+
minify: true,
|
|
78
54
|
format,
|
|
79
55
|
platform: 'node',
|
|
80
56
|
packages: 'external',
|
|
@@ -83,18 +59,41 @@ const start = async (args) => {
|
|
|
83
59
|
},
|
|
84
60
|
})
|
|
85
61
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const
|
|
62
|
+
const uxpjs = path.join(process.cwd(), 'express.js')
|
|
63
|
+
const uxpts = path.join(process.cwd(), 'express.ts')
|
|
64
|
+
const exists = fs.existsSync(uxpjs) || fs.existsSync(uxpts);
|
|
65
|
+
const uxpFile = exists ? (fs.existsSync(uxpjs) ? 'express.js' : 'express.ts') : '';
|
|
66
|
+
let contents = `import server from './.mpack/core';`;
|
|
67
|
+
contents += uxpFile ? `
|
|
68
|
+
import uxp from './${uxpFile}';
|
|
69
|
+
server(uxp);
|
|
70
|
+
` : `server();`;
|
|
71
|
+
|
|
72
|
+
const result = await esbuild.build({
|
|
73
|
+
bundle: true,
|
|
74
|
+
stdin: {
|
|
75
|
+
contents,
|
|
76
|
+
resolveDir: process.cwd(),
|
|
77
|
+
sourcefile: 'virtual.js',
|
|
78
|
+
loader: 'ts',
|
|
79
|
+
},
|
|
80
|
+
format,
|
|
81
|
+
outfile: path.join(mpack, 'index.js'),
|
|
82
|
+
platform: 'node',
|
|
83
|
+
packages: 'external',
|
|
84
|
+
sourcemap: true,
|
|
85
|
+
metafile: true,
|
|
86
|
+
})
|
|
89
87
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
let server = startServer();
|
|
89
|
+
if (uxpFile) {
|
|
90
|
+
const importedFiles = Object.keys(result.metafile.inputs);
|
|
91
|
+
const watcher = chokidar.watch(importedFiles, {
|
|
92
|
+
ignored: /node_modules/,
|
|
93
|
+
ignoreInitial: true
|
|
94
94
|
});
|
|
95
95
|
|
|
96
96
|
watcher.on('change', async () => {
|
|
97
|
-
// restart the server and remove log Server exited with code
|
|
98
97
|
server.kill();
|
|
99
98
|
server = startServer();
|
|
100
99
|
});
|
package/src/helpers.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import child_process from 'child_process'
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import figures from 'figures';
|
|
4
|
-
|
|
5
2
|
export const execSync = (command, option = {}) => {
|
|
6
3
|
try {
|
|
7
4
|
const result = child_process.execSync(command, {
|
|
@@ -17,21 +14,59 @@ export const execSync = (command, option = {}) => {
|
|
|
17
14
|
};
|
|
18
15
|
|
|
19
16
|
|
|
17
|
+
export const conicon = {
|
|
18
|
+
info: 'ℹ',
|
|
19
|
+
success: '✔',
|
|
20
|
+
warning: '⚠',
|
|
21
|
+
error: '✖',
|
|
22
|
+
dot: '․',
|
|
23
|
+
pointer: '❯',
|
|
24
|
+
arrowRight: '→',
|
|
25
|
+
arrowDown: '↓',
|
|
26
|
+
arrowUp: '↑',
|
|
27
|
+
star: '★',
|
|
28
|
+
check: '✅',
|
|
29
|
+
cross: '❌',
|
|
30
|
+
question: '?',
|
|
31
|
+
ellipsis: '…',
|
|
32
|
+
clock: '⏱',
|
|
33
|
+
hourglass: '⏳',
|
|
34
|
+
rocket: '🚀',
|
|
35
|
+
bug: '🐞',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const concolor = {
|
|
39
|
+
reset: (str) => `\x1b[0m${str}\x1b[0m`,
|
|
40
|
+
red: (str) => `\x1b[31m${str}\x1b[0m`,
|
|
41
|
+
green: (str) => `\x1b[32m${str}\x1b[0m`,
|
|
42
|
+
yellow: (str) => `\x1b[33m${str}\x1b[0m`,
|
|
43
|
+
blue: (str) => `\x1b[34m${str}\x1b[0m`,
|
|
44
|
+
magenta: (str) => `\x1b[35m${str}\x1b[0m`,
|
|
45
|
+
cyan: (str) => `\x1b[36m${str}\x1b[0m`,
|
|
46
|
+
white: (str) => `\x1b[37m${str}\x1b[0m`,
|
|
47
|
+
bold: (str) => `\x1b[1m${str}\x1b[0m`,
|
|
48
|
+
dim: (str) => `\x1b[2m${str}\x1b[0m`,
|
|
49
|
+
underline: (str) => `\x1b[4m${str}\x1b[0m`,
|
|
50
|
+
};
|
|
51
|
+
|
|
20
52
|
|
|
21
53
|
export const logger = {
|
|
54
|
+
log: (message, prefix, icon, color) => {
|
|
55
|
+
let _color = concolor[color] || concolor.reset;
|
|
56
|
+
let _icon = conicon[icon] || '';
|
|
57
|
+
prefix = prefix ? _color(concolor.bold(prefix)) : "";
|
|
58
|
+
console.log(`${_icon ? _color(_icon) + " " : ""}${prefix} ${message}`);
|
|
59
|
+
},
|
|
22
60
|
info: (message, prefix = 'INFO', icon = true) => {
|
|
23
|
-
|
|
61
|
+
logger.log(message, prefix, icon ? 'info' : '', 'blue');
|
|
24
62
|
},
|
|
25
63
|
success: (message, prefix = 'SUCCESS:', icon = true) => {
|
|
26
|
-
|
|
64
|
+
logger.log(message, prefix, icon ? 'success' : '', 'green');
|
|
27
65
|
},
|
|
28
66
|
warning: (message, prefix = 'WARNING:', icon = true) => {
|
|
29
|
-
|
|
67
|
+
logger.log(message, prefix, icon ? 'warning' : '', 'yellow');
|
|
30
68
|
},
|
|
31
69
|
error: (message, prefix = 'ERROR:', icon = true) => {
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
custom: (icon, color, label, message) => {
|
|
35
|
-
console.log(`${chalk[color](icon)} ${chalk[color].bold(`${label}:`)} ${message}`);
|
|
36
|
-
},
|
|
70
|
+
logger.log(message, prefix, icon ? 'error' : '', 'red');
|
|
71
|
+
}
|
|
37
72
|
};
|
package/src/index.js
CHANGED
|
File without changes
|