create-weave-backend-app 0.1.0
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.
- package/README.md +11 -0
- package/dist/chunk-HIPWNEQ7.js +366 -0
- package/dist/create-app.d.ts +14 -0
- package/dist/create-app.js +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +120 -0
- package/package.json +66 -0
- package/template/+express+azure-web-pubsub/README.md +38 -0
- package/template/+express+azure-web-pubsub/eslint.config.js +11 -0
- package/template/+express+azure-web-pubsub/example.env +10 -0
- package/template/+express+azure-web-pubsub/example.gitignore +37 -0
- package/template/+express+azure-web-pubsub/src/api/v1/controllers/delImage.ts +22 -0
- package/template/+express+azure-web-pubsub/src/api/v1/controllers/getHealth.ts +5 -0
- package/template/+express+azure-web-pubsub/src/api/v1/controllers/getImage.ts +35 -0
- package/template/+express+azure-web-pubsub/src/api/v1/controllers/getImages.ts +19 -0
- package/template/+express+azure-web-pubsub/src/api/v1/controllers/getRoomConnect.ts +17 -0
- package/template/+express+azure-web-pubsub/src/api/v1/controllers/postRemoveBackground.ts +60 -0
- package/template/+express+azure-web-pubsub/src/api/v1/controllers/postUploadImage.ts +35 -0
- package/template/+express+azure-web-pubsub/src/api/v1/router.ts +46 -0
- package/template/+express+azure-web-pubsub/src/app.ts +32 -0
- package/template/+express+azure-web-pubsub/src/config/config.ts +38 -0
- package/template/+express+azure-web-pubsub/src/constants.ts +1 -0
- package/template/+express+azure-web-pubsub/src/images/persistence.ts +240 -0
- package/template/+express+azure-web-pubsub/src/logger/logger.ts +24 -0
- package/template/+express+azure-web-pubsub/src/middlewares/body-parser.ts +11 -0
- package/template/+express+azure-web-pubsub/src/middlewares/cors.ts +16 -0
- package/template/+express+azure-web-pubsub/src/middlewares/http-logger.ts +13 -0
- package/template/+express+azure-web-pubsub/src/middlewares/http-response-headers.ts +14 -0
- package/template/+express+azure-web-pubsub/src/server.ts +28 -0
- package/template/+express+azure-web-pubsub/src/store.ts +77 -0
- package/template/+express+azure-web-pubsub/src/types.ts +6 -0
- package/template/+express+azure-web-pubsub/src/utils.ts +33 -0
- package/template/+express+azure-web-pubsub/src/validate.ts +22 -0
- package/template/+express+azure-web-pubsub/tsconfig.json +16 -0
- package/template/+express+websockets/README.md +38 -0
- package/template/+express+websockets/eslint.config.js +11 -0
- package/template/+express+websockets/example.env +3 -0
- package/template/+express+websockets/example.gitignore +37 -0
- package/template/+express+websockets/src/api/v1/controllers/delImage.ts +22 -0
- package/template/+express+websockets/src/api/v1/controllers/getHealth.ts +5 -0
- package/template/+express+websockets/src/api/v1/controllers/getImage.ts +35 -0
- package/template/+express+websockets/src/api/v1/controllers/getImages.ts +19 -0
- package/template/+express+websockets/src/api/v1/controllers/getRoomConnect.ts +9 -0
- package/template/+express+websockets/src/api/v1/controllers/postRemoveBackground.ts +60 -0
- package/template/+express+websockets/src/api/v1/controllers/postUploadImage.ts +35 -0
- package/template/+express+websockets/src/api/v1/router.ts +44 -0
- package/template/+express+websockets/src/app.ts +32 -0
- package/template/+express+websockets/src/config/config.ts +38 -0
- package/template/+express+websockets/src/constants.ts +1 -0
- package/template/+express+websockets/src/images/persistence.ts +240 -0
- package/template/+express+websockets/src/logger/logger.ts +24 -0
- package/template/+express+websockets/src/middlewares/body-parser.ts +11 -0
- package/template/+express+websockets/src/middlewares/cors.ts +16 -0
- package/template/+express+websockets/src/middlewares/http-logger.ts +13 -0
- package/template/+express+websockets/src/middlewares/http-response-headers.ts +14 -0
- package/template/+express+websockets/src/server.ts +28 -0
- package/template/+express+websockets/src/store.ts +69 -0
- package/template/+express+websockets/src/types.ts +6 -0
- package/template/+express+websockets/src/utils.ts +33 -0
- package/template/+express+websockets/src/validate.ts +22 -0
- package/template/+express+websockets/tsconfig.json +16 -0
- package/template/package.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
// src/create-app.ts
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
|
|
5
|
+
// src/git.ts
|
|
6
|
+
import { execSync } from "node:child_process";
|
|
7
|
+
import { rmSync } from "node:fs";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
function isInGitRepository(cwd2) {
|
|
10
|
+
try {
|
|
11
|
+
execSync("git rev-parse --is-inside-work-tree", { stdio: "ignore", cwd: cwd2 });
|
|
12
|
+
return true;
|
|
13
|
+
} catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function isInMercurialRepository(cwd2) {
|
|
18
|
+
try {
|
|
19
|
+
execSync("hg --cwd . root", { stdio: "ignore", cwd: cwd2 });
|
|
20
|
+
return true;
|
|
21
|
+
} catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function isDefaultBranchSet(cwd2) {
|
|
26
|
+
try {
|
|
27
|
+
execSync("git config init.defaultBranch", { stdio: "ignore", cwd: cwd2 });
|
|
28
|
+
return true;
|
|
29
|
+
} catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function tryGitInit(root) {
|
|
34
|
+
let didInit = false;
|
|
35
|
+
try {
|
|
36
|
+
execSync("git --version", { stdio: "ignore" });
|
|
37
|
+
if (isInGitRepository(root) || isInMercurialRepository(root)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
execSync("git init", { stdio: "ignore", cwd: root });
|
|
41
|
+
didInit = true;
|
|
42
|
+
if (!isDefaultBranchSet(root)) {
|
|
43
|
+
execSync("git checkout -b main", { stdio: "ignore", cwd: root });
|
|
44
|
+
}
|
|
45
|
+
execSync("git add -A", { stdio: "ignore", cwd: root });
|
|
46
|
+
execSync('git commit -m "Initial commit from Create Fumadocs App"', {
|
|
47
|
+
stdio: "ignore",
|
|
48
|
+
cwd: root
|
|
49
|
+
});
|
|
50
|
+
return true;
|
|
51
|
+
} catch {
|
|
52
|
+
if (didInit) {
|
|
53
|
+
try {
|
|
54
|
+
rmSync(join(root, ".git"), { recursive: true, force: true });
|
|
55
|
+
} catch {
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/versions.js
|
|
63
|
+
var versions = { "@inditextech/weave-types": "0.1.0", "@inditextech/weave-sdk": "0.1.0", "@inditextech/weave-store-websockets": "0.1.0", "@inditextech/weave-store-azure-web-pubsub": "0.1.0", "@inditextech/weave-react": "0.1.0" };
|
|
64
|
+
|
|
65
|
+
// template/package.json
|
|
66
|
+
var package_default = {
|
|
67
|
+
name: "example-versions",
|
|
68
|
+
version: "0.0.0",
|
|
69
|
+
private: true,
|
|
70
|
+
description: "Used to track dependency versions in create-*-app",
|
|
71
|
+
license: "MIT",
|
|
72
|
+
dependencies: {
|
|
73
|
+
"@azure/storage-blob": "^12.26.0",
|
|
74
|
+
"@azure/web-pubsub": "^1.1.4",
|
|
75
|
+
"@azure/web-pubsub-express": "^1.0.6",
|
|
76
|
+
"@imgly/background-removal-node": "^1.4.5",
|
|
77
|
+
"@inditextech/weave-sdk": "0.0.0",
|
|
78
|
+
"@inditextech/weave-store-websockets": "0.0.0",
|
|
79
|
+
"@inditextech/weave-store-azure-web-pubsub": "0.0.0",
|
|
80
|
+
"@inditextech/weave-types": "0.0.0",
|
|
81
|
+
canvas: "^3.1.0",
|
|
82
|
+
cors: "^2.8.5",
|
|
83
|
+
dotenv: "^16.4.7",
|
|
84
|
+
express: "^4.21.2",
|
|
85
|
+
helmet: "^8.0.0",
|
|
86
|
+
morgan: "^1.10.0",
|
|
87
|
+
multer: "^1.4.5-lts.1",
|
|
88
|
+
pino: "^9.6.0",
|
|
89
|
+
"pino-http": "^10.4.0",
|
|
90
|
+
"pino-pretty": "^13.0.0",
|
|
91
|
+
"ts-node": "^10.9.2",
|
|
92
|
+
uuid: "^11.1.0",
|
|
93
|
+
ws: "^8.18.1",
|
|
94
|
+
"y-protocols": "^1.0.6",
|
|
95
|
+
yjs: "^13.6.24",
|
|
96
|
+
zod: "^3.24.2"
|
|
97
|
+
},
|
|
98
|
+
devDependencies: {
|
|
99
|
+
"@eslint/js": "^9.21.0",
|
|
100
|
+
"@types/cors": "^2.8.17",
|
|
101
|
+
"@types/express": "^5.0.0",
|
|
102
|
+
"@types/helmet": "^4.0.0",
|
|
103
|
+
"@types/morgan": "^1.9.9",
|
|
104
|
+
"@types/multer": "^1.4.12",
|
|
105
|
+
"@types/node": "^22.13.5",
|
|
106
|
+
"@types/ws": "^8.18.0",
|
|
107
|
+
"@typescript-eslint/eslint-plugin": "^8.25.0",
|
|
108
|
+
"@typescript-eslint/parser": "^8.25.0",
|
|
109
|
+
commitlint: "^19.7.1",
|
|
110
|
+
eslint: "^9.21.0",
|
|
111
|
+
globals: "^16.0.0",
|
|
112
|
+
nodemon: "^3.1.9",
|
|
113
|
+
prettier: "^3.5.2",
|
|
114
|
+
"prettier-eslint": "^16.3.0",
|
|
115
|
+
"tsconfig-paths": "^4.2.0",
|
|
116
|
+
tsx: "^4.19.3",
|
|
117
|
+
typescript: "^5.7.3",
|
|
118
|
+
"typescript-eslint": "^8.25.0"
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// src/auto-install.ts
|
|
123
|
+
import { spawn } from "cross-spawn";
|
|
124
|
+
function getPackageManager() {
|
|
125
|
+
const userAgent = process.env.npm_config_user_agent ?? "";
|
|
126
|
+
if (userAgent.startsWith("yarn")) {
|
|
127
|
+
return "yarn";
|
|
128
|
+
}
|
|
129
|
+
if (userAgent.startsWith("pnpm")) {
|
|
130
|
+
return "pnpm";
|
|
131
|
+
}
|
|
132
|
+
if (userAgent.startsWith("bun")) {
|
|
133
|
+
return "bun";
|
|
134
|
+
}
|
|
135
|
+
return "npm";
|
|
136
|
+
}
|
|
137
|
+
function autoInstall(manager, dest) {
|
|
138
|
+
return new Promise((res, reject) => {
|
|
139
|
+
const installProcess = spawn(manager, ["install"], {
|
|
140
|
+
stdio: "ignore",
|
|
141
|
+
env: {
|
|
142
|
+
...process.env,
|
|
143
|
+
NODE_ENV: "development",
|
|
144
|
+
DISABLE_OPENCOLLECTIVE: "1"
|
|
145
|
+
},
|
|
146
|
+
cwd: dest
|
|
147
|
+
});
|
|
148
|
+
installProcess.on("close", (code) => {
|
|
149
|
+
if (code !== 0) {
|
|
150
|
+
reject(new Error("Install failed"));
|
|
151
|
+
} else {
|
|
152
|
+
res();
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/constants.ts
|
|
159
|
+
import { fileURLToPath } from "node:url";
|
|
160
|
+
var sourceDir = fileURLToPath(new URL(`../`, import.meta.url).href);
|
|
161
|
+
var cwd = process.cwd();
|
|
162
|
+
|
|
163
|
+
// src/create-app.ts
|
|
164
|
+
async function create(options) {
|
|
165
|
+
const {
|
|
166
|
+
installDeps = true,
|
|
167
|
+
initializeGit = true,
|
|
168
|
+
log = console.log
|
|
169
|
+
} = options;
|
|
170
|
+
const projectName = path.basename(options.outputDir);
|
|
171
|
+
const dest = path.resolve(cwd, options.outputDir);
|
|
172
|
+
function defaultRename(file) {
|
|
173
|
+
file = file.replace("example.gitignore", ".gitignore");
|
|
174
|
+
file = file.replace("example.env", ".env");
|
|
175
|
+
return file;
|
|
176
|
+
}
|
|
177
|
+
await copy(
|
|
178
|
+
path.join(sourceDir, `template/${options.template}`),
|
|
179
|
+
dest,
|
|
180
|
+
defaultRename
|
|
181
|
+
);
|
|
182
|
+
const tsconfigPath = path.join(dest, "tsconfig.json");
|
|
183
|
+
const content = (await fs.readFile(tsconfigPath)).toString();
|
|
184
|
+
const config = JSON.parse(content);
|
|
185
|
+
if (config.compilerOptions?.paths) {
|
|
186
|
+
Object.assign(config.compilerOptions.paths, {
|
|
187
|
+
"@/*": ["./src/*"]
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
await fs.writeFile(tsconfigPath, JSON.stringify(config, null, 2));
|
|
191
|
+
const packageJson = createPackageJson(projectName, options);
|
|
192
|
+
await fs.writeFile(
|
|
193
|
+
path.join(dest, "package.json"),
|
|
194
|
+
JSON.stringify(packageJson, null, 2)
|
|
195
|
+
);
|
|
196
|
+
const readMe = await getReadme(dest, projectName);
|
|
197
|
+
await fs.writeFile(path.join(dest, "README.md"), readMe);
|
|
198
|
+
if (installDeps) {
|
|
199
|
+
await autoInstall(options.packageManager, dest);
|
|
200
|
+
log("Installed dependencies");
|
|
201
|
+
}
|
|
202
|
+
if (initializeGit && tryGitInit(dest)) {
|
|
203
|
+
log("Initialized Git repository");
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
async function getReadme(dest, projectName) {
|
|
207
|
+
const template = await fs.readFile(path.join(dest, "README.md")).then((res) => res.toString());
|
|
208
|
+
return `# ${projectName}
|
|
209
|
+
|
|
210
|
+
${template}`;
|
|
211
|
+
}
|
|
212
|
+
async function copy(from, to, rename = (s) => s) {
|
|
213
|
+
const stats = await fs.stat(from);
|
|
214
|
+
if (stats.isDirectory()) {
|
|
215
|
+
const files = await fs.readdir(from);
|
|
216
|
+
await Promise.all(
|
|
217
|
+
files.map(
|
|
218
|
+
(file) => copy(path.join(from, file), rename(path.join(to, file)))
|
|
219
|
+
)
|
|
220
|
+
);
|
|
221
|
+
} else {
|
|
222
|
+
await fs.mkdir(path.dirname(to), { recursive: true });
|
|
223
|
+
await fs.copyFile(from, to);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function createPackageJson(projectName, options) {
|
|
227
|
+
if (options.template === "+express+azure-web-pubsub") {
|
|
228
|
+
return {
|
|
229
|
+
name: projectName,
|
|
230
|
+
type: "module",
|
|
231
|
+
scripts: {
|
|
232
|
+
build: "tsc && mkdir -p ./dist/public && mkdir -p ./dist/temp && cp -r ./public ./dist",
|
|
233
|
+
copyAssets: "mkdir -p ./public && cp -r node_modules/@imgly/background-removal-node/dist/. public",
|
|
234
|
+
dev: 'nodemon --exec "tsx --env-file=.env src/server.ts"',
|
|
235
|
+
postinstall: "npm run copyAssets",
|
|
236
|
+
start: "node --experimental-specifier-resolution=node --env-file=.env --loader ts-node/esm dist/server.js"
|
|
237
|
+
},
|
|
238
|
+
private: true,
|
|
239
|
+
dependencies: {
|
|
240
|
+
...pick(versions, [
|
|
241
|
+
"@inditextech/weave-types",
|
|
242
|
+
"@inditextech/weave-sdk",
|
|
243
|
+
"@inditextech/weave-store-azure-web-pubsub"
|
|
244
|
+
]),
|
|
245
|
+
...pick(package_default.dependencies, [
|
|
246
|
+
"@imgly/background-removal-node",
|
|
247
|
+
"canvas",
|
|
248
|
+
"cors",
|
|
249
|
+
"dotenv",
|
|
250
|
+
"express",
|
|
251
|
+
"helmet",
|
|
252
|
+
"morgan",
|
|
253
|
+
"multer",
|
|
254
|
+
"pino",
|
|
255
|
+
"pino-http",
|
|
256
|
+
"pino-pretty",
|
|
257
|
+
"ts-node",
|
|
258
|
+
"uuid",
|
|
259
|
+
"ws",
|
|
260
|
+
"y-protocols",
|
|
261
|
+
"yjs",
|
|
262
|
+
"zod"
|
|
263
|
+
])
|
|
264
|
+
},
|
|
265
|
+
devDependencies: pick(package_default.devDependencies, [
|
|
266
|
+
"@eslint/js",
|
|
267
|
+
"@types/cors",
|
|
268
|
+
"@types/express",
|
|
269
|
+
"@types/helmet",
|
|
270
|
+
"@types/morgan",
|
|
271
|
+
"@types/multer",
|
|
272
|
+
"@types/node",
|
|
273
|
+
"@types/ws",
|
|
274
|
+
"@typescript-eslint/eslint-plugin",
|
|
275
|
+
"@typescript-eslint/parser",
|
|
276
|
+
"eslint",
|
|
277
|
+
"globals",
|
|
278
|
+
"nodemon",
|
|
279
|
+
"prettier",
|
|
280
|
+
"prettier-eslint",
|
|
281
|
+
"tsconfig-paths",
|
|
282
|
+
"tsx",
|
|
283
|
+
"typescript",
|
|
284
|
+
"typescript-eslint"
|
|
285
|
+
])
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
return {
|
|
289
|
+
name: projectName,
|
|
290
|
+
version: "0.0.0",
|
|
291
|
+
private: true,
|
|
292
|
+
scripts: {
|
|
293
|
+
build: "tsc && mkdir -p ./dist/public && mkdir -p ./dist/temp && cp -r ./public ./dist",
|
|
294
|
+
copyAssets: "mkdir -p ./public && cp -r node_modules/@imgly/background-removal-node/dist/. public",
|
|
295
|
+
dev: 'nodemon --exec "tsx --env-file=.env src/server.ts"',
|
|
296
|
+
postinstall: "npm run copyAssets",
|
|
297
|
+
start: "node --experimental-specifier-resolution=node --env-file=.env --loader ts-node/esm dist/server.js"
|
|
298
|
+
},
|
|
299
|
+
dependencies: {
|
|
300
|
+
...pick(package_default.dependencies, [
|
|
301
|
+
"@azure/web-pubsub",
|
|
302
|
+
"@azure/web-pubsub-express",
|
|
303
|
+
"@imgly/background-removal-node",
|
|
304
|
+
"canvas",
|
|
305
|
+
"cors",
|
|
306
|
+
"dotenv",
|
|
307
|
+
"express",
|
|
308
|
+
"helmet",
|
|
309
|
+
"morgan",
|
|
310
|
+
"multer",
|
|
311
|
+
"pino",
|
|
312
|
+
"pino-http",
|
|
313
|
+
"pino-pretty",
|
|
314
|
+
"ts-node",
|
|
315
|
+
"uuid",
|
|
316
|
+
"ws",
|
|
317
|
+
"y-protocols",
|
|
318
|
+
"yjs",
|
|
319
|
+
"zod"
|
|
320
|
+
]),
|
|
321
|
+
...pick(versions, [
|
|
322
|
+
"@inditextech/weave-types",
|
|
323
|
+
"@inditextech/weave-sdk",
|
|
324
|
+
"@inditextech/weave-store-websockets"
|
|
325
|
+
])
|
|
326
|
+
},
|
|
327
|
+
devDependencies: {
|
|
328
|
+
...pick(package_default.devDependencies, [
|
|
329
|
+
"@eslint/js",
|
|
330
|
+
"@types/cors",
|
|
331
|
+
"@types/express",
|
|
332
|
+
"@types/helmet",
|
|
333
|
+
"@types/morgan",
|
|
334
|
+
"@types/multer",
|
|
335
|
+
"@types/node",
|
|
336
|
+
"@types/ws",
|
|
337
|
+
"@typescript-eslint/eslint-plugin",
|
|
338
|
+
"@typescript-eslint/parser",
|
|
339
|
+
"eslint",
|
|
340
|
+
"globals",
|
|
341
|
+
"nodemon",
|
|
342
|
+
"prettier",
|
|
343
|
+
"prettier-eslint",
|
|
344
|
+
"tsconfig-paths",
|
|
345
|
+
"tsx",
|
|
346
|
+
"typescript",
|
|
347
|
+
"typescript-eslint"
|
|
348
|
+
])
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
function pick(obj, keys) {
|
|
353
|
+
const result = {};
|
|
354
|
+
for (const key of keys) {
|
|
355
|
+
if (key in obj) {
|
|
356
|
+
result[key] = obj[key];
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return result;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export {
|
|
363
|
+
getPackageManager,
|
|
364
|
+
cwd,
|
|
365
|
+
create
|
|
366
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun';
|
|
2
|
+
|
|
3
|
+
type Template = '+express+websockets' | '+express+azure-web-pubsub';
|
|
4
|
+
interface Options {
|
|
5
|
+
outputDir: string;
|
|
6
|
+
template: Template;
|
|
7
|
+
packageManager: PackageManager;
|
|
8
|
+
installDeps?: boolean;
|
|
9
|
+
initializeGit?: boolean;
|
|
10
|
+
log?: (message: string) => void;
|
|
11
|
+
}
|
|
12
|
+
declare function create(options: Options): Promise<void>;
|
|
13
|
+
|
|
14
|
+
export { type Options, type Template, create };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
create,
|
|
4
|
+
cwd,
|
|
5
|
+
getPackageManager
|
|
6
|
+
} from "./chunk-HIPWNEQ7.js";
|
|
7
|
+
|
|
8
|
+
// src/index.ts
|
|
9
|
+
import fs from "node:fs/promises";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import {
|
|
12
|
+
cancel,
|
|
13
|
+
confirm,
|
|
14
|
+
group,
|
|
15
|
+
intro,
|
|
16
|
+
isCancel,
|
|
17
|
+
outro,
|
|
18
|
+
select,
|
|
19
|
+
spinner,
|
|
20
|
+
text
|
|
21
|
+
} from "@clack/prompts";
|
|
22
|
+
import pc from "picocolors";
|
|
23
|
+
var manager = getPackageManager();
|
|
24
|
+
async function main() {
|
|
25
|
+
intro(pc.bgCyan(pc.bold("Create Weave.js Backend Service")));
|
|
26
|
+
const options = await group(
|
|
27
|
+
{
|
|
28
|
+
name: () => text({
|
|
29
|
+
message: "Project name",
|
|
30
|
+
placeholder: "my-service",
|
|
31
|
+
defaultValue: "my-service"
|
|
32
|
+
}),
|
|
33
|
+
template: () => select({
|
|
34
|
+
message: "Choose a template",
|
|
35
|
+
initialValue: "+express+websockets",
|
|
36
|
+
options: [
|
|
37
|
+
{
|
|
38
|
+
value: "+express+websockets",
|
|
39
|
+
label: "Express.js: Weave.js Websockets Store",
|
|
40
|
+
hint: "recommended"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
value: "+express+azure-web-pubsub",
|
|
44
|
+
label: "Express.js: Weave.js Azure Web PubSub Store"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}),
|
|
48
|
+
// src: (v) => {
|
|
49
|
+
// if (!v.results.template?.startsWith('+next')) return;
|
|
50
|
+
// return confirm({
|
|
51
|
+
// message: 'Use `/src` directory?',
|
|
52
|
+
// initialValue: false,
|
|
53
|
+
// });
|
|
54
|
+
// },
|
|
55
|
+
// eslint: (v) => {
|
|
56
|
+
// if (!v.results.template?.startsWith('+next')) return;
|
|
57
|
+
// return confirm({
|
|
58
|
+
// message: 'Add default ESLint configuration?',
|
|
59
|
+
// initialValue: false,
|
|
60
|
+
// });
|
|
61
|
+
// },
|
|
62
|
+
installDeps: () => confirm({
|
|
63
|
+
message: `Do you want to install packages automatically? (detected as ${manager})`
|
|
64
|
+
})
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
onCancel: () => {
|
|
68
|
+
cancel("Installation Stopped.");
|
|
69
|
+
process.exit(0);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
const projectName = options.name.toLowerCase().replace(/\s/, "-");
|
|
74
|
+
const dest = path.resolve(cwd, projectName);
|
|
75
|
+
const destDir = await fs.readdir(dest).catch(() => null);
|
|
76
|
+
if (destDir && destDir.length > 0) {
|
|
77
|
+
const del = await confirm({
|
|
78
|
+
message: `directory ${projectName} already exists, do you want to delete its files?`
|
|
79
|
+
});
|
|
80
|
+
if (isCancel(del)) {
|
|
81
|
+
cancel();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (del) {
|
|
85
|
+
const info2 = spinner();
|
|
86
|
+
info2.start(`Deleting files in ${projectName}`);
|
|
87
|
+
await Promise.all(
|
|
88
|
+
destDir.map((item) => {
|
|
89
|
+
return fs.rm(path.join(dest, item), {
|
|
90
|
+
recursive: true,
|
|
91
|
+
force: true
|
|
92
|
+
});
|
|
93
|
+
})
|
|
94
|
+
);
|
|
95
|
+
info2.stop(`Deleted files in ${projectName}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const info = spinner();
|
|
99
|
+
info.start(`Generating Project`);
|
|
100
|
+
await create({
|
|
101
|
+
packageManager: manager,
|
|
102
|
+
template: options.template,
|
|
103
|
+
outputDir: dest,
|
|
104
|
+
installDeps: options.installDeps,
|
|
105
|
+
log: (message) => {
|
|
106
|
+
info.message(message);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
info.stop("Project Generated");
|
|
110
|
+
outro(pc.bgGreen(pc.bold("Done")));
|
|
111
|
+
console.log(pc.bold("\nOpen the project"));
|
|
112
|
+
console.log(pc.cyan(`cd ${projectName}`));
|
|
113
|
+
console.log(pc.bold("\nRun Development Server"));
|
|
114
|
+
console.log(pc.cyan("npm run dev | pnpm run dev | yarn dev"));
|
|
115
|
+
process.exit(0);
|
|
116
|
+
}
|
|
117
|
+
main().catch((e) => {
|
|
118
|
+
console.error(e);
|
|
119
|
+
throw e;
|
|
120
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-weave-backend-app",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Create a new backend artifact for site with Weave.js",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"NextJs",
|
|
7
|
+
"next",
|
|
8
|
+
"react",
|
|
9
|
+
"Weave.js"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://inditextech.github.io/weavejs",
|
|
12
|
+
"repository": "github:InditexTech/weavejs",
|
|
13
|
+
"license": "Apache-2.0",
|
|
14
|
+
"author": "Jesus Manuel Piñeiro Cid <jesusmpc@inditex.com>",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"bin": "./dist/index.js",
|
|
17
|
+
"module": "./dist/create-app.js",
|
|
18
|
+
"types": "./dist/create-app.d.ts",
|
|
19
|
+
"files": [
|
|
20
|
+
"template/*",
|
|
21
|
+
"dist/*"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsup",
|
|
25
|
+
"bump:snapshot": "npm version $npm_package_version.$(date \"+%s\")",
|
|
26
|
+
"clean": "rimraf dist",
|
|
27
|
+
"dev": "tsup --watch",
|
|
28
|
+
"link": "npm link",
|
|
29
|
+
"lint:fix": "npm run lint -- --fix",
|
|
30
|
+
"lint": "eslint ./src",
|
|
31
|
+
"publish:snapshot": "npm publish",
|
|
32
|
+
"release:perform": "npm publish --access public",
|
|
33
|
+
"release:prepare": "npm run verify",
|
|
34
|
+
"test": "echo \"No tests defined\" && exit 0",
|
|
35
|
+
"types:check": "tsc --noEmit",
|
|
36
|
+
"verify": "npm run lint && npm run test && npm run build",
|
|
37
|
+
"version:development": "npm version $(npm version minor)-SNAPSHOT",
|
|
38
|
+
"version:release": "npm version $RELEASE_VERSION -m \"[npm-scripts] prepare release $RELEASE_VERSION\" --tag-version-prefix \"\""
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@clack/prompts": "^0.10.1",
|
|
42
|
+
"cross-spawn": "^7.0.6",
|
|
43
|
+
"picocolors": "^1.1.1"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/cross-spawn": "^6.0.6",
|
|
47
|
+
"@types/node": "22.14.1",
|
|
48
|
+
"fast-glob": "^3.3.3",
|
|
49
|
+
"tsup": "8.4.0"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": "^18.12 || ^20.11 || ^22.11"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public"
|
|
56
|
+
},
|
|
57
|
+
"nx": {
|
|
58
|
+
"implicitDependencies": [
|
|
59
|
+
"@inditextech/weave-react",
|
|
60
|
+
"@inditextech/weave-sdk",
|
|
61
|
+
"@inditextech/weave-store-azure-web-pubsub",
|
|
62
|
+
"@inditextech/weave-store-websockets",
|
|
63
|
+
"@inditextech/weave-types"
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Weave.js Backend start template
|
|
2
|
+
|
|
3
|
+
This is an Express.js application that was generated with **Create Weave.js Backend**
|
|
4
|
+
|
|
5
|
+
This server setup the Weave.js
|
|
6
|
+
[Azure Web Pubsub store](https://inditextech.github.io/weavejs/docs/main/build/stores/azure-web-pubsub-store) store. So before perform the quickstart please setup on the `.env` file the configuration for your Azure Web Pubsub instance.
|
|
7
|
+
|
|
8
|
+
## Quickstart
|
|
9
|
+
|
|
10
|
+
If you skipped the automatic installation of the dependencies, run first this
|
|
11
|
+
command:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install
|
|
15
|
+
# or
|
|
16
|
+
pnpm install
|
|
17
|
+
# or
|
|
18
|
+
yarn install
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Now, lets run the development server:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm run dev
|
|
25
|
+
# or
|
|
26
|
+
pnpm dev
|
|
27
|
+
# or
|
|
28
|
+
yarn dev
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Learn more
|
|
32
|
+
|
|
33
|
+
To learn more about Express.js and Weave.js, take a look at the following
|
|
34
|
+
resources:
|
|
35
|
+
|
|
36
|
+
- [Express.js](https://expressjs.com/) - learn about Express.js
|
|
37
|
+
- [Weave.js](https://inditextech.github.io/weavejs) - learn about Weave.js
|
|
38
|
+
- [Weave.js repository](https://github.com/InditexTech/weavejs) - check out out code.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import globals from "globals";
|
|
2
|
+
import pluginJs from "@eslint/js";
|
|
3
|
+
import tseslint from "typescript-eslint";
|
|
4
|
+
|
|
5
|
+
/** @type {import('eslint').Linter.Config[]} */
|
|
6
|
+
export default [
|
|
7
|
+
{files: ["**/*.{js,mjs,cjs,ts}"], ignores: ["dist/**/*"],},
|
|
8
|
+
{languageOptions: { globals: globals.node }},
|
|
9
|
+
pluginJs.configs.recommended,
|
|
10
|
+
...tseslint.configs.recommended,
|
|
11
|
+
];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
HOSTNAME=0.0.0.0
|
|
2
|
+
PORT=8080
|
|
3
|
+
LOG_LEVEL=debug
|
|
4
|
+
|
|
5
|
+
// Endpoint for the Azure Web PubSub service
|
|
6
|
+
WEAVE_AZURE_WEB_PUBSUB_ENDPOINT=<your-endpoint>
|
|
7
|
+
// Secret key for the Azure Web PubSub service
|
|
8
|
+
WEAVE_AZURE_WEB_PUBSUB_KEY=<your-key>
|
|
9
|
+
// Name of the Hub for the Azure Web PubSub service
|
|
10
|
+
WEAVE_AZURE_WEB_PUBSUB_HUB_NAME=<your-hub-name>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Logs
|
|
2
|
+
logs
|
|
3
|
+
*.log
|
|
4
|
+
npm-debug.log*
|
|
5
|
+
yarn-debug.log*
|
|
6
|
+
yarn-error.log*
|
|
7
|
+
pnpm-debug.log*
|
|
8
|
+
lerna-debug.log*
|
|
9
|
+
reports
|
|
10
|
+
|
|
11
|
+
node_modules
|
|
12
|
+
dist
|
|
13
|
+
dist-ssr
|
|
14
|
+
*.local
|
|
15
|
+
vite.config.ts*
|
|
16
|
+
!vite.config.ts
|
|
17
|
+
|
|
18
|
+
# Editor directories and files
|
|
19
|
+
.vscode/*
|
|
20
|
+
!.vscode/extensions.json
|
|
21
|
+
.idea
|
|
22
|
+
.DS_Store
|
|
23
|
+
*.suo
|
|
24
|
+
*.ntvs*
|
|
25
|
+
*.njsproj
|
|
26
|
+
*.sln
|
|
27
|
+
*.sw?
|
|
28
|
+
|
|
29
|
+
*.pem
|
|
30
|
+
.env*
|
|
31
|
+
.npmrc
|
|
32
|
+
|
|
33
|
+
images
|
|
34
|
+
images-mimetype
|
|
35
|
+
rooms
|
|
36
|
+
temp
|
|
37
|
+
public
|