rimecms 1.2.0 → 1.3.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/dist/adapter-sqlite/constant.d.ts +16 -0
- package/dist/adapter-sqlite/constant.js +16 -0
- package/dist/adapter-sqlite/db-move.server.d.ts +31 -0
- package/dist/adapter-sqlite/db-move.server.js +102 -0
- package/dist/adapter-sqlite/drizzle-config.server.d.ts +9 -0
- package/dist/adapter-sqlite/drizzle-config.server.js +39 -0
- package/dist/adapter-sqlite/generate-schema/write.server.js +7 -3
- package/dist/adapter-sqlite/hooks.server.d.ts +3 -0
- package/dist/adapter-sqlite/hooks.server.js +64 -0
- package/dist/adapter-sqlite/index.server.d.ts +9 -1
- package/dist/adapter-sqlite/index.server.js +18 -2
- package/dist/core/adapter.d.ts +27 -0
- package/dist/core/auth/better-auth-tables.server.d.ts +4 -1
- package/dist/core/auth/better-auth-tables.server.js +4 -1
- package/dist/core/auth/handler/index.server.js +35 -9
- package/dist/core/auth/user.server.d.ts +8 -3
- package/dist/core/auth/user.server.js +8 -3
- package/dist/core/boot.server.js +7 -2
- package/dist/core/codegen.server.d.ts +2 -3
- package/dist/core/codegen.server.js +10 -14
- package/dist/core/config/types.d.ts +4 -2
- package/dist/core/dev/cli/commands/build.d.ts +2 -2
- package/dist/core/dev/cli/commands/build.js +22 -11
- package/dist/core/dev/cli/commands/clear.server.d.ts +5 -0
- package/dist/core/dev/cli/commands/clear.server.js +17 -4
- package/dist/core/dev/cli/commands/init.server.d.ts +3 -1
- package/dist/core/dev/cli/commands/init.server.js +11 -46
- package/dist/core/dev/cli/commands/uploads-move.server.js +3 -0
- package/dist/core/dev/cli/index.js +19 -3
- package/dist/core/dev/cli/templates/init.d.ts +5 -9
- package/dist/core/dev/cli/templates/init.js +5 -38
- package/dist/core/dev/cli/util/adapter-hooks.server.d.ts +15 -0
- package/dist/core/dev/cli/util/adapter-hooks.server.js +17 -0
- package/dist/core/dev/cli/util/package-manager.server.d.ts +5 -1
- package/dist/core/dev/cli/util/package-manager.server.js +8 -10
- package/dist/core/dev/deny-storage.server.d.ts +2 -2
- package/dist/core/dev/deny-storage.server.js +2 -2
- package/dist/core/dev/ensure.server.js +0 -18
- package/dist/core/dev/vite.server.js +8 -4
- package/dist/panel/pages/dashboard/DashboardRow.svelte +13 -0
- package/dist/panel/style/font.css +2 -2
- package/dist/panel/style/index.css +2 -2
- package/package.json +6 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import devCache from './dev/cache.server.js';
|
|
2
|
-
import {
|
|
2
|
+
import { regenerateHooks, regenerateParams } from './dev/cli/templates/init.js';
|
|
3
3
|
import generateRoutes from './dev/codegen/routes/index.server.js';
|
|
4
4
|
import generateTypes from './dev/codegen/types/index.server.js';
|
|
5
5
|
import { RimeError } from './errors/index.js';
|
|
@@ -33,9 +33,8 @@ const cliRunning = () => {
|
|
|
33
33
|
* Phase 1 of three — everything rime writes to disk, in the order it writes it.
|
|
34
34
|
*
|
|
35
35
|
* The one place the build sequence is written down. Unlike the hook pipeline in `core/pipeline/`
|
|
36
|
-
* it cannot be a flat array, because each step's output is the next step's input on disk
|
|
37
|
-
*
|
|
38
|
-
* it straight off the filesystem.
|
|
36
|
+
* it cannot be a flat array, because each step's output is the next step's input on disk: the
|
|
37
|
+
* schema is written before the types that declare its module.
|
|
39
38
|
*
|
|
40
39
|
* Runs *inside* boot, and only under `dev`: in development codegen is on the fly — editing a collection invalidates the config module, the app reboots,
|
|
41
40
|
* and this runs again as part of that reload. There is no separate codegen program, and
|
|
@@ -67,21 +66,18 @@ export const runCodegen = async (args) => {
|
|
|
67
66
|
}
|
|
68
67
|
// 3. SvelteKit routes — the (rime) panel tree and /api, plus the param matchers.
|
|
69
68
|
generateRoutes(config);
|
|
70
|
-
// 4. drizzle.
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
regenerateDrizzleConfig();
|
|
74
|
-
// 5. The drizzle schema. Owned by the adapter, which is why it arrives as an argument: this
|
|
75
|
-
// is the one codegen step rime does not implement itself.
|
|
69
|
+
// 4. The drizzle schema. Owned by the adapter, which is why it arrives as an argument: this
|
|
70
|
+
// is the one codegen step rime does not implement itself. The adapter keeps its own
|
|
71
|
+
// drizzle.config.ts current.
|
|
76
72
|
await generateSchema(config);
|
|
77
|
-
//
|
|
73
|
+
// 5. app.generated.d.ts — the types that carry collection and area slugs into consumer code.
|
|
78
74
|
await generateTypes(config);
|
|
79
|
-
//
|
|
75
|
+
// 6. src/hooks.server.ts, if the consumer has not written one.
|
|
80
76
|
regenerateHooks();
|
|
81
|
-
//
|
|
77
|
+
// 7. src/params.ts, if the consumer has not written one — the file that spreads the matchers
|
|
82
78
|
// generateRoutes wrote.
|
|
83
79
|
regenerateParams();
|
|
84
|
-
//
|
|
80
|
+
// 8. Every step wrote its files: the next boot with this config has nothing to do. A step that
|
|
85
81
|
// threw leaves the memo unstored, so the next boot runs them again.
|
|
86
82
|
devCache.remember('config', memo);
|
|
87
83
|
};
|
|
@@ -6,7 +6,7 @@ import type { CollectionAuthConfig, AdditionalStaffConfig } from '../auth/types.
|
|
|
6
6
|
import type { CollectionLabel } from '../prototype/collection/types.js';
|
|
7
7
|
import type { UploadConfig } from '../prototype/collection/upload/types.js';
|
|
8
8
|
import type { VersionsConfig } from '../prototype/shared/versions/types.js';
|
|
9
|
-
import type { Adapter } from '../adapter.js';
|
|
9
|
+
import type { Adapter, AdapterHooks } from '../adapter.js';
|
|
10
10
|
import type { Hook, HookBeforeOperation } from '../pipeline/types.js';
|
|
11
11
|
import type { Plugin } from '../plugins/index.js';
|
|
12
12
|
import type { SMTPConfig } from '../plugins/mailer/index.server.js';
|
|
@@ -38,12 +38,14 @@ export interface Config {
|
|
|
38
38
|
* Database adapter
|
|
39
39
|
* @example
|
|
40
40
|
* export default rime({
|
|
41
|
-
* $adapter: adapterSqlite(
|
|
41
|
+
* $adapter: adapterSqlite('app.sqlite')
|
|
42
42
|
* }
|
|
43
43
|
*/
|
|
44
44
|
$adapter: {
|
|
45
45
|
createAdapter: (config: any) => Promise<Adapter>;
|
|
46
46
|
generateSchema: (config: any) => Promise<void>;
|
|
47
|
+
/** What the adapter does to the project in dev and from the CLI. */
|
|
48
|
+
hooks: AdapterHooks;
|
|
47
49
|
};
|
|
48
50
|
/** Transversal auth config */
|
|
49
51
|
$auth?: {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { logger } from '../../../logger.server.js';
|
|
2
|
-
import { UPLOADS } from '../../../prototype/collection/upload/constant.js';
|
|
3
2
|
import chalk from 'chalk';
|
|
4
3
|
import { spawnSync } from 'child_process';
|
|
5
4
|
import { copyFileSync, cpSync, existsSync, mkdirSync, renameSync, rmSync, writeFileSync } from 'fs';
|
|
5
|
+
import { trycatch } from '../../../../util/function.js';
|
|
6
|
+
import { importAdapterHooks, recordedHooksModule } from '../util/adapter-hooks.server.js';
|
|
6
7
|
import { getInvokingPackageManager } from '../util/package-manager.server.js';
|
|
7
8
|
import { usesBunScripts } from '../util/package.server.js';
|
|
8
9
|
import { envProduction, nodeServer } from '../templates/build.js';
|
|
@@ -23,8 +24,18 @@ const installCommands = {
|
|
|
23
24
|
runEnv: 'bunx rime env'
|
|
24
25
|
}
|
|
25
26
|
};
|
|
26
|
-
export const build = (args) => {
|
|
27
|
+
export const build = async (args) => {
|
|
27
28
|
const bun = usesBunScripts();
|
|
29
|
+
// -w ships the database: refused while the adapter asks for a step first, `rime db:move` for a
|
|
30
|
+
// project whose database is not in storage/ yet, as a dev boot is
|
|
31
|
+
if (args.withStorage) {
|
|
32
|
+
const [error] = await trycatch(async () => (await importAdapterHooks(recordedHooksModule())).boot());
|
|
33
|
+
if (error) {
|
|
34
|
+
logger.error(`[✗] ${error.message}`);
|
|
35
|
+
process.exitCode = 1;
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
28
39
|
// Delete app folder if it exists
|
|
29
40
|
if (existsSync('./app')) {
|
|
30
41
|
rmSync('./app', { recursive: true, force: true });
|
|
@@ -49,19 +60,19 @@ export const build = (args) => {
|
|
|
49
60
|
// Copy package.json
|
|
50
61
|
copyFileSync('./package.json', './app/package.json');
|
|
51
62
|
logger.debug('[✓] package.json copied');
|
|
52
|
-
//
|
|
53
|
-
if (args.
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
// storage/: the database and the uploads
|
|
64
|
+
if (args.withStorage) {
|
|
65
|
+
if (existsSync('./storage')) {
|
|
66
|
+
cpSync('./storage', './app/storage', { recursive: true });
|
|
67
|
+
logger.debug('[✓] storage directory copied');
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
logger.warn('No storage directory to copy (skip)');
|
|
71
|
+
}
|
|
56
72
|
}
|
|
57
|
-
// Copy the static folder and the uploads if flag is set
|
|
58
73
|
if (args.withStatic) {
|
|
59
74
|
cpSync('./static', './app/static', { recursive: true });
|
|
60
75
|
logger.debug('[✓] static directory copied');
|
|
61
|
-
if (existsSync(`./${UPLOADS.DIRECTORY}`)) {
|
|
62
|
-
cpSync(`./${UPLOADS.DIRECTORY}`, `./app/${UPLOADS.DIRECTORY}`, { recursive: true });
|
|
63
|
-
logger.debug('[✓] uploads directory copied');
|
|
64
|
-
}
|
|
65
76
|
}
|
|
66
77
|
// Create main entry server file
|
|
67
78
|
writeFileSync('./app/index.js', nodeServer);
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `rime clear`: removes the database adapter's files, then everything rime generated or keeps for
|
|
3
|
+
* itself. Loads no config: the adapter's hooks come from the module `rime init` or the last dev
|
|
4
|
+
* boot recorded in `node_modules/.rime`, else from the default adapter's, as after a fresh install.
|
|
5
|
+
*/
|
|
1
6
|
export declare const clear: (args: {
|
|
2
7
|
force?: boolean;
|
|
3
8
|
}) => Promise<void>;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { UPLOADS } from '../../../prototype/collection/upload/constant.js';
|
|
2
2
|
import { RIME_DEV_CACHE_DIR } from '../../../constants.server.js';
|
|
3
3
|
import { logger } from '../../../logger.server.js';
|
|
4
|
+
import { trycatch } from '../../../../util/function.js';
|
|
4
5
|
import { rmSync } from 'node:fs';
|
|
5
6
|
import path from 'node:path';
|
|
6
7
|
import { CONFIG_DIR, GENERATED_DIR } from '../../constants.server.js';
|
|
8
|
+
import { importAdapterHooks, recordedHooksModule } from '../util/adapter-hooks.server.js';
|
|
7
9
|
import { prompt } from '../util/prompt.server.js';
|
|
8
10
|
const clearMessage = `Are you sure you want to delete all related rime files (Y/n):
|
|
11
|
+
- the files of the database adapter
|
|
9
12
|
- ./storage/uploads
|
|
10
|
-
- ./db
|
|
11
13
|
- ./src/routes/(rime)
|
|
12
14
|
- ./${CONFIG_DIR}
|
|
13
15
|
- ./${GENERATED_DIR}
|
|
@@ -15,9 +17,13 @@ const clearMessage = `Are you sure you want to delete all related rime files (Y/
|
|
|
15
17
|
- ./src/rime.generated.d.ts
|
|
16
18
|
- ./src/rime.modules.generated.d.ts
|
|
17
19
|
- ./src/hooks.server.ts
|
|
18
|
-
- ./drizzle.config.ts
|
|
19
20
|
- ./node_modules/.rime
|
|
20
21
|
`;
|
|
22
|
+
/**
|
|
23
|
+
* `rime clear`: removes the database adapter's files, then everything rime generated or keeps for
|
|
24
|
+
* itself. Loads no config: the adapter's hooks come from the module `rime init` or the last dev
|
|
25
|
+
* boot recorded in `node_modules/.rime`, else from the default adapter's, as after a fresh install.
|
|
26
|
+
*/
|
|
21
27
|
export const clear = async (args) => {
|
|
22
28
|
let shouldProceed = true;
|
|
23
29
|
if (!args.force) {
|
|
@@ -27,18 +33,25 @@ export const clear = async (args) => {
|
|
|
27
33
|
if (!shouldProceed) {
|
|
28
34
|
return logger.debug('Operation cancelled. Great!');
|
|
29
35
|
}
|
|
36
|
+
// The adapter's files, through the hooks module `rime init` or the last dev boot recorded, read
|
|
37
|
+
// before the cache goes, else through the default adapter's
|
|
38
|
+
const [error, removed] = await trycatch(async () => (await importAdapterHooks(recordedHooksModule())).clear());
|
|
39
|
+
if (error) {
|
|
40
|
+
logger.warn(`The database adapter's files are left: ${error.message}`);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
removed.forEach((entry) => logger.debug(`- ${entry}`));
|
|
44
|
+
}
|
|
30
45
|
// Remove directories
|
|
31
46
|
rmSync(RIME_DEV_CACHE_DIR, { recursive: true, force: true });
|
|
32
47
|
rmSync(path.join('src', 'routes', '(rime)'), { recursive: true, force: true });
|
|
33
48
|
rmSync(CONFIG_DIR, { recursive: true, force: true });
|
|
34
49
|
rmSync(GENERATED_DIR, { recursive: true, force: true });
|
|
35
|
-
rmSync(path.join('db'), { recursive: true, force: true });
|
|
36
50
|
rmSync(UPLOADS.DIRECTORY, { recursive: true, force: true });
|
|
37
51
|
// Remove files
|
|
38
52
|
rmSync(path.join('src', 'hooks.server.ts'), { force: true });
|
|
39
53
|
rmSync(path.join('src', 'app.generated.d.ts'), { force: true });
|
|
40
54
|
rmSync(path.join('src', 'rime.generated.d.ts'), { force: true });
|
|
41
55
|
rmSync(path.join('src', 'rime.modules.generated.d.ts'), { force: true });
|
|
42
|
-
rmSync(path.join('drizzle.config.ts'), { force: true });
|
|
43
56
|
return logger.debug('rime cleared');
|
|
44
57
|
};
|
|
@@ -3,6 +3,8 @@ type Args = {
|
|
|
3
3
|
skipInstall?: boolean;
|
|
4
4
|
name?: string;
|
|
5
5
|
bun?: boolean;
|
|
6
|
+
/** The database adapter: `sqlite`, or a package with a `hooks` entry. */
|
|
7
|
+
adapter?: string;
|
|
6
8
|
};
|
|
7
|
-
export declare const init: ({ force, name: incomingName, skipInstall, bun }: Args) => Promise<void>;
|
|
9
|
+
export declare const init: ({ force, name: incomingName, skipInstall, bun, adapter: adapterName }: Args) => Promise<void>;
|
|
8
10
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import devCache from '../../cache.server.js';
|
|
1
2
|
import { logger } from '../../../logger.server.js';
|
|
2
3
|
import { trycatchSync } from '../../../../util/function.js';
|
|
3
4
|
import { generate as generateCode } from '@babel/generator';
|
|
@@ -5,13 +6,12 @@ import * as t from '@babel/types';
|
|
|
5
6
|
import { babelParse, getLang } from 'ast-kit';
|
|
6
7
|
import { execSync } from 'child_process';
|
|
7
8
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
8
|
-
import { cp, mkdir } from 'fs/promises';
|
|
9
9
|
import fs from 'node:fs';
|
|
10
10
|
import path from 'path';
|
|
11
|
-
import { fileURLToPath } from 'url';
|
|
12
11
|
import { CONFIG_DIR, OUTPUT_DIR } from '../../constants.server.js';
|
|
13
12
|
import { devEnv, missingEnv, renderEnv } from '../templates/env.js';
|
|
14
13
|
import * as templates from '../templates/init.js';
|
|
14
|
+
import { adapterHooksModule, DEFAULT_ADAPTER, importAdapterHooks } from '../util/adapter-hooks.server.js';
|
|
15
15
|
import { installDependencies, SVELTEKIT_ADAPTER } from '../util/package-manager.server.js';
|
|
16
16
|
import { getPackageInfoByKey, MIN_BUN, setBunScripts } from '../util/package.server.js';
|
|
17
17
|
import { projectName } from '../util/project-name.js';
|
|
@@ -19,9 +19,8 @@ import { prompt } from '../util/prompt.server.js';
|
|
|
19
19
|
import { generate } from './generate.server.js';
|
|
20
20
|
const PACKAGE = 'rimecms';
|
|
21
21
|
const root = process.cwd();
|
|
22
|
-
export const init = async ({ force, name: incomingName, skipInstall, bun }) => {
|
|
22
|
+
export const init = async ({ force, name: incomingName, skipInstall, bun, adapter: adapterName = DEFAULT_ADAPTER }) => {
|
|
23
23
|
const packageName = getPackageInfoByKey('name');
|
|
24
|
-
const driver = bun ? 'bun' : 'libsql';
|
|
25
24
|
function setEnv() {
|
|
26
25
|
const envPath = path.resolve(root, '.env');
|
|
27
26
|
const blocks = devEnv();
|
|
@@ -69,30 +68,20 @@ export const init = async ({ force, name: incomingName, skipInstall, bun }) => {
|
|
|
69
68
|
writeFileSync(envVarsPath, next);
|
|
70
69
|
logger.debug(`[✓] ${file}: ${missing.join(', ')} declared`);
|
|
71
70
|
}
|
|
72
|
-
function setConfig(
|
|
71
|
+
function setConfig(adapter) {
|
|
73
72
|
const configDirPath = path.resolve(root, CONFIG_DIR);
|
|
74
73
|
const configPath = path.join(configDirPath, 'rime.config.server.ts');
|
|
75
74
|
if (!existsSync(configPath)) {
|
|
76
75
|
if (!existsSync(configDirPath)) {
|
|
77
76
|
mkdirSync(configDirPath);
|
|
78
77
|
}
|
|
79
|
-
writeFileSync(configPath, templates.defaultConfig(
|
|
78
|
+
writeFileSync(configPath, templates.defaultConfig(adapter));
|
|
80
79
|
logger.debug(`[✓] Config created at ${configDirPath}/rime.config.server.ts`);
|
|
81
80
|
}
|
|
82
81
|
else {
|
|
83
82
|
logger.debug('[✓] Config already exists (skip)');
|
|
84
83
|
}
|
|
85
84
|
}
|
|
86
|
-
function setDatabase() {
|
|
87
|
-
const dbPath = path.join(root, 'db');
|
|
88
|
-
if (!existsSync(dbPath)) {
|
|
89
|
-
mkdirSync(dbPath);
|
|
90
|
-
logger.debug('[✓] Database folder created');
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
logger.debug('[✓] Database folder already exists (skip)');
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
85
|
function addToGitignore() {
|
|
97
86
|
const gitignorePath = path.join(root, '.gitignore');
|
|
98
87
|
if (!existsSync(gitignorePath)) {
|
|
@@ -106,7 +95,6 @@ export const init = async ({ force, name: incomingName, skipInstall, bun }) => {
|
|
|
106
95
|
const updates = [
|
|
107
96
|
'.cache',
|
|
108
97
|
'/logs',
|
|
109
|
-
'/db',
|
|
110
98
|
'/storage',
|
|
111
99
|
OUTPUT_DIR,
|
|
112
100
|
'src/app.generated.d.ts',
|
|
@@ -124,17 +112,6 @@ export const init = async ({ force, name: incomingName, skipInstall, bun }) => {
|
|
|
124
112
|
writeFileSync(gitignorePath, gitignoreContent);
|
|
125
113
|
logger.debug('[✓] .gitignore populated');
|
|
126
114
|
}
|
|
127
|
-
function setDrizzle(name) {
|
|
128
|
-
const drizzleConfigPath = path.join(root, 'drizzle.config.ts');
|
|
129
|
-
if (!existsSync(drizzleConfigPath)) {
|
|
130
|
-
writeFileSync(drizzleConfigPath, templates.drizzleConfig(name.toString()));
|
|
131
|
-
logger.debug('[✓] Drizzle config added');
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
logger.debug(templates.regenerateDrizzleConfig(root)
|
|
135
|
-
? '[✓] Drizzle config schema path updated'
|
|
136
|
-
: '[✓] Drizzle config already exists (skip)');
|
|
137
|
-
}
|
|
138
115
|
function setBun() {
|
|
139
116
|
if (!bun)
|
|
140
117
|
return;
|
|
@@ -223,19 +200,6 @@ export const init = async ({ force, name: incomingName, skipInstall, bun }) => {
|
|
|
223
200
|
}
|
|
224
201
|
return null;
|
|
225
202
|
}
|
|
226
|
-
async function copyAssets() {
|
|
227
|
-
try {
|
|
228
|
-
const currentDir = path.dirname(fileURLToPath(import.meta.url));
|
|
229
|
-
await mkdir(path.resolve(process.cwd(), 'static/assets/panel/fonts'), { recursive: true });
|
|
230
|
-
await cp(path.join(currentDir, '../../../../panel/fonts'), path.resolve(process.cwd(), 'static/assets/panel/fonts'), {
|
|
231
|
-
recursive: true
|
|
232
|
-
});
|
|
233
|
-
logger.debug('[✓] Copied assets');
|
|
234
|
-
}
|
|
235
|
-
catch (err) {
|
|
236
|
-
console.error('Error copying fonts:', err);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
203
|
const name = await projectName({ incomingName, packageName, force: !!force, ask: prompt });
|
|
240
204
|
if (!name) {
|
|
241
205
|
logger.error(`--name "${incomingName}": use letters, numbers, hyphens and underscores`);
|
|
@@ -245,14 +209,15 @@ export const init = async ({ force, name: incomingName, skipInstall, bun }) => {
|
|
|
245
209
|
setEnv();
|
|
246
210
|
setEnvVars();
|
|
247
211
|
addToGitignore();
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
212
|
+
// The adapter's files: recorded first, so `rime clear` finds its hooks with no config loaded
|
|
213
|
+
const specifier = adapterHooksModule(adapterName);
|
|
214
|
+
devCache.set('adapter-hooks', specifier);
|
|
215
|
+
const adapter = await (await importAdapterHooks(specifier)).init({ name, bun: !!bun });
|
|
216
|
+
setConfig(adapter.config);
|
|
251
217
|
setBun();
|
|
252
218
|
setAdapter();
|
|
253
219
|
configureVite();
|
|
254
|
-
|
|
255
|
-
!skipInstall && installDependencies();
|
|
220
|
+
!skipInstall && installDependencies(adapter);
|
|
256
221
|
await generate({ force: true });
|
|
257
222
|
logger.debug('[✓] done');
|
|
258
223
|
};
|
|
@@ -85,6 +85,9 @@ export const moveUploads = async (rime) => {
|
|
|
85
85
|
*/
|
|
86
86
|
export const uploadsMove = async () => {
|
|
87
87
|
async function run() {
|
|
88
|
+
// A CLI run, as `rime generate` marks itself: the bin runs on Node, so a config on the bun
|
|
89
|
+
// driver opens its database with libsql (adapter-sqlite/connect.server.ts)
|
|
90
|
+
process.env.RIME_CLI = 'true';
|
|
88
91
|
ensureUserConfigExist();
|
|
89
92
|
await sanitize();
|
|
90
93
|
const { createServer } = await import('vite');
|
|
@@ -5,6 +5,7 @@ import { program } from 'commander';
|
|
|
5
5
|
import { existsSync, writeFileSync } from 'fs';
|
|
6
6
|
import { logSettings } from '../env.server.js';
|
|
7
7
|
import { envProduction } from './templates/build.js';
|
|
8
|
+
import { DEFAULT_ADAPTER } from './util/adapter-hooks.server.js';
|
|
8
9
|
logger.configure(logSettings);
|
|
9
10
|
// The commands report their steps at debug: shown here even without a level set
|
|
10
11
|
if (!['TRACE', 'DEBUG'].includes(logger.getLevel() ?? ''))
|
|
@@ -16,18 +17,19 @@ program
|
|
|
16
17
|
.option('-f, --force', 'Force init with default package name', false)
|
|
17
18
|
.option('-s, --skip-install', 'Do not install dependencies', false)
|
|
18
19
|
.option('-b, --bun', 'Bun pack: bun:sqlite driver, bun --bun scripts', false)
|
|
20
|
+
.option('-a, --adapter <name>', 'The database adapter: sqlite, or a package with a hooks entry', DEFAULT_ADAPTER)
|
|
19
21
|
.action(async (args) => {
|
|
20
22
|
const init = await import('./commands/init.server.js').then((m) => m.init);
|
|
21
23
|
init(args);
|
|
22
24
|
});
|
|
23
25
|
program
|
|
24
26
|
.command('build')
|
|
25
|
-
.option('-d, --with-database', 'Include database', false)
|
|
26
27
|
.option('-e, --with-env', 'Create the /app/.env file from the production template', false)
|
|
27
|
-
.option('-s, --with-static', 'Copy the
|
|
28
|
+
.option('-s, --with-static', 'Copy the static directory', false)
|
|
29
|
+
.option('-w, --with-storage', 'Copy storage/: the database and the uploads', false)
|
|
28
30
|
.action(async (args) => {
|
|
29
31
|
const build = await import('./commands/build.js').then((m) => m.build);
|
|
30
|
-
build(args);
|
|
32
|
+
await build(args);
|
|
31
33
|
});
|
|
32
34
|
program
|
|
33
35
|
.command('clear')
|
|
@@ -63,6 +65,20 @@ program
|
|
|
63
65
|
process.exitCode = 1;
|
|
64
66
|
}
|
|
65
67
|
});
|
|
68
|
+
program
|
|
69
|
+
.command('db:move')
|
|
70
|
+
.description('Moves the database and its migrations from db/ to storage/sqlite/, points the ./db paths ' +
|
|
71
|
+
'of drizzle.config.ts there, and adds /storage to .gitignore. Run once, after upgrading, ' +
|
|
72
|
+
'with the server stopped.')
|
|
73
|
+
.action(async () => {
|
|
74
|
+
const dbMove = await import('../../../adapter-sqlite/db-move.server.js').then((m) => m.dbMove);
|
|
75
|
+
try {
|
|
76
|
+
dbMove();
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
process.exitCode = 1;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
66
82
|
program
|
|
67
83
|
.command('package')
|
|
68
84
|
.description('Builds a rime plugin/field package for publish: svelte-kit sync, svelte-package, then ' +
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const
|
|
1
|
+
/** The starter config `rime init` writes, its `$adapter` the call the adapter's `init` answers. */
|
|
2
|
+
export declare const defaultConfig: (adapter: {
|
|
3
|
+
import: string;
|
|
4
|
+
call: string;
|
|
5
|
+
}) => string;
|
|
3
6
|
export declare const hooks: () => string;
|
|
4
7
|
/** Writes src/hooks.server.ts if missing. If it already exists, patches only the config
|
|
5
8
|
* import line if it's stale (e.g. after RIME_CONFIG_DIR changes the import path), and adds
|
|
@@ -30,13 +33,6 @@ export declare const appParams: (fromDir: string) => string;
|
|
|
30
33
|
* changes), and warns when the file does not import them at all. Returns whether it wrote
|
|
31
34
|
* anything. */
|
|
32
35
|
export declare function regenerateParams(root?: string): boolean;
|
|
33
|
-
/** Patches drizzle.config.ts's schema path line if it's stale (e.g. after RIME_CONFIG_DIR
|
|
34
|
-
* changes) — only that one line, since the rest of the file may carry real customizations
|
|
35
|
-
* (verbose, custom fields, etc.). Must run before generateSchema()'s own drizzle-kit
|
|
36
|
-
* generate/migrate shell-out, which reads this file from disk. No-op if the file doesn't
|
|
37
|
-
* exist — creating it from scratch needs a project name, which is `rime init`'s job
|
|
38
|
-
* (setDrizzle() in cli/commands/init.server.ts). Returns whether it patched anything. */
|
|
39
|
-
export declare function regenerateDrizzleConfig(root?: string): boolean;
|
|
40
36
|
/** Swaps adapter-auto for adapter-node in the app's Vite config. adapter-auto produces nothing
|
|
41
37
|
* for a plain Node or Bun server. Any other adapter is the app's choice and left alone. Returns
|
|
42
38
|
* the files it patched. */
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { logger } from '../../../logger.server.js';
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import {
|
|
4
|
+
import { configImportPaths, paramsPath, relativeImportSpecifier } from '../../constants.server.js';
|
|
5
5
|
import { SVELTEKIT_ADAPTER } from '../util/package-manager.server.js';
|
|
6
6
|
const PACKAGE = 'rimecms';
|
|
7
|
-
|
|
7
|
+
/** The starter config `rime init` writes, its `$adapter` the call the adapter's `init` answers. */
|
|
8
|
+
export const defaultConfig = (adapter) => `
|
|
8
9
|
import { Collection, rime } from '$rime/config';
|
|
9
10
|
import { text } from '${PACKAGE}/fields';
|
|
10
|
-
|
|
11
|
+
${adapter.import}
|
|
11
12
|
|
|
12
13
|
const Pages = Collection.create('pages', {
|
|
13
14
|
fields: [text('title').isTitle()]
|
|
@@ -21,25 +22,10 @@ const Medias = Collection.create('medias', {
|
|
|
21
22
|
});
|
|
22
23
|
|
|
23
24
|
export default rime({
|
|
24
|
-
$adapter:
|
|
25
|
+
$adapter: ${adapter.call},
|
|
25
26
|
collections: [Pages, Medias]
|
|
26
27
|
});
|
|
27
28
|
`;
|
|
28
|
-
export const drizzleConfig = (name) => `
|
|
29
|
-
import { defineConfig, type Config } from 'drizzle-kit';
|
|
30
|
-
|
|
31
|
-
export const config: Config = {
|
|
32
|
-
schema: './${GENERATED_DIR}/schema.server.ts',
|
|
33
|
-
out: './db',
|
|
34
|
-
strict: false,
|
|
35
|
-
dialect: 'sqlite',
|
|
36
|
-
dbCredentials: {
|
|
37
|
-
url: './db/${name}.sqlite'
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export default defineConfig(config);
|
|
42
|
-
`;
|
|
43
29
|
// src/, where hooks.server.ts lives: its config import is relative to it.
|
|
44
30
|
const HOOKS_DIR = path.resolve(process.cwd(), 'src');
|
|
45
31
|
const HANDLE_ERROR_EXPORT = `export { handleError } from '${PACKAGE}/server';`;
|
|
@@ -155,25 +141,6 @@ export function regenerateParams(root = process.cwd()) {
|
|
|
155
141
|
}
|
|
156
142
|
return false;
|
|
157
143
|
}
|
|
158
|
-
const DRIZZLE_SCHEMA_LINE_REGEX = /^\s*schema:\s*['"][^'"]*['"],?\s*$/m;
|
|
159
|
-
/** Patches drizzle.config.ts's schema path line if it's stale (e.g. after RIME_CONFIG_DIR
|
|
160
|
-
* changes) — only that one line, since the rest of the file may carry real customizations
|
|
161
|
-
* (verbose, custom fields, etc.). Must run before generateSchema()'s own drizzle-kit
|
|
162
|
-
* generate/migrate shell-out, which reads this file from disk. No-op if the file doesn't
|
|
163
|
-
* exist — creating it from scratch needs a project name, which is `rime init`'s job
|
|
164
|
-
* (setDrizzle() in cli/commands/init.server.ts). Returns whether it patched anything. */
|
|
165
|
-
export function regenerateDrizzleConfig(root = process.cwd()) {
|
|
166
|
-
const drizzleConfigPath = path.join(root, 'drizzle.config.ts');
|
|
167
|
-
if (!existsSync(drizzleConfigPath))
|
|
168
|
-
return false;
|
|
169
|
-
const expectedSchemaLine = ` schema: './${GENERATED_DIR}/schema.server.ts',`;
|
|
170
|
-
const content = readFileSync(drizzleConfigPath, 'utf-8');
|
|
171
|
-
if (DRIZZLE_SCHEMA_LINE_REGEX.test(content) && !content.includes(expectedSchemaLine)) {
|
|
172
|
-
writeFileSync(drizzleConfigPath, content.replace(DRIZZLE_SCHEMA_LINE_REGEX, expectedSchemaLine));
|
|
173
|
-
return true;
|
|
174
|
-
}
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
144
|
const ADAPTER_CONFIG_FILES = ['vite.config.ts', 'vite.config.js'];
|
|
178
145
|
/** Swaps adapter-auto for adapter-node in the app's Vite config. adapter-auto produces nothing
|
|
179
146
|
* for a plain Node or Bun server. Any other adapter is the app's choice and left alone. Returns
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AdapterHooks } from '../../../adapter.js';
|
|
2
|
+
/** The adapter `rime init` sets up when `--adapter` names none, and `rime clear` asks with no record. */
|
|
3
|
+
export declare const DEFAULT_ADAPTER = "sqlite";
|
|
4
|
+
/** `--adapter` as a hooks module: `sqlite` is rime's own, any other name a package's `<name>/hooks`. */
|
|
5
|
+
export declare const adapterHooksModule: (name: string) => string;
|
|
6
|
+
/**
|
|
7
|
+
* Imports the hooks a module specifier names. Rime's own come from the source through `#lib`: in
|
|
8
|
+
* this repo `rimecms/...` resolves to `dist/`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const importAdapterHooks: (specifier: string) => Promise<AdapterHooks>;
|
|
11
|
+
/**
|
|
12
|
+
* The hooks module of this project's adapter: the one `rime init` or the last dev boot recorded in
|
|
13
|
+
* `node_modules/.rime`, else the default adapter's, as after a fresh install.
|
|
14
|
+
*/
|
|
15
|
+
export declare const recordedHooksModule: () => string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import devCache from '../../cache.server.js';
|
|
2
|
+
/** The adapter `rime init` sets up when `--adapter` names none, and `rime clear` asks with no record. */
|
|
3
|
+
export const DEFAULT_ADAPTER = 'sqlite';
|
|
4
|
+
/** `--adapter` as a hooks module: `sqlite` is rime's own, any other name a package's `<name>/hooks`. */
|
|
5
|
+
export const adapterHooksModule = (name) => name === 'sqlite' ? 'rimecms/adapter-sqlite/hooks' : `${name}/hooks`;
|
|
6
|
+
/**
|
|
7
|
+
* Imports the hooks a module specifier names. Rime's own come from the source through `#lib`: in
|
|
8
|
+
* this repo `rimecms/...` resolves to `dist/`.
|
|
9
|
+
*/
|
|
10
|
+
export const importAdapterHooks = (specifier) => (specifier === 'rimecms/adapter-sqlite/hooks'
|
|
11
|
+
? import('../../../../adapter-sqlite/hooks.server.js')
|
|
12
|
+
: import(/* @vite-ignore */ specifier)).then((m) => m.hooks);
|
|
13
|
+
/**
|
|
14
|
+
* The hooks module of this project's adapter: the one `rime init` or the last dev boot recorded in
|
|
15
|
+
* `node_modules/.rime`, else the default adapter's, as after a fresh install.
|
|
16
|
+
*/
|
|
17
|
+
export const recordedHooksModule = () => devCache.get('adapter-hooks') || adapterHooksModule(DEFAULT_ADAPTER);
|
|
@@ -7,5 +7,9 @@ export declare function getPackageManager(): PackageManagerName;
|
|
|
7
7
|
* set on the child process. Falls back to npm, which is also what npx reports.
|
|
8
8
|
*/
|
|
9
9
|
export declare function getInvokingPackageManager(): PackageManagerName;
|
|
10
|
-
|
|
10
|
+
/** Installs rime's own packages, and the ones the database adapter asks for. */
|
|
11
|
+
export declare function installDependencies(adapter: {
|
|
12
|
+
dependencies: string[];
|
|
13
|
+
devDependencies: string[];
|
|
14
|
+
}): void;
|
|
11
15
|
export {};
|
|
@@ -9,26 +9,23 @@ const packageManagersMap = {
|
|
|
9
9
|
npm: 'package-lock.json',
|
|
10
10
|
deno: 'deno.lock'
|
|
11
11
|
};
|
|
12
|
-
|
|
13
|
-
// prerelease range drifts across API changes.
|
|
14
|
-
const DRIZZLE = '1.0.0-rc.4';
|
|
15
|
-
const deps = [`drizzle-orm@${DRIZZLE}`, '@libsql/client', '@lucide/svelte', 'sharp'];
|
|
12
|
+
const deps = ['@lucide/svelte', 'sharp'];
|
|
16
13
|
// Both packs build with adapter-node: the Bun pack runs the same server on Bun
|
|
17
14
|
export const SVELTEKIT_ADAPTER = '@sveltejs/adapter-node';
|
|
18
|
-
const devDeps = [SVELTEKIT_ADAPTER
|
|
15
|
+
const devDeps = [SVELTEKIT_ADAPTER];
|
|
19
16
|
const packageManagerConfigs = {
|
|
20
17
|
pnpm: {
|
|
21
|
-
command: (devDeps) => `pnpm add -D ${devDeps.join(' ')} && pnpm add ${deps.join(' ')}`,
|
|
18
|
+
command: (deps, devDeps) => `pnpm add -D ${devDeps.join(' ')} && pnpm add ${deps.join(' ')}`,
|
|
22
19
|
preInstall: configurePnpm,
|
|
23
20
|
postInstall: () => {
|
|
24
21
|
execSync('pnpm rebuild');
|
|
25
22
|
}
|
|
26
23
|
},
|
|
27
24
|
bun: {
|
|
28
|
-
command: (devDeps) => `bun add -D ${devDeps.join(' ')} && bun add ${deps.join(' ')}`
|
|
25
|
+
command: (deps, devDeps) => `bun add -D ${devDeps.join(' ')} && bun add ${deps.join(' ')}`
|
|
29
26
|
},
|
|
30
27
|
npm: {
|
|
31
|
-
command: (devDeps) => `npm install -D ${devDeps.join(' ')} && npm install ${deps.join(' ')}`
|
|
28
|
+
command: (deps, devDeps) => `npm install -D ${devDeps.join(' ')} && npm install ${deps.join(' ')}`
|
|
32
29
|
}
|
|
33
30
|
};
|
|
34
31
|
export function getPackageManager() {
|
|
@@ -55,7 +52,8 @@ export function getInvokingPackageManager() {
|
|
|
55
52
|
}
|
|
56
53
|
return 'npm';
|
|
57
54
|
}
|
|
58
|
-
|
|
55
|
+
/** Installs rime's own packages, and the ones the database adapter asks for. */
|
|
56
|
+
export function installDependencies(adapter) {
|
|
59
57
|
const pm = getInvokingPackageManager();
|
|
60
58
|
if (pm === 'deno' || pm === 'yarn') {
|
|
61
59
|
throw new Error('Unsupported package manager ' + pm);
|
|
@@ -64,7 +62,7 @@ export function installDependencies() {
|
|
|
64
62
|
// Pre installation hooks
|
|
65
63
|
config.preInstall?.();
|
|
66
64
|
// Main installation
|
|
67
|
-
const command = config.command(devDeps);
|
|
65
|
+
const command = config.command([...adapter.dependencies, ...deps], [...devDeps, ...adapter.devDependencies]);
|
|
68
66
|
logger.debug('exec : ' + command);
|
|
69
67
|
execSync(command);
|
|
70
68
|
// Post installation hooks
|
|
@@ -12,7 +12,7 @@ import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
|
12
12
|
export declare const isStorageUrl: (url?: string) => boolean;
|
|
13
13
|
/**
|
|
14
14
|
* A dev server middleware that answers 404 for `/storage` and `/storage/*`. `storage/` holds the
|
|
15
|
-
* uploads and
|
|
16
|
-
*
|
|
15
|
+
* uploads and the database, and Vite's own static middleware would otherwise answer 403 for a
|
|
16
|
+
* file it finds there.
|
|
17
17
|
*/
|
|
18
18
|
export declare const denyStorage: (req: IncomingMessage, res: ServerResponse, next: () => void) => void;
|
|
@@ -18,8 +18,8 @@ export const isStorageUrl = (url = '/') => {
|
|
|
18
18
|
};
|
|
19
19
|
/**
|
|
20
20
|
* A dev server middleware that answers 404 for `/storage` and `/storage/*`. `storage/` holds the
|
|
21
|
-
* uploads and
|
|
22
|
-
*
|
|
21
|
+
* uploads and the database, and Vite's own static middleware would otherwise answer 403 for a
|
|
22
|
+
* file it finds there.
|
|
23
23
|
*/
|
|
24
24
|
export const denyStorage = (req, res, next) => {
|
|
25
25
|
if (!isStorageUrl(req.url))
|