makepack 1.3.4 → 1.3.6

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,68 +1,68 @@
1
- import inquirer from "inquirer"
2
- import makeProjectDirectory from "./makeProjectDirectory.js"
3
- import fs from "fs-extra"
4
- import path from "path"
5
- const cwd = process.cwd()
6
- const cwdFolder = cwd.split(path.sep).pop()
7
-
8
- const makeProjectInformation = async () => {
9
- const projectDir = await makeProjectDirectory()
10
- const information = await inquirer.prompt([
11
- {
12
- type: 'list',
13
- name: 'template',
14
- message: 'Select a template',
15
- choices: ['typescript', 'javascript', 'react with typescript', 'react with javascript'],
16
- default: 'typeScript'
17
- }
18
- ])
19
-
20
- if (projectDir.dirname !== cwdFolder) {
21
- fs.removeSync(projectDir.cwd)
22
- fs.mkdirSync(projectDir.cwd)
23
- }
24
- information.entry = "index"
25
- information.rootdir = "src"
26
-
27
- switch (information.template) {
28
- case "typescript":
29
- information.entry = information.entry + ".ts"
30
- break;
31
- case "javascript":
32
- information.entry = information.entry + ".js"
33
- break;
34
- case "react with typescript":
35
- information.entry = information.entry + ".tsx"
36
- break;
37
- case "react with javascript":
38
- information.entry = information.entry + ".jsx"
39
- break;
40
- }
41
-
42
- // check if the root directory exists
43
- if (!fs.existsSync(path.join(projectDir.cwd, information.rootdir))) {
44
- fs.mkdirSync(path.join(projectDir.cwd, information.rootdir))
45
- }
46
-
47
- /*
48
- {
49
- port: 3000,
50
- outdir: "pack",
51
- cwd: 'C:\xampp\htdocs\makepack\asd',
52
- dirname: 'asd',
53
- isCurrentDir: false,
54
- template: 'typescript',
55
- rootdir: 'src',
56
- entry: 'index'
57
- }
58
- */
59
-
60
- return {
61
- // port: 3000,
62
- outdir: "pack",
63
- ...projectDir,
64
- ...information
65
- }
66
- }
67
-
1
+ import inquirer from "inquirer"
2
+ import makeProjectDirectory from "./makeProjectDirectory.js"
3
+ import fs from "fs-extra"
4
+ import path from "path"
5
+ const cwd = process.cwd()
6
+ const cwdFolder = cwd.split(path.sep).pop()
7
+
8
+ const makeProjectInformation = async () => {
9
+ const projectDir = await makeProjectDirectory()
10
+ const information = await inquirer.prompt([
11
+ {
12
+ type: 'list',
13
+ name: 'template',
14
+ message: 'Select a template',
15
+ choices: ['typescript', 'javascript', 'react with typescript', 'react with javascript'],
16
+ default: 'typeScript'
17
+ }
18
+ ])
19
+
20
+ if (projectDir.dirname !== cwdFolder) {
21
+ fs.removeSync(projectDir.cwd)
22
+ fs.mkdirSync(projectDir.cwd)
23
+ }
24
+ information.entry = "index"
25
+ information.rootdir = "src"
26
+
27
+ switch (information.template) {
28
+ case "typescript":
29
+ information.entry = information.entry + ".ts"
30
+ break;
31
+ case "javascript":
32
+ information.entry = information.entry + ".js"
33
+ break;
34
+ case "react with typescript":
35
+ information.entry = information.entry + ".tsx"
36
+ break;
37
+ case "react with javascript":
38
+ information.entry = information.entry + ".jsx"
39
+ break;
40
+ }
41
+
42
+ // check if the root directory exists
43
+ if (!fs.existsSync(path.join(projectDir.cwd, information.rootdir))) {
44
+ fs.mkdirSync(path.join(projectDir.cwd, information.rootdir))
45
+ }
46
+
47
+ /*
48
+ {
49
+ port: 3000,
50
+ outdir: "pack",
51
+ cwd: 'C:\xampp\htdocs\makepack\asd',
52
+ dirname: 'asd',
53
+ isCurrentDir: false,
54
+ template: 'typescript',
55
+ rootdir: 'src',
56
+ entry: 'index'
57
+ }
58
+ */
59
+
60
+ return {
61
+ // port: 3000,
62
+ outdir: "pack",
63
+ ...projectDir,
64
+ ...information
65
+ }
66
+ }
67
+
68
68
  export default makeProjectInformation
