create-momentum-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/LICENSE +21 -0
- package/README.md +33 -0
- package/index.cjs +222 -0
- package/package.json +69 -0
- package/templates/analog/eslint.config.mjs +9 -0
- package/templates/analog/index.html +25 -0
- package/templates/analog/package.json.tmpl +47 -0
- package/templates/analog/postcss.config.cjs +6 -0
- package/templates/analog/src/app/app.config.server.ts +7 -0
- package/templates/analog/src/app/app.config.ts +27 -0
- package/templates/analog/src/app/app.ts +9 -0
- package/templates/analog/src/collections/posts.ts +16 -0
- package/templates/analog/src/main.server.ts +6 -0
- package/templates/analog/src/main.ts +5 -0
- package/templates/analog/src/momentum.config.ts.tmpl +50 -0
- package/templates/analog/src/server/middleware/00-init.ts +13 -0
- package/templates/analog/src/server/routes/api/[...momentum].ts +73 -0
- package/templates/analog/src/server/utils/momentum-init.ts.tmpl +87 -0
- package/templates/analog/src/styles.css +140 -0
- package/templates/analog/tailwind.config.ts +12 -0
- package/templates/analog/tsconfig.app.json +9 -0
- package/templates/analog/tsconfig.json +26 -0
- package/templates/analog/vite.config.ts.tmpl +19 -0
- package/templates/angular/angular.json.tmpl +71 -0
- package/templates/angular/eslint.config.mjs +31 -0
- package/templates/angular/package.json.tmpl +47 -0
- package/templates/angular/postcss.config.js +6 -0
- package/templates/angular/src/app/app.config.server.ts +7 -0
- package/templates/angular/src/app/app.config.ts +14 -0
- package/templates/angular/src/app/app.routes.ts +3 -0
- package/templates/angular/src/app/app.ts +9 -0
- package/templates/angular/src/collections/posts.ts +16 -0
- package/templates/angular/src/index.html.tmpl +13 -0
- package/templates/angular/src/main.server.ts +7 -0
- package/templates/angular/src/main.ts +5 -0
- package/templates/angular/src/momentum.config.ts.tmpl +59 -0
- package/templates/angular/src/server.ts.tmpl +74 -0
- package/templates/angular/src/styles.css +140 -0
- package/templates/angular/tailwind.config.js +11 -0
- package/templates/angular/tsconfig.app.json +9 -0
- package/templates/angular/tsconfig.json +26 -0
- package/templates/shared/.claude/CLAUDE.md +155 -0
- package/templates/shared/.claude/skills/collection/SKILL.md +117 -0
- package/templates/shared/.claude/skills/momentum-api/SKILL.md +158 -0
- package/templates/shared/.env.example.tmpl +11 -0
- package/templates/shared/README.md.tmpl +27 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present Momentum CMS Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# create-momentum-app
|
|
2
|
+
|
|
3
|
+
Scaffold a new Momentum CMS application with a single command.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx create-momentum-app
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Non-interactive
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx create-momentum-app my-app --flavor angular --database postgres
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Options
|
|
18
|
+
|
|
19
|
+
| Flag | Description | Default |
|
|
20
|
+
| -------------- | ---------------------- | ---------- |
|
|
21
|
+
| `--flavor` | `angular` or `analog` | (prompted) |
|
|
22
|
+
| `--database` | `postgres` or `sqlite` | (prompted) |
|
|
23
|
+
| `--no-install` | Skip `npm install` | false |
|
|
24
|
+
|
|
25
|
+
## What you get
|
|
26
|
+
|
|
27
|
+
- A fully configured Momentum CMS project
|
|
28
|
+
- Angular SSR with Express or Analog with Nitro
|
|
29
|
+
- Admin dashboard UI at `/admin`
|
|
30
|
+
- REST API at `/api`
|
|
31
|
+
- Authentication via Better Auth
|
|
32
|
+
- Drizzle ORM with PostgreSQL or SQLite
|
|
33
|
+
- Tailwind CSS with the Momentum admin theme
|
package/index.cjs
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
|
|
25
|
+
// apps/create-momentum-app/src/cli.ts
|
|
26
|
+
var import_prompts = __toESM(require("prompts"));
|
|
27
|
+
var import_picocolors2 = __toESM(require("picocolors"));
|
|
28
|
+
|
|
29
|
+
// apps/create-momentum-app/src/create-project.ts
|
|
30
|
+
var import_node_path = __toESM(require("node:path"));
|
|
31
|
+
var import_node_child_process = require("node:child_process");
|
|
32
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
33
|
+
var import_picocolors = __toESM(require("picocolors"));
|
|
34
|
+
var TEMPLATE_EXT = ".tmpl";
|
|
35
|
+
function getTemplatesDir() {
|
|
36
|
+
return import_node_path.default.resolve(__dirname, "templates");
|
|
37
|
+
}
|
|
38
|
+
function interpolate(content, vars) {
|
|
39
|
+
let result = content;
|
|
40
|
+
for (const [key, value] of Object.entries(vars)) {
|
|
41
|
+
result = result.replaceAll(`{{${key}}}`, value);
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
function copyTemplateDir(srcDir, destDir, vars) {
|
|
46
|
+
const entries = import_fs_extra.default.readdirSync(srcDir, { withFileTypes: true });
|
|
47
|
+
for (const entry of entries) {
|
|
48
|
+
const srcPath = import_node_path.default.join(srcDir, entry.name);
|
|
49
|
+
let destName = entry.name;
|
|
50
|
+
if (entry.isDirectory()) {
|
|
51
|
+
const destPath2 = import_node_path.default.join(destDir, destName);
|
|
52
|
+
import_fs_extra.default.ensureDirSync(destPath2);
|
|
53
|
+
copyTemplateDir(srcPath, destPath2, vars);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const isTemplate = destName.endsWith(TEMPLATE_EXT);
|
|
57
|
+
if (isTemplate) {
|
|
58
|
+
destName = destName.slice(0, -TEMPLATE_EXT.length);
|
|
59
|
+
}
|
|
60
|
+
const destPath = import_node_path.default.join(destDir, destName);
|
|
61
|
+
if (isTemplate) {
|
|
62
|
+
const content = import_fs_extra.default.readFileSync(srcPath, "utf-8");
|
|
63
|
+
import_fs_extra.default.writeFileSync(destPath, interpolate(content, vars), "utf-8");
|
|
64
|
+
} else {
|
|
65
|
+
import_fs_extra.default.copyFileSync(srcPath, destPath);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async function createProject(options) {
|
|
70
|
+
const { projectName, flavor, database, install, registry } = options;
|
|
71
|
+
const projectDir = import_node_path.default.resolve(process.cwd(), projectName);
|
|
72
|
+
if (import_fs_extra.default.existsSync(projectDir)) {
|
|
73
|
+
console.error(import_picocolors.default.red(`
|
|
74
|
+
Directory "${projectName}" already exists.`));
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
const templatesDir = getTemplatesDir();
|
|
78
|
+
const pkgJson = import_fs_extra.default.readJsonSync(import_node_path.default.resolve(__dirname, "package.json"));
|
|
79
|
+
const packageVersion = pkgJson.version ?? "0.0.1";
|
|
80
|
+
const vars = {
|
|
81
|
+
projectName,
|
|
82
|
+
packageVersion,
|
|
83
|
+
databaseType: database,
|
|
84
|
+
dbImport: database === "postgres" ? "import { postgresAdapter } from '@momentumcms/db-drizzle';" : "import { sqliteAdapter } from '@momentumcms/db-drizzle';",
|
|
85
|
+
dbAdapter: database === "postgres" ? `postgresAdapter({
|
|
86
|
+
connectionString: process.env['DATABASE_URL'] ?? 'postgresql://postgres:postgres@localhost:5432/momentum',
|
|
87
|
+
})` : `sqliteAdapter({
|
|
88
|
+
filename: process.env['DATABASE_PATH'] ?? './data/momentum.db',
|
|
89
|
+
})`,
|
|
90
|
+
dbPoolSetup: database === "postgres" ? `import type { PostgresAdapterWithRaw } from '@momentumcms/db-drizzle';
|
|
91
|
+
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- PostgresAdapter implements PostgresAdapterWithRaw
|
|
93
|
+
const pool = (dbAdapter as PostgresAdapterWithRaw).getPool();` : "",
|
|
94
|
+
authDbConfig: database === "postgres" ? "db: { type: 'postgres', pool }," : "db: { type: 'sqlite', database: dbAdapter.getDatabase() },",
|
|
95
|
+
dbPackage: database === "postgres" ? '"pg": "^8.18.0"' : '"better-sqlite3": "^12.6.0"',
|
|
96
|
+
dbDevPackage: database === "postgres" ? "" : '"@types/better-sqlite3": "^7.6.13",',
|
|
97
|
+
envDbVar: database === "postgres" ? "DATABASE_URL=postgresql://postgres:postgres@localhost:5432/momentum" : "DATABASE_PATH=./data/momentum.db",
|
|
98
|
+
defaultPort: flavor === "angular" ? "4000" : "4200"
|
|
99
|
+
};
|
|
100
|
+
console.log();
|
|
101
|
+
console.log(import_picocolors.default.cyan(`Creating ${import_picocolors.default.bold(projectName)} with ${flavor} + ${database}...`));
|
|
102
|
+
console.log();
|
|
103
|
+
import_fs_extra.default.ensureDirSync(projectDir);
|
|
104
|
+
copyTemplateDir(import_node_path.default.join(templatesDir, "shared"), projectDir, vars);
|
|
105
|
+
copyTemplateDir(import_node_path.default.join(templatesDir, flavor), projectDir, vars);
|
|
106
|
+
if (install) {
|
|
107
|
+
console.log(import_picocolors.default.dim("Installing dependencies..."));
|
|
108
|
+
const args = ["install"];
|
|
109
|
+
if (registry) {
|
|
110
|
+
args.push("--registry", registry);
|
|
111
|
+
}
|
|
112
|
+
(0, import_node_child_process.execFileSync)("npm", args, {
|
|
113
|
+
cwd: projectDir,
|
|
114
|
+
stdio: "inherit"
|
|
115
|
+
});
|
|
116
|
+
console.log();
|
|
117
|
+
}
|
|
118
|
+
console.log(import_picocolors.default.green(import_picocolors.default.bold("Done!")));
|
|
119
|
+
console.log();
|
|
120
|
+
console.log(" Next steps:");
|
|
121
|
+
console.log();
|
|
122
|
+
console.log(import_picocolors.default.dim(` cd ${projectName}`));
|
|
123
|
+
if (!install) {
|
|
124
|
+
console.log(import_picocolors.default.dim(" npm install"));
|
|
125
|
+
}
|
|
126
|
+
console.log(import_picocolors.default.dim(" npm run dev"));
|
|
127
|
+
console.log();
|
|
128
|
+
console.log(import_picocolors.default.dim(" Open http://localhost:" + vars.defaultPort + "/admin"));
|
|
129
|
+
console.log();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// apps/create-momentum-app/src/cli.ts
|
|
133
|
+
function parseArgs(argv) {
|
|
134
|
+
const args = argv.slice(2);
|
|
135
|
+
const opts = {};
|
|
136
|
+
for (let i = 0; i < args.length; i++) {
|
|
137
|
+
const arg = args[i];
|
|
138
|
+
if (arg === "--flavor" && args[i + 1]) {
|
|
139
|
+
const val = args[++i];
|
|
140
|
+
if (val === "angular" || val === "analog") {
|
|
141
|
+
opts.flavor = val;
|
|
142
|
+
}
|
|
143
|
+
} else if (arg === "--database" && args[i + 1]) {
|
|
144
|
+
const val = args[++i];
|
|
145
|
+
if (val === "postgres" || val === "sqlite") {
|
|
146
|
+
opts.database = val;
|
|
147
|
+
}
|
|
148
|
+
} else if (arg === "--no-install") {
|
|
149
|
+
opts.install = false;
|
|
150
|
+
} else if (arg === "--registry" && args[i + 1]) {
|
|
151
|
+
opts.registry = args[++i];
|
|
152
|
+
} else if (!arg.startsWith("-") && !opts.projectName) {
|
|
153
|
+
opts.projectName = arg;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return opts;
|
|
157
|
+
}
|
|
158
|
+
function isValidProjectName(name) {
|
|
159
|
+
return /^[a-zA-Z][a-zA-Z0-9_-]*$/.test(name);
|
|
160
|
+
}
|
|
161
|
+
async function runCLI() {
|
|
162
|
+
console.log();
|
|
163
|
+
console.log(import_picocolors2.default.bold(import_picocolors2.default.cyan(" Momentum CMS")));
|
|
164
|
+
console.log(import_picocolors2.default.dim(" Create a new Momentum CMS application"));
|
|
165
|
+
console.log();
|
|
166
|
+
const cliArgs = parseArgs(process.argv);
|
|
167
|
+
const response = await (0, import_prompts.default)(
|
|
168
|
+
[
|
|
169
|
+
{
|
|
170
|
+
type: cliArgs.projectName ? null : "text",
|
|
171
|
+
name: "projectName",
|
|
172
|
+
message: "Project name:",
|
|
173
|
+
initial: "my-momentum-app",
|
|
174
|
+
validate: (value) => isValidProjectName(value) ? true : "Invalid name. Use letters, numbers, hyphens, underscores."
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
type: cliArgs.flavor ? null : "select",
|
|
178
|
+
name: "flavor",
|
|
179
|
+
message: "Which framework?",
|
|
180
|
+
choices: [
|
|
181
|
+
{ title: "Angular (Express SSR)", value: "angular" },
|
|
182
|
+
{ title: "Analog (Nitro)", value: "analog" }
|
|
183
|
+
]
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
type: cliArgs.database ? null : "select",
|
|
187
|
+
name: "database",
|
|
188
|
+
message: "Which database?",
|
|
189
|
+
choices: [
|
|
190
|
+
{ title: "PostgreSQL", value: "postgres" },
|
|
191
|
+
{ title: "SQLite", value: "sqlite" }
|
|
192
|
+
]
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
type: cliArgs.install !== void 0 ? null : "confirm",
|
|
196
|
+
name: "install",
|
|
197
|
+
message: "Install dependencies?",
|
|
198
|
+
initial: true
|
|
199
|
+
}
|
|
200
|
+
],
|
|
201
|
+
{
|
|
202
|
+
onCancel: () => {
|
|
203
|
+
console.log(import_picocolors2.default.red("\nSetup cancelled."));
|
|
204
|
+
process.exit(1);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
);
|
|
208
|
+
const options = {
|
|
209
|
+
projectName: cliArgs.projectName ?? response.projectName,
|
|
210
|
+
flavor: cliArgs.flavor ?? response.flavor,
|
|
211
|
+
database: cliArgs.database ?? response.database,
|
|
212
|
+
install: cliArgs.install ?? response.install ?? true,
|
|
213
|
+
registry: cliArgs.registry
|
|
214
|
+
};
|
|
215
|
+
await createProject(options);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// apps/create-momentum-app/src/index.ts
|
|
219
|
+
runCLI().catch((err) => {
|
|
220
|
+
console.error(err);
|
|
221
|
+
process.exit(1);
|
|
222
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-momentum-app",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Create a new Momentum CMS application",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Momentum CMS Contributors",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/momentum-cms/momentum-cms.git",
|
|
10
|
+
"directory": "apps/create-momentum-app"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/momentum-cms/momentum-cms#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/momentum-cms/momentum-cms/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"cms",
|
|
18
|
+
"headless-cms",
|
|
19
|
+
"angular",
|
|
20
|
+
"momentum-cms",
|
|
21
|
+
"create-app",
|
|
22
|
+
"cli",
|
|
23
|
+
"scaffold"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18"
|
|
27
|
+
},
|
|
28
|
+
"bin": {
|
|
29
|
+
"create-momentum-app": "./index.cjs"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"index.cjs",
|
|
33
|
+
"templates",
|
|
34
|
+
"LICENSE",
|
|
35
|
+
"README.md"
|
|
36
|
+
],
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@angular/aria": "21.1.2",
|
|
39
|
+
"@angular/cdk": "21.1.2",
|
|
40
|
+
"@angular/common": "21.1.2",
|
|
41
|
+
"@angular/compiler": "21.1.2",
|
|
42
|
+
"@angular/core": "21.1.2",
|
|
43
|
+
"@angular/forms": "21.1.2",
|
|
44
|
+
"@angular/platform-browser": "21.1.2",
|
|
45
|
+
"@angular/platform-server": "21.1.2",
|
|
46
|
+
"@angular/router": "21.1.2",
|
|
47
|
+
"@aws-sdk/client-s3": "3.983.0",
|
|
48
|
+
"@aws-sdk/s3-request-presigner": "3.983.0",
|
|
49
|
+
"@ng-icons/core": "33.0.0",
|
|
50
|
+
"@ng-icons/heroicons": "33.0.0",
|
|
51
|
+
"@tiptap/core": "3.19.0",
|
|
52
|
+
"@tiptap/extension-link": "3.19.0",
|
|
53
|
+
"@tiptap/extension-placeholder": "3.19.0",
|
|
54
|
+
"@tiptap/extension-underline": "3.19.0",
|
|
55
|
+
"@tiptap/starter-kit": "3.19.0",
|
|
56
|
+
"better-auth": "1.4.18",
|
|
57
|
+
"better-sqlite3": "12.6.2",
|
|
58
|
+
"fs-extra": "^11.2.0",
|
|
59
|
+
"graphql": "16.12.0",
|
|
60
|
+
"h3": "1.15.5",
|
|
61
|
+
"nodemailer": "8.0.0",
|
|
62
|
+
"pg": "8.18.0",
|
|
63
|
+
"picocolors": "^1.1.0",
|
|
64
|
+
"prompts": "^2.4.2",
|
|
65
|
+
"rxjs": "7.8.2"
|
|
66
|
+
},
|
|
67
|
+
"main": "./index.cjs",
|
|
68
|
+
"type": "commonjs"
|
|
69
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<title>Momentum CMS</title>
|
|
6
|
+
<base href="/" />
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
8
|
+
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
|
9
|
+
<link rel="stylesheet" href="/src/styles.css" />
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<script>
|
|
13
|
+
try {
|
|
14
|
+
var t = localStorage.getItem('mcms-theme');
|
|
15
|
+
if (
|
|
16
|
+
t === 'dark' ||
|
|
17
|
+
((!t || t === 'system') && matchMedia('(prefers-color-scheme:dark)').matches)
|
|
18
|
+
)
|
|
19
|
+
document.documentElement.classList.add('dark');
|
|
20
|
+
} catch (e) {}
|
|
21
|
+
</script>
|
|
22
|
+
<app-root></app-root>
|
|
23
|
+
<script type="module" src="/src/main.ts"></script>
|
|
24
|
+
</body>
|
|
25
|
+
</html>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{projectName}}",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "analog dev",
|
|
8
|
+
"build": "analog build",
|
|
9
|
+
"start": "node dist/analog/server/index.mjs"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@analogjs/platform": "^2.2.3",
|
|
13
|
+
"@analogjs/router": "^2.2.3",
|
|
14
|
+
"@angular/common": "~21.1.0",
|
|
15
|
+
"@angular/compiler": "~21.1.0",
|
|
16
|
+
"@angular/core": "~21.1.0",
|
|
17
|
+
"@angular/forms": "~21.1.0",
|
|
18
|
+
"@angular/platform-browser": "~21.1.0",
|
|
19
|
+
"@angular/platform-server": "~21.1.0",
|
|
20
|
+
"@angular/router": "~21.1.0",
|
|
21
|
+
"@angular/cdk": "^21.1.2",
|
|
22
|
+
"@momentumcms/core": "^{{packageVersion}}",
|
|
23
|
+
"@momentumcms/db-drizzle": "^{{packageVersion}}",
|
|
24
|
+
"@momentumcms/server-core": "^{{packageVersion}}",
|
|
25
|
+
"@momentumcms/server-analog": "^{{packageVersion}}",
|
|
26
|
+
"@momentumcms/auth": "^{{packageVersion}}",
|
|
27
|
+
"@momentumcms/admin": "^{{packageVersion}}",
|
|
28
|
+
"@momentumcms/storage": "^{{packageVersion}}",
|
|
29
|
+
"@momentumcms/logger": "^{{packageVersion}}",
|
|
30
|
+
"@momentumcms/plugins-core": "^{{packageVersion}}",
|
|
31
|
+
{{dbPackage}},
|
|
32
|
+
"dotenv": "^17.2.3",
|
|
33
|
+
"h3": "^1.15.5",
|
|
34
|
+
"rxjs": "~7.8.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@angular/cli": "~21.1.0",
|
|
38
|
+
"@angular/compiler-cli": "~21.1.0",
|
|
39
|
+
"@analogjs/vite-plugin-angular": "^2.2.3",
|
|
40
|
+
{{dbDevPackage}}
|
|
41
|
+
"typescript": "~5.9.2",
|
|
42
|
+
"vite": "^7.0.0",
|
|
43
|
+
"tailwindcss": "^3.4.19",
|
|
44
|
+
"postcss": "^8.5.6",
|
|
45
|
+
"autoprefixer": "^10.4.24"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { mergeApplicationConfig, ApplicationConfig } from '@angular/core';
|
|
2
|
+
import { provideServerRendering } from '@angular/platform-server';
|
|
3
|
+
import { appConfig } from './app.config';
|
|
4
|
+
|
|
5
|
+
export const serverConfig: ApplicationConfig = mergeApplicationConfig(appConfig, {
|
|
6
|
+
providers: [provideServerRendering()],
|
|
7
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
|
|
2
|
+
import { provideHttpClient, withFetch, withInterceptors } from '@angular/common/http';
|
|
3
|
+
import { provideClientHydration, withEventReplay } from '@angular/platform-browser';
|
|
4
|
+
import { provideFileRouter, requestContextInterceptor, withExtraRoutes } from '@analogjs/router';
|
|
5
|
+
import { momentumAdminRoutes, crudToastInterceptor } from '@momentumcms/admin';
|
|
6
|
+
import { BASE_AUTH_COLLECTIONS } from '@momentumcms/auth';
|
|
7
|
+
import { Posts } from '../collections/posts';
|
|
8
|
+
|
|
9
|
+
const adminRoutes = momentumAdminRoutes({
|
|
10
|
+
basePath: '/admin',
|
|
11
|
+
collections: [Posts, ...BASE_AUTH_COLLECTIONS],
|
|
12
|
+
branding: {
|
|
13
|
+
title: 'Momentum CMS',
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const appConfig: ApplicationConfig = {
|
|
18
|
+
providers: [
|
|
19
|
+
provideZoneChangeDetection({ eventCoalescing: true }),
|
|
20
|
+
provideFileRouter(withExtraRoutes(adminRoutes)),
|
|
21
|
+
provideHttpClient(
|
|
22
|
+
withFetch(),
|
|
23
|
+
withInterceptors([crudToastInterceptor, requestContextInterceptor]),
|
|
24
|
+
),
|
|
25
|
+
provideClientHydration(withEventReplay()),
|
|
26
|
+
],
|
|
27
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineCollection, text, richText } from '@momentumcms/core';
|
|
2
|
+
|
|
3
|
+
export const Posts = defineCollection({
|
|
4
|
+
slug: 'posts',
|
|
5
|
+
fields: [
|
|
6
|
+
text('title', { required: true }),
|
|
7
|
+
text('slug', { required: true, unique: true }),
|
|
8
|
+
richText('content'),
|
|
9
|
+
],
|
|
10
|
+
access: {
|
|
11
|
+
read: () => true,
|
|
12
|
+
create: ({ req }) => !!req.user,
|
|
13
|
+
update: ({ req }) => !!req.user,
|
|
14
|
+
delete: ({ req }) => !!req.user,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import { defineMomentumConfig } from '@momentumcms/core';
|
|
3
|
+
{{dbImport}}
|
|
4
|
+
import { momentumAuth } from '@momentumcms/auth';
|
|
5
|
+
import { localStorageAdapter } from '@momentumcms/storage';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { Posts } from './collections/posts';
|
|
8
|
+
|
|
9
|
+
const dbAdapter = {{dbAdapter}};
|
|
10
|
+
|
|
11
|
+
{{dbPoolSetup}}
|
|
12
|
+
|
|
13
|
+
const authBaseURL =
|
|
14
|
+
process.env['BETTER_AUTH_URL'] || `http://localhost:${process.env['PORT'] || {{defaultPort}}}`;
|
|
15
|
+
|
|
16
|
+
export const authPlugin = momentumAuth({
|
|
17
|
+
{{authDbConfig}}
|
|
18
|
+
baseURL: authBaseURL,
|
|
19
|
+
trustedOrigins: [authBaseURL],
|
|
20
|
+
email: {
|
|
21
|
+
appName: '{{projectName}}',
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const config = defineMomentumConfig({
|
|
26
|
+
db: { adapter: dbAdapter },
|
|
27
|
+
collections: [Posts],
|
|
28
|
+
storage: {
|
|
29
|
+
adapter: localStorageAdapter({
|
|
30
|
+
directory: join(process.cwd(), 'data', 'uploads'),
|
|
31
|
+
}),
|
|
32
|
+
},
|
|
33
|
+
admin: {
|
|
34
|
+
basePath: '/admin',
|
|
35
|
+
branding: {
|
|
36
|
+
title: '{{projectName}}',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
server: {
|
|
40
|
+
port: Number(process.env['PORT']) || {{defaultPort}},
|
|
41
|
+
cors: {
|
|
42
|
+
origin: process.env['CORS_ORIGIN'] || '*',
|
|
43
|
+
methods: ['GET', 'POST', 'PATCH', 'PUT', 'DELETE', 'OPTIONS'],
|
|
44
|
+
headers: ['Content-Type', 'Authorization', 'X-API-Key'],
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
plugins: [authPlugin],
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export default config;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { defineEventHandler } from 'h3';
|
|
2
|
+
import { ensureInitialized } from '../utils/momentum-init';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Nitro middleware that ensures Momentum CMS is fully initialized
|
|
6
|
+
* before handling any request (API routes AND SSR page renders).
|
|
7
|
+
*
|
|
8
|
+
* Named with "00-" prefix to guarantee execution before other middleware
|
|
9
|
+
* (Nitro loads middleware in alphabetical order).
|
|
10
|
+
*/
|
|
11
|
+
export default defineEventHandler(async () => {
|
|
12
|
+
await ensureInitialized();
|
|
13
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineEventHandler,
|
|
3
|
+
readBody,
|
|
4
|
+
getQuery,
|
|
5
|
+
getRouterParams,
|
|
6
|
+
setResponseStatus,
|
|
7
|
+
setResponseHeader,
|
|
8
|
+
readMultipartFormData,
|
|
9
|
+
send,
|
|
10
|
+
getHeaders,
|
|
11
|
+
} from 'h3';
|
|
12
|
+
import { createComprehensiveMomentumHandler } from '@momentumcms/server-analog';
|
|
13
|
+
import { ensureInitialized, getAuth } from '../../utils/momentum-init';
|
|
14
|
+
import momentumConfig from '../../../momentum.config';
|
|
15
|
+
|
|
16
|
+
let handler: ReturnType<typeof createComprehensiveMomentumHandler>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Catch-all API handler for Momentum CMS.
|
|
20
|
+
* Handles all collection CRUD, globals, versioning, publishing, media,
|
|
21
|
+
* batch operations, search, import/export, and custom endpoints.
|
|
22
|
+
*
|
|
23
|
+
* Auth: Better Auth session-based authentication.
|
|
24
|
+
*/
|
|
25
|
+
export default defineEventHandler(async (event) => {
|
|
26
|
+
await ensureInitialized();
|
|
27
|
+
|
|
28
|
+
if (!handler) {
|
|
29
|
+
handler = createComprehensiveMomentumHandler(momentumConfig);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let user: { id: string; email?: string; name?: string; role?: string } | undefined;
|
|
33
|
+
|
|
34
|
+
// Try session auth via Better Auth
|
|
35
|
+
const auth = getAuth();
|
|
36
|
+
if (auth) {
|
|
37
|
+
try {
|
|
38
|
+
const rawHeaders = getHeaders(event);
|
|
39
|
+
const headers = new Headers();
|
|
40
|
+
for (const [key, value] of Object.entries(rawHeaders)) {
|
|
41
|
+
if (value != null) {
|
|
42
|
+
headers.set(key, value);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const session = await auth.api.getSession({ headers });
|
|
46
|
+
if (session) {
|
|
47
|
+
const userRecord = session.user as Record<string, unknown>;
|
|
48
|
+
const role = typeof userRecord['role'] === 'string' ? userRecord['role'] : 'user';
|
|
49
|
+
user = {
|
|
50
|
+
id: session.user.id,
|
|
51
|
+
email: session.user.email,
|
|
52
|
+
role,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
} catch {
|
|
56
|
+
// Session validation failed - continue without auth
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return handler(
|
|
61
|
+
event,
|
|
62
|
+
{
|
|
63
|
+
readBody,
|
|
64
|
+
getQuery,
|
|
65
|
+
getRouterParams,
|
|
66
|
+
setResponseStatus,
|
|
67
|
+
setResponseHeader,
|
|
68
|
+
readMultipartFormData,
|
|
69
|
+
send,
|
|
70
|
+
},
|
|
71
|
+
{ user },
|
|
72
|
+
);
|
|
73
|
+
});
|