makepack 1.3.8 → 1.3.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.
@@ -1,42 +1,42 @@
1
- import path from "path"
2
- import fs from "fs-extra"
3
- import inquirer from "inquirer"
4
- const cwd = process.cwd()
5
- const cwdFolder = cwd.split(path.sep).pop()
6
-
7
- export default async () => {
8
- const { projectDirName } = await inquirer.prompt([
9
- {
10
- type: 'input',
11
- name: 'projectDirName',
12
- message: 'Enter the project name',
13
- default: cwdFolder
14
- }
15
- ])
16
-
17
- let projectDir = cwd
18
-
19
- if (projectDirName !== cwdFolder) {
20
- projectDir = path.join(cwd, projectDirName);
21
- if (fs.existsSync(projectDir)) {
22
- const { proceed } = await inquirer.prompt([
23
- {
24
- type: "confirm",
25
- name: 'proceed',
26
- message: "The directory already exists, do you want to overwrite it?",
27
- default: cwdFolder
28
- }
29
- ])
30
- if (!proceed) {
31
- console.log('Project creation canceled.');
32
- return
33
- }
34
- }
35
- }
36
-
37
- return {
38
- cwd: projectDir,
39
- dirname: projectDirName,
40
- isCurrentDir: projectDirName === cwdFolder
41
- }
1
+ import path from "path"
2
+ import fs from "fs-extra"
3
+ import inquirer from "inquirer"
4
+ const cwd = process.cwd()
5
+ const cwdFolder = cwd.split(path.sep).pop()
6
+
7
+ export default async () => {
8
+ const { projectDirName } = await inquirer.prompt([
9
+ {
10
+ type: 'input',
11
+ name: 'projectDirName',
12
+ message: 'Enter the project name',
13
+ default: cwdFolder
14
+ }
15
+ ])
16
+
17
+ let projectDir = cwd
18
+
19
+ if (projectDirName !== cwdFolder) {
20
+ projectDir = path.join(cwd, projectDirName);
21
+ if (fs.existsSync(projectDir)) {
22
+ const { proceed } = await inquirer.prompt([
23
+ {
24
+ type: "confirm",
25
+ name: 'proceed',
26
+ message: "The directory already exists, do you want to overwrite it?",
27
+ default: cwdFolder
28
+ }
29
+ ])
30
+ if (!proceed) {
31
+ console.log('Project creation canceled.');
32
+ return
33
+ }
34
+ }
35
+ }
36
+
37
+ return {
38
+ cwd: projectDir,
39
+ dirname: projectDirName,
40
+ isCurrentDir: projectDirName === cwdFolder
41
+ }
42
42
  }
@@ -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,95 +1,112 @@
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
-
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
+ exports: {
76
+ ".": {
77
+ "types": "./types/index.d.ts",
78
+ "import": "./esm/index.js",
79
+ "require": "./cjs/index.js"
80
+ },
81
+ "./*": {
82
+ "types": "./types/*.d.ts",
83
+ "import": "./esm/*.js",
84
+ "require": "./cjs/*.js"
85
+ },
86
+ "./types/*": "./types/*.d.ts",
87
+ "./esm/*": "./esm/*.js",
88
+ "./esm/*.js": "./esm/*.js",
89
+ "./cjs/*": "./cjs/*.js",
90
+ "./cjs/*.js": "./cjs/*.js"
91
+ },
92
+ ...packageJson,
93
+ }
94
+
95
+ delete packageJson.type
96
+
97
+ fs.writeFileSync(path.join(process.cwd(), args.outdir, '/package.json'), JSON.stringify(packageJson, null, 2));
98
+
99
+ fs.copyFileSync(path.join(process.cwd(), '/readme.md'), path.join(process.cwd(), args.outdir, `/readme.md`))
100
+ console.log('✅ Production build generated successfully! The package is ready for deployment.');
101
+
102
+ if (args.publish) {
103
+ console.log("Publishing the production build to the npm repository...")
104
+ execSync(`npm publish`, {
105
+ cwd: path.join(process.cwd(), args.outdir)
106
+ })
107
+ } else {
108
+ 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! 🚀`);
109
+ }
110
+ }
111
+
95
112
  export default pack
@@ -1,97 +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
-
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
-
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
+
97
97
  export default serve