@@ -1,77 +1,113 @@
1
- import esbuild from 'esbuild';
2
- import fs from 'fs-extra';
3
- import path from 'path';
4
- import { glob } from 'glob'
5
- import ts from 'typescript'
6
- import { execSync, logLoader, loadConfig } from '../../helpers.js';
7
-
8
- const pack = async (args) => {
9
- args.outdir = 'pack'
10
- try {
11
- fs.removeSync(path.join(process.cwd(), args.outdir));
12
- } catch (err) { }
13
-
14
- const files = await glob('src/**/*.{tsx,ts,js,jsx}') || []
15
- const entries = files.map(entry => path.join(process.cwd(), entry))
16
- let loader = logLoader("Generating a production build for the package...")
17
- const esbuildConfig = await loadConfig('esbuild.config.js') || {}
18
-
19
- esbuild.buildSync({
20
- // minify: true,
21
- sourcemap: true,
22
- format: "esm",
23
- platform: 'node',
24
- loader: { '.ts': 'ts' },
25
- // tsconfig: path.join(process.cwd(), 'tsconfig.json'),
26
- ...esbuildConfig,
27
- entryPoints: entries,
28
- outdir: path.join(process.cwd(), args.outdir),
29
- })
30
- loader.stop()
31
- loader = logLoader("🔄 Generating TypeScript declarations...")
32
- const options = {
33
- declaration: true,
34
- emitDeclarationOnly: true,
35
- outDir: path.join(process.cwd(), args.outdir),
36
- strict: true,
37
- allowJs: true,
38
- jsx: ts.JsxEmit.React,
39
- esModuleInterop: true,
40
- };
41
-
42
- const program = ts.createProgram(files, options);
43
- const emitResult = program.emit();
44
- const diagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
45
-
46
- if (diagnostics.length > 0) {
47
- diagnostics.forEach(diagnostic => {
48
- const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
49
- if (diagnostic.file) {
50
- const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
51
- console.error(`Error at ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
52
- } else {
53
- console.error(`Error: ${message}`);
54
- }
55
- });
56
- } else {
57
- console.log('✅ TypeScript declaration files generated successfully!');
58
- }
59
- loader.stop()
60
-
61
- fs.copyFileSync(path.join(process.cwd(), '/package.json'), path.join(process.cwd(), args.outdir, `/package.json`))
62
- fs.copyFileSync(path.join(process.cwd(), '/readme.md'), path.join(process.cwd(), args.outdir, `/readme.md`))
63
- console.log('✅ Production build generated successfully! The package is ready for deployment.');
64
-
65
- if (args.publish) {
66
- console.log("Publishing the production build to the npm repository...")
67
- execSync(`npm publish`, {
68
- cwd: path.join(process.cwd(), args.outdir)
69
- })
70
- } else {
71
- console.log(`To publish your package:\n1. Navigate to the ${args.outdir} directory:\ncd ./${args.outdir}\n2. Publish the package to npm:\nnpm publish\nYour package is ready to share with the world! 🚀`);
72
- }
73
-
74
-
75
- }
76
-
1
+ import esbuild from 'esbuild';
2
+ import fs from 'fs-extra';
3
+ import path from 'path';
4
+ import { glob } from 'glob'
5
+ import ts from 'typescript'
6
+ import { execSync, logLoader, loadConfig } from '../../helpers.js';
7
+
8
+ const pack = async (args) => {
9
+ args.outdir = 'pack'
10
+ try {
11
+ fs.removeSync(path.join(process.cwd(), args.outdir));
12
+ fs.mkdirSync(path.join(process.cwd(), args.outdir));
13
+ } catch (err) { }
14
+
15
+ const files = await glob('src/**/*.{tsx,ts,js,jsx}') || []
16
+ const entryPoints = files.map(entry => path.join(process.cwd(), entry))
17
+ let loader = logLoader("Generating a production build for the package...")
18
+ const esbuildConfig = await loadConfig('esbuild.config.js') || {}
19
+
20
+ function build(format) {
21
+ return esbuild.build({
22
+ // bundle: true,
23
+ // target: ['esnext'],
24
+ // splitting: format === 'esm', // Enable code splitting only for ESM
25
+ minify: true,
26
+ sourcemap: true,
27
+ jsx: 'automatic',
28
+ loader: {
29
+ '.ts': 'ts',
30
+ '.tsx': 'tsx'
31
+ },
32
+ ...esbuildConfig,
33
+ format: format, // 'esm' or 'cjs'
34
+ entryPoints,
35
+ outdir: path.join(process.cwd(), args.outdir, format),
36
+ });
37
+ }
38
+
39
+ Promise.all([
40
+ build('esm'),
41
+ build('cjs'),
42
+ ]).catch(() => process.exit(1));
43
+
44
+ loader.stop()
45
+ loader = logLoader("🔄 Generating TypeScript declarations...")
46
+ const options = {
47
+ declaration: true,
48
+ emitDeclarationOnly: true,
49
+ outDir: path.join(process.cwd(), args.outdir, 'types'),
50
+ strict: true,
51
+ allowJs: true,
52
+ jsx: ts.JsxEmit.React,
53
+ esModuleInterop: true,
54
+ };
55
+
56
+ const program = ts.createProgram(files, options);
57
+ const emitResult = program.emit();
58
+ const diagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
59
+
60
+ if (diagnostics.length > 0) {
61
+ diagnostics.forEach(diagnostic => {
62
+ const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
63
+ if (diagnostic.file) {
64
+ const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
65
+ console.error(`Error at ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
66
+ } else {
67
+ console.error(`Error: ${message}`);
68
+ }
69
+ });
70
+ } else {
71
+ console.log('✅ TypeScript declaration files generated successfully!');
72
+ }
73
+ loader.stop()
74
+
75
+ let packageJson = JSON.parse(fs.readFileSync(path.join(process.cwd(), '/package.json'), 'utf8'));
76
+
77
+ let name = packageJson.name
78
+ let version = packageJson.version
79
+ let description = packageJson.description
80
+ delete packageJson.name
81
+ delete packageJson.version
82
+ delete packageJson.description
83
+
84
+ packageJson = {
85
+ name,
86
+ version,
87
+ description,
88
+ main: './cjs/index.js',
89
+ module: './esm/index.js',
90
+ types: './types/index.d.ts',
91
+ ...packageJson,
92
+ }
93
+
94
+ delete packageJson.type
95
+
96
+ fs.writeFileSync(path.join(process.cwd(), args.outdir, '/package.json'), JSON.stringify(packageJson, null, 2));
97
+
98
+ fs.copyFileSync(path.join(process.cwd(), '/readme.md'), path.join(process.cwd(), args.outdir, `/readme.md`))
99
+ console.log('✅ Production build generated successfully! The package is ready for deployment.');
100
+
101
+ if (args.publish) {
102
+ console.log("Publishing the production build to the npm repository...")
103
+ execSync(`npm publish`, {
104
+ cwd: path.join(process.cwd(), args.outdir)
105
+ })
106
+ } else {
107
+ console.log(`To publish your package:\n1. Navigate to the ${args.outdir} directory:\ncd ./${args.outdir}\n2. Publish the package to npm:\nnpm publish\nYour package is ready to share with the world! 🚀`);
108
+ }
109
+
110
+
111
+ }
112
+
77
113
  export default pack
@@ -1,107 +1,107 @@
1
- import inquirer from 'inquirer'
2
- import fs from 'fs-extra'
3
- import path from 'path'
4
- import { createServer as createViteServer } from 'vite';
5
- import express from 'express';
6
- import { glob } from 'glob'
7
- import { logger, loadConfig } from '../../helpers.js'
8
- import chalk from 'chalk';
9
- import figlet from 'figlet';
10
- import react from '@vitejs/plugin-react'
11
-
12
- const app = express();
13
-
14
-
15
-
16
- const serve = async (args) => {
17
- if (args.root === undefined) {
18
- const serveFile = await glob('serve.{ts,js,tsx,jsx}', {
19
- cwd: process.cwd()
20
- })
21
- if (!serveFile.length) {
22
- let { root } = await inquirer.prompt([{
23
- type: 'input',
24
- name: 'root',
25
- message: 'Enter the root file',
26
- }]);
27
-
28
- if (!fs.existsSync(path.join(process.cwd(), root))) {
29
- throw new Error(`invalid root: ${root}`);
30
- }
31
- args.root = root;
32
- } else {
33
- args.root = serveFile[0];
34
- }
35
- }
36
-
37
- let template = `
38
- <!doctype html>
39
- <html lang="en">
40
- <head>
41
- <meta charset="UTF-8" />
42
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
43
- </head>
44
- <body>
45
- <div id="root"></div>
46
- <script type="module" src="${args.root}"></script>
47
- </body>
48
- </html>
49
- `;
50
-
51
- let viteConfig = await loadConfig('vite.config.js') || {}
52
-
53
- const vite = await createViteServer({
54
- ...viteConfig,
55
- root: process.cwd(),
56
- plugins: [react(), ...(viteConfig.plugins || [])],
57
- server: {
58
- middlewareMode: true,
59
- ...(viteConfig.server || {})
60
- },
61
- customLogger: {
62
- info: (msg) => {
63
- logger.info(msg)
64
- },
65
- warn: (msg) => logger.warning(msg),
66
- error: (msg) => logger.error(msg),
67
- ...(viteConfig.customLogger || {})
68
- },
69
- appType: 'custom'
70
- });
71
-
72
- app.use(vite.middlewares);
73
- app.get('/', async (req, res, next) => {
74
- const url = req.originalUrl;
75
- try {
76
- template = await vite.transformIndexHtml(url, template);
77
- res.status(200).set({
78
- 'Content-Type': 'text/html'
79
- }).end(template);
80
- } catch (e) {
81
- vite.ssrFixStacktrace(e);
82
- next(e);
83
- }
84
- });
85
-
86
- let server = app.listen(args.port, () => {
87
- figlet("Make Pack", function (err, data) {
88
- if (err) {
89
- console.log("Something went wrong...");
90
- console.dir(err);
91
- server.close(() => {
92
- console.log('Server has been stopped.');
93
- });
94
- process.exit()
95
- }
96
- console.log(data);
97
- logger.success(`Server is running on ${chalk.blue(chalk.underline(`http://localhost:${args.port}`))}`);
98
- });
99
- });
100
-
101
- app.use((err, req, res, next) => {
102
- logger.error(`Unhandled Error: ${err.message}`);
103
- res.status(500).send('Internal Server Error');
104
- });
105
- }
106
-
1
+ import inquirer from 'inquirer'
2
+ import fs from 'fs-extra'
3
+ import path from 'path'
4
+ import { createServer as createViteServer } from 'vite';
5
+ import express from 'express';
6
+ import { glob } from 'glob'
7
+ import { logger, loadConfig } from '../../helpers.js'
8
+ import chalk from 'chalk';
9
+ import figlet from 'figlet';
10
+ import react from '@vitejs/plugin-react'
11
+
12
+ const app = express();
13
+
14
+
15
+
16
+ const serve = async (args) => {
17
+ if (args.root === undefined) {
18
+ const serveFile = await glob('serve.{ts,js,tsx,jsx}', {
19
+ cwd: process.cwd()
20
+ })
21
+ if (!serveFile.length) {
22
+ let { root } = await inquirer.prompt([{
23
+ type: 'input',
24
+ name: 'root',
25
+ message: 'Enter the root file',
26
+ }]);
27
+
28
+ if (!fs.existsSync(path.join(process.cwd(), root))) {
29
+ throw new Error(`invalid root: ${root}`);
30
+ }
31
+ args.root = root;
32
+ } else {
33
+ args.root = serveFile[0];
34
+ }
35
+ }
36
+
37
+ let template = `
38
+ <!doctype html>
39
+ <html lang="en">
40
+ <head>
41
+ <meta charset="UTF-8" />
42
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
43
+ </head>
44
+ <body>
45
+ <div id="root"></div>
46
+ <script type="module" src="${args.root}"></script>
47
+ </body>
48
+ </html>
49
+ `;
50
+
51
+ let viteConfig = await loadConfig('vite.config.js') || {}
52
+
53
+ const vite = await createViteServer({
54
+ ...viteConfig,
55
+ root: process.cwd(),
56
+ plugins: [react(), ...(viteConfig.plugins || [])],
57
+ server: {
58
+ middlewareMode: true,
59
+ ...(viteConfig.server || {})
60
+ },
61
+ customLogger: {
62
+ info: (msg) => {
63
+ logger.info(msg)
64
+ },
65
+ warn: (msg) => logger.warning(msg),
66
+ error: (msg) => logger.error(msg),
67
+ ...(viteConfig.customLogger || {})
68
+ },
69
+ appType: 'custom'
70
+ });
71
+
72
+ app.use(vite.middlewares);
73
+ app.get('/', async (req, res, next) => {
74
+ const url = req.originalUrl;
75
+ try {
76
+ template = await vite.transformIndexHtml(url, template);
77
+ res.status(200).set({
78
+ 'Content-Type': 'text/html'
79
+ }).end(template);
80
+ } catch (e) {
81
+ vite.ssrFixStacktrace(e);
82
+ next(e);
83
+ }
84
+ });
85
+
86
+ let server = app.listen(args.port, () => {
87
+ figlet("Make Pack", function (err, data) {
88
+ if (err) {
89
+ console.log("Something went wrong...");
90
+ console.dir(err);
91
+ server.close(() => {
92
+ console.log('Server has been stopped.');
93
+ });
94
+ process.exit()
95
+ }
96
+ console.log(data);
97
+ logger.success(`Server is running on ${chalk.blue(chalk.underline(`http://localhost:${args.port}`))}`);
98
+ });
99
+ });
100
+
101
+ app.use((err, req, res, next) => {
102
+ logger.error(`Unhandled Error: ${err.message}`);
103
+ res.status(500).send('Internal Server Error');
104
+ });
105
+ }
106
+
107
107
  export default serve