create-surf-app 0.1.24 → 0.1.25
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.
|
@@ -3,18 +3,15 @@ import fs from "fs";
|
|
|
3
3
|
import os from "os";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import { fileURLToPath } from "url";
|
|
6
|
-
var DEFAULT_FRONTEND_PORT = "5173";
|
|
7
6
|
var DEFAULT_BACKEND_PORT = "3001";
|
|
8
7
|
async function createSurfApp({
|
|
9
8
|
projectName = ".",
|
|
10
|
-
frontendPort = process.env.VITE_PORT || DEFAULT_FRONTEND_PORT,
|
|
11
9
|
backendPort = process.env.VITE_BACKEND_PORT || DEFAULT_BACKEND_PORT,
|
|
12
10
|
previewBase = process.env.VITE_BASE,
|
|
13
11
|
logger = console.log
|
|
14
12
|
} = {}) {
|
|
15
13
|
const root = path.resolve(projectName);
|
|
16
14
|
const name = path.basename(root);
|
|
17
|
-
const validatedFrontendPort = validatePort("frontend", frontendPort);
|
|
18
15
|
const validatedBackendPort = validatePort("backend", backendPort);
|
|
19
16
|
const templateDir = resolveTemplateDir();
|
|
20
17
|
logger(`
|
|
@@ -22,7 +19,7 @@ async function createSurfApp({
|
|
|
22
19
|
`);
|
|
23
20
|
fs.mkdirSync(root, { recursive: true });
|
|
24
21
|
copyDir(templateDir, root, root, logger);
|
|
25
|
-
writeEnvFiles(root,
|
|
22
|
+
writeEnvFiles(root, validatedBackendPort, previewBase);
|
|
26
23
|
logger(`
|
|
27
24
|
Done! Next steps:
|
|
28
25
|
|
|
@@ -36,7 +33,7 @@ Done! Next steps:
|
|
|
36
33
|
# Start frontend
|
|
37
34
|
cd frontend && npm run dev
|
|
38
35
|
|
|
39
|
-
Open
|
|
36
|
+
Open the local URL printed by Vite
|
|
40
37
|
`);
|
|
41
38
|
return root;
|
|
42
39
|
}
|
|
@@ -72,11 +69,11 @@ function validatePort(label, value) {
|
|
|
72
69
|
}
|
|
73
70
|
return String(port);
|
|
74
71
|
}
|
|
75
|
-
function writeEnvFiles(root,
|
|
72
|
+
function writeEnvFiles(root, backendPort, previewBase) {
|
|
76
73
|
const backendEnvPath = path.join(root, "backend", ".env");
|
|
77
74
|
const frontendEnvPath = path.join(root, "frontend", ".env");
|
|
78
75
|
fs.writeFileSync(backendEnvPath, `PORT=${backendPort}${os.EOL}`);
|
|
79
|
-
let frontendEnv = `
|
|
76
|
+
let frontendEnv = `VITE_BACKEND_PORT=${backendPort}${os.EOL}`;
|
|
80
77
|
if (previewBase) {
|
|
81
78
|
frontendEnv += `VITE_BASE=${previewBase}${os.EOL}`;
|
|
82
79
|
}
|
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import tailwindcss from '@tailwindcss/vite'
|
|
|
5
5
|
|
|
6
6
|
function readRequiredPort(
|
|
7
7
|
env: Record<string, string>,
|
|
8
|
-
name: 'VITE_BACKEND_PORT'
|
|
8
|
+
name: 'VITE_BACKEND_PORT',
|
|
9
9
|
) {
|
|
10
10
|
const value = env[name]
|
|
11
11
|
const port = Number.parseInt(value || '', 10)
|
|
@@ -33,7 +33,6 @@ export default defineConfig(({ mode }) => {
|
|
|
33
33
|
return {
|
|
34
34
|
plugins: [react(), tailwindcss()],
|
|
35
35
|
server: {
|
|
36
|
-
port: readRequiredPort(env, 'VITE_PORT'),
|
|
37
36
|
host: '0.0.0.0',
|
|
38
37
|
proxy: {
|
|
39
38
|
[`${apiBasePrefix}/api`]: backendProxy,
|