makepack 1.5.24 → 1.6.1

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,57 +1,62 @@
1
- // import react from '@vitejs/plugin-react'
2
- import { createServer as createViteServer } from 'vite';
3
- import { logger } from '../../helpers.js'
4
- import makepackConfig from '../../makepack-config.js';
5
-
6
- const viteSetup = async (app) => {
7
- const config = await makepackConfig()
8
- const viteConfig = {
9
- root: process.cwd(),
10
- base: "/",
11
- // plugins: [react()],
12
- server: {
13
- middlewareMode: true,
14
- },
15
- customLogger: {
16
- info: (msg) => {
17
- logger.info(msg)
18
- },
19
- warn: (msg) => logger.warning(msg),
20
- error: (msg) => logger.error(msg),
21
- },
22
- appType: 'custom'
23
- }
24
-
25
- const vite = await createViteServer(viteConfig);
26
- app.use(vite.middlewares);
27
-
28
- app.get('*', async (req, res, next) => {
29
- const url = req.originalUrl;
30
-
31
- try {
32
- let template = await vite.transformIndexHtml(url, `
33
- <!doctype html>
34
- <html lang="en">
35
- <head>
36
- <meta charset="UTF-8" />
37
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
38
- </head>
39
- <body>
40
- <div id="root"></div>
41
- <script type="module" src="${config.start.entry}"></script>
42
- </body>
43
- </html>
44
- `);
45
-
46
- res.status(200).set({
47
- 'Content-Type': 'text/html'
48
- }).end(template);
49
- } catch (e) {
50
- vite.ssrFixStacktrace(e);
51
- next(e);
52
- }
53
- });
54
- }
55
-
56
-
1
+ // import react from '@vitejs/plugin-react'
2
+ import { createServer as createViteServer } from 'vite';
3
+ import { logger } from '../../helpers.js'
4
+ import path from 'path';
5
+ import fs from 'fs';
6
+
7
+ const viteSetup = async (app) => {
8
+ const viteConfig = {
9
+ root: process.cwd(),
10
+ base: "/",
11
+ // plugins: [react()],
12
+ server: {
13
+ middlewareMode: true,
14
+ },
15
+ customLogger: {
16
+ info: (msg) => {
17
+ logger.info(msg)
18
+ },
19
+ warn: (msg) => logger.warning(msg),
20
+ error: (msg) => logger.error(msg),
21
+ },
22
+ appType: 'custom'
23
+ }
24
+
25
+ const vite = await createViteServer(viteConfig);
26
+ app.use(vite.middlewares);
27
+
28
+ // exists tsconfig.json in the root directory
29
+ const isTs = fs.existsSync(path.resolve(process.cwd(), 'tsconfig.json'))
30
+
31
+ let entry = isTs ? '/src/index.ts' : '/src/index.js';
32
+
33
+ app.get('*', async (req, res, next) => {
34
+ const url = req.originalUrl;
35
+
36
+ try {
37
+ let template = await vite.transformIndexHtml(url, `
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="${entry}"></script>
47
+ </body>
48
+ </html>
49
+ `);
50
+
51
+ res.status(200).set({
52
+ 'Content-Type': 'text/html'
53
+ }).end(template);
54
+ } catch (e) {
55
+ vite.ssrFixStacktrace(e);
56
+ next(e);
57
+ }
58
+ });
59
+ }
60
+
61
+
57
62
  export default viteSetup
