@monodog/backend 1.1.4 ā 1.1.6
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.
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This script runs automatically after 'pnpm install' to ensure the necessary
|
|
3
|
+
// workspace directories are set up for the customer.
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const packagesToCreate = ['backend', 'frontend'];
|
|
11
|
+
/**
|
|
12
|
+
* Creates a minimal package.json and index.js for a new workspace.
|
|
13
|
+
* @param workspaceName - The name of the workspace (e.g., 'backend').
|
|
14
|
+
*/
|
|
15
|
+
function createMinimalWorkspace(workspaceName) {
|
|
16
|
+
const packageDir = path_1.default.join(process.cwd(), 'packages', workspaceName);
|
|
17
|
+
const packageJsonPath = path_1.default.join(packageDir, 'package.json');
|
|
18
|
+
const indexJsPath = path_1.default.join(packageDir, 'index.js');
|
|
19
|
+
// 1. Create the directory structure
|
|
20
|
+
if (!fs_1.default.existsSync(packageDir)) {
|
|
21
|
+
console.log(`\nā
Creating essential workspace directory: packages/${workspaceName}`);
|
|
22
|
+
fs_1.default.mkdirSync(packageDir, { recursive: true });
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
// If it exists, we assume the customer has already populated it.
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// 2. Define package.json content
|
|
29
|
+
const packageJsonContent = JSON.stringify({
|
|
30
|
+
name: workspaceName,
|
|
31
|
+
version: '1.0.0',
|
|
32
|
+
description: `Source code for the ${workspaceName} service.`,
|
|
33
|
+
scripts: {
|
|
34
|
+
// Placeholder scripts for the customer to use
|
|
35
|
+
start: `node index.js`,
|
|
36
|
+
dev: `echo "Starting ${workspaceName}..." && node index.js`,
|
|
37
|
+
},
|
|
38
|
+
// We can pre-add common dev dependencies here if necessary
|
|
39
|
+
devDependencies: {
|
|
40
|
+
// Example:
|
|
41
|
+
// typescript: '^5.0.0',
|
|
42
|
+
},
|
|
43
|
+
}, null, 2);
|
|
44
|
+
// 3. Write package.json
|
|
45
|
+
console.log(`š Writing minimal package.json for ${workspaceName}...`);
|
|
46
|
+
fs_1.default.writeFileSync(packageJsonPath, packageJsonContent, { encoding: 'utf8' });
|
|
47
|
+
// 4. Write a placeholder file
|
|
48
|
+
const indexJsContent = `console.log('Hello from the packages/${workspaceName} workspace!');`;
|
|
49
|
+
console.log('š Writing placeholder index.js...');
|
|
50
|
+
fs_1.default.writeFileSync(indexJsPath, indexJsContent, { encoding: 'utf8' });
|
|
51
|
+
}
|
|
52
|
+
function setupTemplate() {
|
|
53
|
+
console.log('\n--- Template Initializer (Running via postinstall) ---');
|
|
54
|
+
// 1. Ensure the packages directory exists
|
|
55
|
+
const packagesRoot = path_1.default.join(process.cwd(), 'packages');
|
|
56
|
+
if (!fs_1.default.existsSync(packagesRoot)) {
|
|
57
|
+
fs_1.default.mkdirSync(packagesRoot, { recursive: true });
|
|
58
|
+
}
|
|
59
|
+
// 2. Create default workspaces
|
|
60
|
+
packagesToCreate.forEach(createMinimalWorkspace);
|
|
61
|
+
console.log('\n⨠Initial template setup complete. Packages are ready to be developed.');
|
|
62
|
+
// Note: pnpm install has already run when this script executes,
|
|
63
|
+
// so no need to run 'pnpm install' again.
|
|
64
|
+
}
|
|
65
|
+
setupTemplate();
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monodog/backend",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"description": "Backend API server for monodog monorepo dashboard",
|
|
5
|
-
"main": "dist/
|
|
5
|
+
"main": "dist/setup-workspace.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"bin": {
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"clean": "rm -rf dist node_modules/.cache",
|
|
20
20
|
"test:coverage": "jest --coverage",
|
|
21
21
|
"lint": "eslint .",
|
|
22
|
-
"lint:fix": "eslint . --fix"
|
|
22
|
+
"lint:fix": "eslint . --fix",
|
|
23
|
+
"postinstall": "pnpm run build && node dist/setup-workspace.js"
|
|
23
24
|
},
|
|
24
25
|
"dependencies": {
|
|
25
26
|
"@prisma/client": "^5.7.0",
|
|
@@ -28,13 +29,13 @@
|
|
|
28
29
|
"express": "^4.18.2",
|
|
29
30
|
"@monodog/ci-status": "1.1.1",
|
|
30
31
|
"@monodog/monorepo-scanner": "1.0.1",
|
|
31
|
-
"@monodog/utils": "1.0.0"
|
|
32
|
+
"@monodog/utils": "1.0.0",
|
|
33
|
+
"prisma": "^5.22.0"
|
|
32
34
|
},
|
|
33
35
|
"devDependencies": {
|
|
34
36
|
"@types/cors": "^2.8.17",
|
|
35
37
|
"@types/express": "^4.17.21",
|
|
36
38
|
"@types/node": "^20.10.0",
|
|
37
|
-
"prisma": "^5.22.0",
|
|
38
39
|
"tsx": "^4.6.0",
|
|
39
40
|
"typescript": "^5.3.0"
|
|
40
41
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
console.log('Hello from the packages/backend workspace!');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
console.log('Hello from the packages/frontend workspace!');
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// This script runs automatically after 'pnpm install' to ensure the necessary
|
|
2
|
+
// workspace directories are set up for the customer.
|
|
3
|
+
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { execSync } from 'child_process';
|
|
7
|
+
|
|
8
|
+
const packagesToCreate: string[] = ['backend', 'frontend'];
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Creates a minimal package.json and index.js for a new workspace.
|
|
12
|
+
* @param workspaceName - The name of the workspace (e.g., 'backend').
|
|
13
|
+
*/
|
|
14
|
+
function createMinimalWorkspace(workspaceName: string): void {
|
|
15
|
+
const packageDir = path.join(process.cwd(), 'packages', workspaceName);
|
|
16
|
+
const packageJsonPath = path.join(packageDir, 'package.json');
|
|
17
|
+
const indexJsPath = path.join(packageDir, 'index.js');
|
|
18
|
+
|
|
19
|
+
// 1. Create the directory structure
|
|
20
|
+
if (!fs.existsSync(packageDir)) {
|
|
21
|
+
console.log(`\nā
Creating essential workspace directory: packages/${workspaceName}`);
|
|
22
|
+
fs.mkdirSync(packageDir, { recursive: true });
|
|
23
|
+
} else {
|
|
24
|
+
// If it exists, we assume the customer has already populated it.
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 2. Define package.json content
|
|
29
|
+
const packageJsonContent = JSON.stringify({
|
|
30
|
+
name: workspaceName,
|
|
31
|
+
version: '1.0.0',
|
|
32
|
+
description: `Source code for the ${workspaceName} service.`,
|
|
33
|
+
scripts: {
|
|
34
|
+
// Placeholder scripts for the customer to use
|
|
35
|
+
start: `node index.js`,
|
|
36
|
+
dev: `echo "Starting ${workspaceName}..." && node index.js`,
|
|
37
|
+
},
|
|
38
|
+
// We can pre-add common dev dependencies here if necessary
|
|
39
|
+
devDependencies: {
|
|
40
|
+
// Example:
|
|
41
|
+
// typescript: '^5.0.0',
|
|
42
|
+
},
|
|
43
|
+
}, null, 2);
|
|
44
|
+
|
|
45
|
+
// 3. Write package.json
|
|
46
|
+
console.log(`š Writing minimal package.json for ${workspaceName}...`);
|
|
47
|
+
fs.writeFileSync(packageJsonPath, packageJsonContent, { encoding: 'utf8' });
|
|
48
|
+
|
|
49
|
+
// 4. Write a placeholder file
|
|
50
|
+
const indexJsContent = `console.log('Hello from the packages/${workspaceName} workspace!');`;
|
|
51
|
+
console.log('š Writing placeholder index.js...');
|
|
52
|
+
fs.writeFileSync(indexJsPath, indexJsContent, { encoding: 'utf8' });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function setupTemplate(): void {
|
|
56
|
+
console.log('\n--- Template Initializer (Running via postinstall) ---');
|
|
57
|
+
|
|
58
|
+
// 1. Ensure the packages directory exists
|
|
59
|
+
const packagesRoot = path.join(process.cwd(), 'packages');
|
|
60
|
+
if (!fs.existsSync(packagesRoot)) {
|
|
61
|
+
fs.mkdirSync(packagesRoot, { recursive: true });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 2. Create default workspaces
|
|
65
|
+
packagesToCreate.forEach(createMinimalWorkspace);
|
|
66
|
+
|
|
67
|
+
console.log('\n⨠Initial template setup complete. Packages are ready to be developed.');
|
|
68
|
+
|
|
69
|
+
// Note: pnpm install has already run when this script executes,
|
|
70
|
+
// so no need to run 'pnpm install' again.
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
setupTemplate();
|