makepack 1.3.7 → 1.3.8

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,111 +1,95 @@
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
- async function build(format) {
21
- return esbuild.buildSync({
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
- await build('esm')
40
- await build('cjs')
41
-
42
- loader.stop()
43
- loader = logLoader("🔄 Generating TypeScript declarations...")
44
- const options = {
45
- declaration: true,
46
- emitDeclarationOnly: true,
47
- outDir: path.join(process.cwd(), args.outdir, 'types'),
48
- strict: true,
49
- allowJs: true,
50
- jsx: ts.JsxEmit.React,
51
- esModuleInterop: true,
52
- };
53
-
54
- const program = ts.createProgram(files, options);
55
- const emitResult = program.emit();
56
- const diagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
57
-
58
- if (diagnostics.length > 0) {
59
- diagnostics.forEach(diagnostic => {
60
- const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
61
- if (diagnostic.file) {
62
- const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
63
- console.error(`Error at ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
64
- } else {
65
- console.error(`Error: ${message}`);
66
- }
67
- });
68
- } else {
69
- console.log('✅ TypeScript declaration files generated successfully!');
70
- }
71
- loader.stop()
72
-
73
- let packageJson = JSON.parse(fs.readFileSync(path.join(process.cwd(), '/package.json'), 'utf8'));
74
-
75
- let name = packageJson.name
76
- let version = packageJson.version
77
- let description = packageJson.description
78
- delete packageJson.name
79
- delete packageJson.version
80
- delete packageJson.description
81
-
82
- packageJson = {
83
- name,
84
- version,
85
- description,
86
- main: './cjs/index.js',
87
- module: './esm/index.js',
88
- types: './types/index.d.ts',
89
- ...packageJson,
90
- }
91
-
92
- delete packageJson.type
93
-
94
- fs.writeFileSync(path.join(process.cwd(), args.outdir, '/package.json'), JSON.stringify(packageJson, null, 2));
95
-
96
- fs.copyFileSync(path.join(process.cwd(), '/readme.md'), path.join(process.cwd(), args.outdir, `/readme.md`))
97
- console.log('✅ Production build generated successfully! The package is ready for deployment.');
98
-
99
- if (args.publish) {
100
- console.log("Publishing the production build to the npm repository...")
101
- execSync(`npm publish`, {
102
- cwd: path.join(process.cwd(), args.outdir)
103
- })
104
- } else {
105
- 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! 🚀`);
106
- }
107
-
108
-
109
- }
110
-
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 config = await loadConfig(args)
19
+ const packConfig = config.pack || {}
20
+ const esmConfig = packConfig?.esm
21
+ const cjsConfig = packConfig?.cjs
22
+ const tsConfig = packConfig?.tsconfig
23
+
24
+ async function build(format) {
25
+ return esbuild.buildSync({
26
+ ...(format === 'esm' ? esmConfig : cjsConfig),
27
+ format: format,
28
+ entryPoints,
29
+ outdir: path.join(process.cwd(), args.outdir, format),
30
+ });
31
+ }
32
+
33
+ esmConfig && await build('esm')
34
+ cjsConfig && await build('cjs')
35
+
36
+ loader.stop()
37
+ if (tsConfig) {
38
+ loader = logLoader("🔄 Generating TypeScript declarations...")
39
+ const program = ts.createProgram(files, tsConfig);
40
+ const emitResult = program.emit();
41
+ const diagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
42
+
43
+ if (diagnostics.length > 0) {
44
+ diagnostics.forEach(diagnostic => {
45
+ const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
46
+ if (diagnostic.file) {
47
+ const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
48
+ console.error(`Error at ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
49
+ } else {
50
+ console.error(`Error: ${message}`);
51
+ }
52
+ });
53
+ } else {
54
+ console.log('✅ TypeScript declaration files generated successfully!');
55
+ }
56
+ loader.stop()
57
+ }
58
+
59
+ let packageJson = JSON.parse(fs.readFileSync(path.join(process.cwd(), '/package.json'), 'utf8'));
60
+
61
+ let name = packageJson.name
62
+ let version = packageJson.version
63
+ let description = packageJson.description
64
+ delete packageJson.name
65
+ delete packageJson.version
66
+ delete packageJson.description
67
+
68
+ packageJson = {
69
+ name,
70
+ version,
71
+ description,
72
+ main: './cjs/index.js',
73
+ module: './esm/index.js',
74
+ types: './types/index.d.ts',
75
+ ...packageJson,
76
+ }
77
+
78
+ delete packageJson.type
79
+
80
+ fs.writeFileSync(path.join(process.cwd(), args.outdir, '/package.json'), JSON.stringify(packageJson, null, 2));
81
+
82
+ fs.copyFileSync(path.join(process.cwd(), '/readme.md'), path.join(process.cwd(), args.outdir, `/readme.md`))
83
+ console.log('✅ Production build generated successfully! The package is ready for deployment.');
84
+
85
+ if (args.publish) {
86
+ console.log("Publishing the production build to the npm repository...")
87
+ execSync(`npm publish`, {
88
+ cwd: path.join(process.cwd(), args.outdir)
89
+ })
90
+ } else {
91
+ 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! 🚀`);
92
+ }
93
+ }
94
+
111
95
  export default pack
@@ -1,107 +1,97 @@
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
+
11
+ const app = express();
12
+
13
+
14
+
15
+ const serve = async (args) => {
16
+ if (args.root === undefined) {
17
+ const serveFile = await glob('serve.{ts,js,tsx,jsx}', {
18
+ cwd: process.cwd()
19
+ })
20
+ if (!serveFile.length) {
21
+ let { root } = await inquirer.prompt([{
22
+ type: 'input',
23
+ name: 'root',
24
+ message: 'Enter the root file',
25
+ }]);
26
+
27
+ if (!fs.existsSync(path.join(process.cwd(), root))) {
28
+ throw new Error(`invalid root: ${root}`);
29
+ }
30
+ args.root = root;
31
+ } else {
32
+ args.root = serveFile[0];
33
+ }
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 config = await loadConfig(args)
52
+ let serveConfig = config.serve || {}
53
+ let viteConfig = serveConfig.vite || {}
54
+ let express = serveConfig.express
55
+
56
+ const vite = await createViteServer(viteConfig);
57
+ app.use(vite.middlewares);
58
+
59
+ if (express) {
60
+ express(app)
61
+ }
62
+
63
+ app.get('*', async (req, res, next) => {
64
+ const url = req.originalUrl;
65
+ try {
66
+ template = await vite.transformIndexHtml(url, template);
67
+ res.status(200).set({
68
+ 'Content-Type': 'text/html'
69
+ }).end(template);
70
+ } catch (e) {
71
+ vite.ssrFixStacktrace(e);
72
+ next(e);
73
+ }
74
+ });
75
+
76
+ let server = app.listen(args.port, () => {
77
+ figlet("Make Pack", function (err, data) {
78
+ if (err) {
79
+ console.log("Something went wrong...");
80
+ console.dir(err);
81
+ server.close(() => {
82
+ console.log('Server has been stopped.');
83
+ });
84
+ process.exit()
85
+ }
86
+ console.log(data);
87
+ logger.success(`Server is running on ${chalk.blue(chalk.underline(`http://localhost:${args.port}`))}`);
88
+ });
89
+ });
90
+
91
+ app.use((err, req, res, next) => {
92
+ logger.error(`Unhandled Error: ${err.message}`);
93
+ res.status(500).send('Internal Server Error');
94
+ });
95
+ }
96
+
107
97
  export default serve