package/src/helpers.js CHANGED
@@ -1,37 +1,37 @@
1
- import child_process from 'child_process'
2
- import chalk from 'chalk';
3
- import figures from 'figures';
4
-
5
- export const execSync = (command, option = {}) => {
6
- try {
7
- const result = child_process.execSync(command, {
8
- encoding: "utf-8",
9
- stdio: 'inherit',
10
- ...option
11
- });
12
- result && console.log(result);
13
- } catch (error) {
14
- console.error(`Command failed: ${error.message}`);
15
- process.exit(1);
16
- }
17
- };
18
-
19
-
20
-
21
- export const logger = {
22
- info: (message, prefix = 'INFO', icon = true) => {
23
- console.log(`${icon ? chalk.blue(figures.info) + " " : ""}${chalk.cyan.bold(prefix)} ${message}`);
24
- },
25
- success: (message, prefix = 'SUCCESS:', icon = true) => {
26
- console.log(`${icon ? chalk.green(figures.tick) + " " : ""}${chalk.green.bold(prefix)} ${message}`);
27
- },
28
- warning: (message, prefix = 'WARNING:', icon = true) => {
29
- console.log(`${icon ? chalk.yellow(figures.warning) + " " : ""}${chalk.yellow.bold(prefix)} ${message}`);
30
- },
31
- error: (message, prefix = 'ERROR:', icon = true) => {
32
- console.log(`${icon ? chalk.red(figures.cross) + " " : ""}${chalk.red.bold(prefix)} ${message}`);
33
- },
34
- custom: (icon, color, label, message) => {
35
- console.log(`${chalk[color](icon)} ${chalk[color].bold(`${label}:`)} ${message}`);
36
- },
1
+ import child_process from 'child_process'
2
+ import chalk from 'chalk';
3
+ import figures from 'figures';
4
+
5
+ export const execSync = (command, option = {}) => {
6
+ try {
7
+ const result = child_process.execSync(command, {
8
+ encoding: "utf-8",
9
+ stdio: 'inherit',
10
+ ...option
11
+ });
12
+ result && console.log(result);
13
+ } catch (error) {
14
+ console.error(`Command failed: ${error.message}`);
15
+ process.exit(1);
16
+ }
17
+ };
18
+
19
+
20
+
21
+ export const logger = {
22
+ info: (message, prefix = 'INFO', icon = true) => {
23
+ console.log(`${icon ? chalk.blue(figures.info) + " " : ""}${chalk.cyan.bold(prefix)} ${message}`);
24
+ },
25
+ success: (message, prefix = 'SUCCESS:', icon = true) => {
26
+ console.log(`${icon ? chalk.green(figures.tick) + " " : ""}${chalk.green.bold(prefix)} ${message}`);
27
+ },
28
+ warning: (message, prefix = 'WARNING:', icon = true) => {
29
+ console.log(`${icon ? chalk.yellow(figures.warning) + " " : ""}${chalk.yellow.bold(prefix)} ${message}`);
30
+ },
31
+ error: (message, prefix = 'ERROR:', icon = true) => {
32
+ console.log(`${icon ? chalk.red(figures.cross) + " " : ""}${chalk.red.bold(prefix)} ${message}`);
33
+ },
34
+ custom: (icon, color, label, message) => {
35
+ console.log(`${chalk[color](icon)} ${chalk[color].bold(`${label}:`)} ${message}`);
36
+ },
37
37
  };
package/src/index.js CHANGED
@@ -1,33 +1,41 @@
1
- #!/usr/bin/env node
2
-
3
- import { Command } from "commander";
4
- import start from "./actions/start/index.js";
5
- import build from "./actions/build/index.js";
6
- import create from "./actions/create/index.js";
7
- import publish from "./actions/publish/index.js";
8
-
9
- const program = new Command();
10
-
11
- program.name("Makepack").description("Usages");
12
-
13
- program
14
- .command("create")
15
- .description("create a new project")
16
- .action(create);
17
-
18
- program
19
- .command("start")
20
- .description("Start the server")
21
- .action(start);
22
-
23
- program
24
- .command("build")
25
- .description("Build the project")
26
- .action(build);
27
-
28
- program
29
- .command("publish")
30
- .description("Publish it to the npm repository")
31
- .action(publish);
32
-
33
- program.parse();
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from "commander";
4
+ import start from "./actions/start/index.js";
5
+ import build from "./actions/build/index.js";
6
+ import create from "./actions/create/index.js";
7
+ import publish from "./actions/publish/index.js";
8
+
9
+ const program = new Command();
10
+
11
+ program.name("Makepack").description("Usages");
12
+
13
+ program
14
+ .command("create")
15
+ .description("Create a new project")
16
+ .action(create);
17
+
18
+ program
19
+ .command("start")
20
+ .option("-p, --port <port>", "Port to run the server", 3000)
21
+ .description("Start the server")
22
+ .action(start);
23
+
24
+ program
25
+ .command("build")
26
+ .description("Build the project")
27
+ .option("-f, --format <format>", "Output format (cjs, esm, umd, default)", "default")
28
+ .option("-b, --bundle <bundle>", "Bundle the project", false)
29
+ .option("-m, --minify <minify>", "Minify the output", true)
30
+ .option("-s, --sourcemap <sourcemap>", "Generate sourcemaps", true)
31
+ .option("-t, --target <target>", "Target ECMAScript version", "es2020")
32
+ .option("-p, --platform <platform>", "Platform to target (node, browser)", "")
33
+ .option("-d, --declaration <declaration>", "Generate TypeScript declaration files", true)
34
+ .action(build);
35
+
36
+ program
37
+ .command("publish")
38
+ .description("Publish it to the npm repository")
39
+ .action(publish);
40
+
41
+ program.parse();
@@ -1,52 +0,0 @@
1
- export default async (info) => {
2
- let ext = info.template.includes('typescript') ? ".tsx" : ".jsx"
3
- let _import = ''
4
- let _code = ''
5
-
6
- switch (info.template) {
7
- case "typescript":
8
- case "javascript":
9
- _import = `import add from './${info.sourceDir}'`
10
- _code = `<code>{add(5,5)}</code>`
11
- break
12
- case "react with typescript":
13
- case "react with javascript":
14
- _import = `import Count from './${info.sourceDir}'`
15
- _code = `<Count />`
16
- break;
17
- }
18
-
19
- const content = `import React from 'react';
20
- import { createRoot } from 'react-dom/client';
21
- ${_import}
22
-
23
- const App = () => {
24
- return (
25
- <div style={{fontFamily: 'monospace,math, sans-serif', textAlign: 'center', marginTop: '50px' }}>
26
- <h1>Welcome to makepack CLI!</h1>
27
- <p>Edit <code>index.tsx</code> and save to reload.</p>
28
- <a
29
- href="https://reactjs.org"
30
- target="_blank"
31
- rel="noopener noreferrer"
32
- style={{ color: '#61dafb', textDecoration: 'none' }}
33
- >
34
- Learn React
35
- </a>
36
- <div style={{marginTop: "50px"}}>
37
- ${_code}
38
- </div>
39
- </div>
40
- );
41
- }
42
- const rootEle = document.getElementById('root')
43
- if (rootEle) {
44
- const root = createRoot(rootEle);
45
- root.render(<App />);
46
- }
47
- `
48
- return {
49
- content,
50
- filename: `App${ext}`
51
- }
52
- }
@@ -1,55 +0,0 @@
1
- import { loadConfig } from "../../../helpers.js"
2
-
3
- export default async (info) => {
4
- const config = await loadConfig()
5
- let dependencies = {}
6
- let devDependencies = {
7
- "makepack": "latest",
8
- "react": "^19.0.0",
9
- "react-dom": "^19.0.0",
10
- "express": "latest"
11
- }
12
-
13
- if (args.template.includes("typescript")) {
14
- devDependencies["typescript"] = "^4.4.2"
15
- devDependencies["@types/react"] = "^19.0.2"
16
- devDependencies["@types/react-dom"] = "^19.0.2"
17
- devDependencies["@types/express"] = "latest"
18
- }
19
-
20
- let main = args.entry.split('.')
21
- main.pop()
22
-
23
- const json = {
24
- name: args.dirname,
25
- version: "1.0.0",
26
- main: `./${config.build.outdir}/cjs/index.js`,
27
- module: `./${config.build.outdir}/index.js`,
28
- types: `./${config.build.outdir}/index.d.ts`,
29
- description: "",
30
- keywords: [],
31
- exports: {
32
- ".": {
33
- "types": `./${config.build.outdir}/index.d.ts`,
34
- "import": `./${config.build.outdir}/index.js`,
35
- "require": `./${config.build.outdir}/cjs/index.js`
36
- },
37
- "./*": {
38
- "import": `./${config.build.outdir}/*.js`,
39
- "require": `./${config.build.outdir}/cjs/*.js`
40
- }
41
- },
42
- scripts: {
43
- "start": "makepack serve",
44
- "build": "makepack build",
45
- "prepare": "npm run build",
46
- },
47
- dependencies,
48
- devDependencies
49
- }
50
-
51
- return {
52
- content: JSON.stringify(json, null, 3),
53
- filename: "package.json"
54
- }
55
- }
@@ -1,7 +0,0 @@
1
- // express.ts
2
- var expressApp = (app) => {
3
- };
4
- var express_default = expressApp;
5
- export {
6
- express_default as default
7
- };
@@ -1,59 +0,0 @@
1
- import { cosmiconfig } from "cosmiconfig";
2
-
3
- const makepackConfig = async () => {
4
- const explorer = cosmiconfig("makepack");
5
- const configResult = await explorer.search();
6
-
7
- const defaultConfig = {
8
- build: {
9
- outdir: "build",
10
- types: true,
11
- formatPackageJson: (p) => p,
12
- configs: [
13
- {
14
- entryPoints: "src/**/*.{tsx,ts,js,jsx}",
15
- outdir: "",
16
- format: "esm",
17
- sourcemap: true,
18
- minify: true,
19
- jsx: 'automatic',
20
- loader: {
21
- '.ts': 'ts',
22
- '.tsx': 'tsx'
23
- },
24
- },
25
- {
26
- entryPoints: "src/**/*.{tsx,ts,js,jsx}",
27
- outdir: "cjs",
28
- format: "cjs",
29
- sourcemap: true,
30
- minify: true,
31
- jsx: 'automatic',
32
- loader: {
33
- '.ts': 'ts',
34
- '.tsx': 'tsx'
35
- },
36
- }
37
- ]
38
- },
39
- start: {
40
- port: 5000,
41
- entry: "App.tsx",
42
- }
43
- }
44
-
45
- if (configResult && configResult.config) {
46
- let fn = configResult.config;
47
- if (typeof fn === 'function') {
48
- const userConfig = fn(defaultConfig)
49
- if (!userConfig) {
50
- console.log("Config function must return a config object")
51
- process.exit(1)
52
- }
53
- return userConfig
54
- }
55
- }
56
- return defaultConfig
57
- }
58
-
59
- export default makepackConfig