kreftjs 0.0.3-beta → 0.0.4-beta

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.
Files changed (53) hide show
  1. package/README.md +12 -12
  2. package/bin/add.js +11 -11
  3. package/bin/artisan-more.js +41 -41
  4. package/bin/artisan.js +41 -41
  5. package/bin/backend/command.js +1 -1
  6. package/bin/backend/factory.js +1 -1
  7. package/bin/backend/index.js +3 -3
  8. package/bin/backend/model.js +2 -2
  9. package/bin/backend/notifications.js +1 -1
  10. package/bin/backend/queue.js +2 -2
  11. package/bin/backend/schedule.js +2 -2
  12. package/bin/backend/seo-pages.js +1 -1
  13. package/bin/backend/storage.js +1 -1
  14. package/bin/backend/support.js +4 -4
  15. package/bin/backend/typescript.js +1 -1
  16. package/bin/build.js +11 -11
  17. package/bin/db-api.js +3 -3
  18. package/bin/db.js +1 -1
  19. package/bin/deps.js +6 -6
  20. package/bin/electron.js +11 -11
  21. package/bin/env.js +2 -2
  22. package/bin/guard.js +2 -2
  23. package/bin/kreftjs-config.js +1 -1
  24. package/bin/kreftjs.js +105 -105
  25. package/bin/layout.js +1 -1
  26. package/bin/no-auth.js +4 -4
  27. package/bin/prerender.js +4 -4
  28. package/bin/server-routes.js +2 -2
  29. package/bin/ssr.js +2 -2
  30. package/bin/terminal.js +1 -1
  31. package/bin/to-ts.js +1 -1
  32. package/bin/update.js +14 -14
  33. package/bin/urls-file.js +1 -1
  34. package/bin/vite.js +11 -11
  35. package/docs/Docs.kreftjs +1 -1
  36. package/docs/README.md +140 -123
  37. package/kreftjs.d.ts +1 -1
  38. package/kreftjs.js +18 -18
  39. package/package.json +1 -1
  40. package/templates/app/README.md +20 -20
  41. package/templates/app/backend/database/migrations/0001_01_01_000000_create_users_table.js +1 -1
  42. package/templates/app/backend/database/migrations/0001_01_01_000002_create_jobs_table.js +1 -1
  43. package/templates/app/backend/database/seeders/DatabaseSeeder.js +1 -1
  44. package/templates/app/backend/routes/api.js +1 -1
  45. package/templates/app/backend/routes/console.js +2 -2
  46. package/templates/app/frontend/errors/ErrorMonitor.kreftjs +2 -2
  47. package/templates/app/frontend/index.html +1 -1
  48. package/templates/app/frontend/kreftjs.d.ts +1 -1
  49. package/templates/app/frontend/kreftjs.js +18 -18
  50. package/templates/app/frontend/pages/Dashboard.kreftjs +1 -1
  51. package/templates/app/frontend/pages/ErrorMonitor.kreftjs +1 -1
  52. package/templates/app/frontend/pages/Home.kreftjs +2 -2
  53. package/templates/errors/ErrorMonitor.kreftjs +1 -1
@@ -15,7 +15,7 @@
15
15
  * await dispatch(new SendWelcomeEmail(user), { delay: 60 }) // in a minute
16
16
  * await dispatchSync(new SendWelcomeEmail(user)) // now
17
17
  *
18
- * QUEUE_CONNECTION in .env: database (the jobs table; kreftjs dev and `kreftjs queue:work` run them) or sync (at once).
18
+ * QUEUE_CONNECTION in .env: database (the jobs table; kreft dev and `kreft queue:work` run them) or sync (at once).
19
19
  */
20
20
  const crypto = require('crypto');
21
21
  const fs = require('fs');
@@ -377,7 +377,7 @@ async function workOne({ queues = ['default'], log = () => {} } = {}) {
377
377
  }
378
378
  }
379
379
 
380
- // kreftjs queue:work — runs jobs as they come (stop with Ctrl+C)
380
+ // kreft queue:work — runs jobs as they come (stop with Ctrl+C)
381
381
  async function work({ queues = ['default'], once = false, sleep = 1, maxJobs = Infinity, log = console.log, stopWhenEmpty = false } = {}) {
382
382
  const workerStartedAt = Date.now();
383
383
  let n = 0;
@@ -7,7 +7,7 @@
7
7
  * Schedule.command('cache:clear').hourly()
8
8
  * Schedule.call(fn).cron('* /15 * * * *') (no space: every 15 minutes)
9
9
  *
10
- * kreftjs dev runs them while it is on; for a real server: kreftjs schedule:work (or `kreftjs schedule:run` from cron each minute).
10
+ * kreft dev runs them while it is on; for a real server: kreft schedule:work (or `kreft schedule:run` from cron each minute).
11
11
  */
12
12
  const tasks = [];
13
13
 
@@ -96,7 +96,7 @@ function loadSchedule(baseDir) {
96
96
  require(file);
97
97
  return file;
98
98
  }
99
- // kreftjs dev / kreftjs schedule:work: check every minute, on the minute
99
+ // kreft dev / kreftjs schedule:work: check every minute, on the minute
100
100
  function startScheduler(baseDir, log = console.log) {
101
101
  let timer = null;
102
102
  const tick = async () => {
@@ -12,7 +12,7 @@
12
12
  * if (!post) return null // answered as 404 (and noindex)
13
13
  * return { title: post.title, description: post.excerpt, og: { image: post.image }, schema: { '@type': 'Article', headline: post.title } }
14
14
  * },
15
- * // the addresses of your data pages, for `kreftjs sitemap`: '/path' or { path, lastmod }
15
+ * // the addresses of your data pages, for `kreft sitemap`: '/path' or { path, lastmod }
16
16
  * urls: async () => (await Post.all()).map((p) => ({ path: '/posts/' + p.slug, lastmod: p.updated_at })),
17
17
  * }
18
18
  *
@@ -5,7 +5,7 @@
5
5
  * const data = await req.validate({ avatar: 'required|image|max:2048' }) // KB
6
6
  * const file = req.file('avatar') // { name, size, type, extension() }
7
7
  * const stored = await file.store('avatars') // 'avatars/3f9c…e1.jpg' on the public disk
8
- * Storage.url(stored) // '/storage/avatars/3f9c…e1.jpg' — kreftjs dev and kreftjs serve send it
8
+ * Storage.url(stored) // '/storage/avatars/3f9c…e1.jpg' — kreft dev and kreft serve send it
9
9
  *
10
10
  * await Storage.put('reports/today.txt', 'hello') // the local disk: backend/storage/app (private)
11
11
  * await Storage.get('reports/today.txt') Storage.exists(…) Storage.delete(…) Storage.files('reports')
@@ -98,11 +98,11 @@ function appKey() {
98
98
  if (k) {
99
99
  const buf = k.startsWith('base64:') ? Buffer.from(k.slice(7), 'base64') : Buffer.from(k);
100
100
  if (buf.length >= 16) return buf;
101
- if (production) throw new Error('APP_KEY is shorter than 16 bytes. Run `kreftjs key:generate` and put the new key in .env.');
102
- console.warn(' APP_KEY in .env is shorter than 16 bytes; run `kreftjs key:generate` for a 256-bit key.');
101
+ if (production) throw new Error('APP_KEY is shorter than 16 bytes. Run `kreft key:generate` and put the new key in .env.');
102
+ console.warn(' APP_KEY in .env is shorter than 16 bytes; run `kreft key:generate` for a 256-bit key.');
103
103
  return buf;
104
104
  }
105
- if (production) throw new Error('APP_KEY is not set. Run `kreftjs key:generate` and put the key in .env (production needs one that every process shares).');
105
+ if (production) throw new Error('APP_KEY is not set. Run `kreft key:generate` and put the key in .env (production needs one that every process shares).');
106
106
  if (!fallbackKey) {
107
107
  fallbackKey = crypto.randomBytes(32);
108
108
  console.warn(' No APP_KEY in .env: signed links stop working when the server restarts.');
@@ -170,7 +170,7 @@ const Mail = {
170
170
  if (!transport) {
171
171
  let nodemailer;
172
172
  try { nodemailer = require(require.resolve('nodemailer', { paths: [process.cwd()] })); } catch (_) {
173
- throw new Error('MAIL_URL is set: install the mailer with kreftjs add nodemailer');
173
+ throw new Error('MAIL_URL is set: install the mailer with kreft add nodemailer');
174
174
  }
175
175
  transport = nodemailer.createTransport(process.env.MAIL_URL);
176
176
  }
@@ -2,7 +2,7 @@
2
2
  * TypeScript support across backend and frontend:
3
3
  * - Backend: routes/api.ts, config/*.ts, server/*.ts, and every .ts file in app/ and database/ load like .js files.
4
4
  * - Frontend: .ts modules (e.g. frontend/logic/*.ts) and .kreftjs components with TypeScript syntax work natively in
5
- * both `kreftjs dev` and `kreftjs build`.
5
+ * both `kreft dev` and `kreft build`.
6
6
  *
7
7
  * Uses `esbuild` when installed in the project, or falls back to Kreft's built-in zero-dependency TypeScript
8
8
  * compiler (`Kreftjs.stripTypeScript` + ESM-to-CJS transform) so TypeScript projects work out of the box with zero setup.
package/bin/build.js CHANGED
@@ -1,13 +1,13 @@
1
1
  /*
2
- * kreftjs build — turns a Kreft app into production files.
2
+ * kreft build — turns a Kreft app into production files.
3
3
  *
4
- * kreftjs build build this folder into ./dist
5
- * kreftjs build ./site build another folder
6
- * kreftjs build --out public choose the output folder
7
- * kreftjs build --base / change <base href> in index.html
8
- * kreftjs build --prerender also save every page as ready HTML (needs: npm i -D jsdom)
9
- * kreftjs build --prerender --urls urls.js ... and the addresses in that file (pages that come from your data)
10
- * kreftjs build --include docs also copy another folder into the output
4
+ * kreft build build this folder into ./dist
5
+ * kreft build ./site build another folder
6
+ * kreft build --out public choose the output folder
7
+ * kreft build --base / change <base href> in index.html
8
+ * kreft build --prerender also save every page as ready HTML (needs: npm i -D jsdom)
9
+ * kreft build --prerender --urls urls.js ... and the addresses in that file (pages that come from your data)
10
+ * kreft build --include docs also copy another folder into the output
11
11
  *
12
12
  * What it does:
13
13
  * 1. Compiles every .kreftjs file ahead of time into app.js (no .kreftjs files are downloaded in production).
@@ -113,7 +113,7 @@ module.exports = function build(args) {
113
113
  const langInject = Object.keys(langData).length ? `Kreftjs.translations(${JSON.stringify(langData)});\n` : '';
114
114
 
115
115
  const precompiled = [...fns].map(([key, src]) => `F[${JSON.stringify(key)}] = ${src};`).join('\n');
116
- const appJs = `/* Built by kreftjs build — do not edit. Rebuild from your .kreftjs files instead. */
116
+ const appJs = `/* Built by kreft build — do not edit. Rebuild from your .kreftjs files instead. */
117
117
  ${env.envScript(env.publicEnv())}
118
118
  (function (Kreftjs) {
119
119
  if (!Kreftjs) throw new Error('Load kreftjs.js before app.js');
@@ -204,7 +204,7 @@ ${indent(components.join('\n\n'))}
204
204
  const links = cssLinks.map(({ spec, local }) => {
205
205
  if (local) return spec;
206
206
  const file = deps.packageFile(project, spec);
207
- if (!file) fail(`The CSS file "${spec}" was not found in node_modules. Run: kreftjs add ${(spec.match(deps.NAME) || [spec])[0]}`);
207
+ if (!file) fail(`The CSS file "${spec}" was not found in node_modules. Run: kreft add ${(spec.match(deps.NAME) || [spec])[0]}`);
208
208
  const info = deps.packageJson(project, spec);
209
209
  copyCss(file, info.dir, path.join(dist, 'vendor', info.name));
210
210
  return toUrlPath(path.join('vendor', info.name, path.relative(info.dir, file)));
@@ -237,7 +237,7 @@ ${indent(components.join('\n\n'))}
237
237
  ...files.sort().map(([f, n]) => ` ${cyan(kb(n))} ${toUrlPath(f)}`),
238
238
  '---',
239
239
  ` ${bold('Output:')} ${dist}`,
240
- ` ${bold('Preview:')} kreftjs dev ${path.relative(process.cwd(), dist) || '.'}`,
240
+ ` ${bold('Preview:')} kreft dev ${path.relative(process.cwd(), dist) || '.'}`,
241
241
  ];
242
242
  console.log('\n' + renderBox(lines, { width: 66, borderColor: green }) + '\n');
243
243
  };
package/bin/db-api.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- * A REST API made from the tables of a database (used by `kreftjs dev --db` and `kreftjs serve --db`).
2
+ * A REST API made from the tables of a database (used by `kreft dev --db` and `kreft serve --db`).
3
3
  *
4
4
  * GET /api the tables you can use
5
5
  * GET /api/posts rows ?userId=3 ?title_like=som ?likes_gte=5 ?q=text
@@ -15,7 +15,7 @@
15
15
  *
16
16
  * Which tables, and what each allows, comes from `tables` (kreftjs.config.json):
17
17
  * { "posts": true, "users": { "write": false, "hidden": ["password"] }, "logs": false }
18
- * `kreftjs dev` shows every table unless you list them; `kreftjs serve` shows only the tables you list.
18
+ * `kreft dev` shows every table unless you list them; `kreft serve` shows only the tables you list.
19
19
  */
20
20
  const { validate } = require('../kreftjs.js'); // the same rules as Kreftjs.validate in the browser
21
21
  const MAX_BODY = 1024 * 1024;
@@ -48,7 +48,7 @@ function createDbApi(db, { tables: allow = null, production = false, prefix = '/
48
48
  }
49
49
  return out;
50
50
  };
51
- // `kreftjs serve` reads the tables once; `kreftjs dev` looks again every 2 s, so a new table shows up by itself
51
+ // `kreft serve` reads the tables once; `kreft dev` looks again every 2 s, so a new table shows up by itself
52
52
  let loadedAt = 0;
53
53
  const tables = async () => {
54
54
  if (schema && (production || Date.now() - loadedAt < 2000)) return schema;
package/bin/db.js CHANGED
@@ -33,7 +33,7 @@ function parseUrl(url) {
33
33
  function driver(name, root) {
34
34
  const paths = [root || process.cwd(), process.cwd(), __dirname];
35
35
  try { return require(require.resolve(name, { paths })); }
36
- catch (_) { throw new Error(`To use this database, install its driver in your project:\n\n kreftjs add ${name}\n`); }
36
+ catch (_) { throw new Error(`To use this database, install its driver in your project:\n\n kreft add ${name}\n`); }
37
37
  }
38
38
 
39
39
  const TEXT = /char|text|clob|string|uuid|enum|json/i;
package/bin/deps.js CHANGED
@@ -5,10 +5,10 @@
5
5
  * import { debounce } from 'lodash'
6
6
  * import 'bootstrap/dist/css/bootstrap.min.css'
7
7
  *
8
- * kreftjs dev answers /__kreft/deps/<package> with the package as one browser-ready ES module, made by
8
+ * kreft dev answers /__kreft/deps/<package> with the package as one browser-ready ES module, made by
9
9
  * esbuild (npm i -D esbuild), and adds an import map so the browser knows where 'dayjs' is.
10
- * kreftjs build writes the same files into dist/deps/. Without esbuild, packages that already ship
11
- * ES modules still work in kreftjs dev; older CommonJS ones (like lodash) need esbuild.
10
+ * kreft build writes the same files into dist/deps/. Without esbuild, packages that already ship
11
+ * ES modules still work in kreft dev; older CommonJS ones (like lodash) need esbuild.
12
12
  */
13
13
  const fs = require('fs');
14
14
  const path = require('path');
@@ -57,14 +57,14 @@ function isEsm(root, spec) {
57
57
 
58
58
  const cache = new Map();
59
59
  // one package (or a file inside it) as a single ES module for the browser.
60
- // bundle() is async (kreftjs dev); bundleSync() is the same for kreftjs build.
60
+ // bundle() is async (kreft dev); bundleSync() is the same for kreft build.
61
61
  function prepare(root, spec, minify) {
62
62
  const esbuild = loadEsbuild(root);
63
- if (!esbuild) throw Object.assign(new Error(`To use "${spec}" in the browser, install esbuild once: kreftjs add -D esbuild`), { code: 'NO_ESBUILD' });
63
+ if (!esbuild) throw Object.assign(new Error(`To use "${spec}" in the browser, install esbuild once: kreft add -D esbuild`), { code: 'NO_ESBUILD' });
64
64
  // only packages by name: never a path that would bundle (and show) one of your own server files
65
65
  if (!isBare(spec) || spec.split('/').some((p) => p === '..' || p === '.')) throw Object.assign(new Error(`"${spec}" is not a package name.`), { code: 'MISSING' });
66
66
  const file = resolveFrom(root, spec);
67
- if (!file) throw Object.assign(new Error(`The package "${spec}" is not installed. Run: kreftjs add ${(spec.match(NAME) || [spec])[0]}`), { code: 'MISSING' });
67
+ if (!file) throw Object.assign(new Error(`The package "${spec}" is not installed. Run: kreft add ${(spec.match(NAME) || [spec])[0]}`), { code: 'MISSING' });
68
68
  const key = spec + '|' + fs.statSync(file).mtimeMs + '|' + minify + '|' + root;
69
69
  const s = JSON.stringify(spec);
70
70
  let tries;
package/bin/electron.js CHANGED
@@ -2,12 +2,12 @@
2
2
  * Electron.js Desktop Support for Kreft
3
3
  *
4
4
  * Commands:
5
- * kreftjs electron:init Add Electron files to an existing project (alias: kreftjs make:electron)
6
- * kreftjs electron:dev Run the app in an Electron desktop window with hot reload (alias: kreftjs electron)
7
- * kreftjs electron:build Build static bundle (kreftjs build) and package desktop installer (electron-builder)
5
+ * kreft electron:init Add Electron files to an existing project (alias: kreft make:electron)
6
+ * kreft electron:dev Run the app in an Electron desktop window with hot reload (alias: kreft electron)
7
+ * kreft electron:build Build static bundle (kreft build) and package desktop installer (electron-builder)
8
8
  *
9
9
  * CLI flag:
10
- * kreftjs new my-app --electron
10
+ * kreft new my-app --electron
11
11
  */
12
12
  const fs = require('fs');
13
13
  const path = require('path');
@@ -286,9 +286,9 @@ function init(args = []) {
286
286
  const pkg = JSON.parse(fs.readFileSync(pkgFile, 'utf8'));
287
287
  pkg.main = 'electron/main.js';
288
288
  pkg.scripts = pkg.scripts || {};
289
- pkg.scripts['electron'] = 'kreftjs electron';
290
- pkg.scripts['electron:dev'] = 'kreftjs electron:dev';
291
- pkg.scripts['electron:build'] = 'kreftjs electron:build';
289
+ pkg.scripts['electron'] = 'kreft electron';
290
+ pkg.scripts['electron:dev'] = 'kreft electron:dev';
291
+ pkg.scripts['electron:build'] = 'kreft electron:build';
292
292
 
293
293
  pkg.devDependencies = pkg.devDependencies || {};
294
294
  if (!pkg.devDependencies['electron']) pkg.devDependencies['electron'] = '^34.2.0';
@@ -317,8 +317,8 @@ function init(args = []) {
317
317
 
318
318
  Next:
319
319
  npm install (install electron & electron-builder)
320
- kreftjs electron:dev (start dev server & launch desktop window)
321
- kreftjs electron:build (build production installer)
320
+ kreft electron:dev (start dev server & launch desktop window)
321
+ kreft electron:build (build production installer)
322
322
  `);
323
323
  }
324
324
 
@@ -433,7 +433,7 @@ function startDev(args, port) {
433
433
 
434
434
  electronProcess.on('error', (err) => {
435
435
  if (err.code === 'ENOENT') {
436
- console.error('\n Electron is not installed locally. Run: kreftjs add -D electron\n');
436
+ console.error('\n Electron is not installed locally. Run: kreft add -D electron\n');
437
437
  } else {
438
438
  console.error(' Electron launch error: ' + err.message);
439
439
  }
@@ -489,7 +489,7 @@ function build(args = []) {
489
489
 
490
490
  packProc.on('error', (err) => {
491
491
  if (err.code === 'ENOENT') {
492
- console.error('\n electron-builder is not installed. Run: kreftjs add -D electron-builder\n');
492
+ console.error('\n electron-builder is not installed. Run: kreft add -D electron-builder\n');
493
493
  } else {
494
494
  console.error(' Packaging error: ' + err.message);
495
495
  }
package/bin/env.js CHANGED
@@ -1,13 +1,13 @@
1
1
  /*
2
2
  * .env files and environment management.
3
3
  *
4
- * # .env (never sent to the browser, never copied by kreftjs build)
4
+ * # .env (never sent to the browser, never copied by kreft build)
5
5
  * APP_NAME="My shop"
6
6
  * DATABASE_URL=sqlite:database/app.db
7
7
  * MAIL_PASSWORD=secret
8
8
  * PUBLIC_APP_NAME=${APP_NAME} ← PUBLIC_ values also reach the browser: env.PUBLIC_APP_NAME
9
9
  *
10
- * Read by kreftjs dev, kreftjs serve, kreftjs build and kreftjs db. Values already set in the real environment win,
10
+ * Read by kreft dev, kreft serve, kreft build and kreft db. Values already set in the real environment win,
11
11
  * so a server can override the file. In server/*.js: process.env.MAIL_PASSWORD (or ctx.env).
12
12
  */
13
13
  const fs = require('fs');
package/bin/guard.js CHANGED
@@ -2,11 +2,11 @@
2
2
  * Folder guard: Kreft notices when the folder it works in is deleted, moved or put in the Trash.
3
3
  *
4
4
  * A running process keeps working on a folder that was moved away (the files are still there, under a new
5
- * name), so `kreftjs dev` would carry on serving a project you thought was gone, and a terminal opened in the
5
+ * name), so `kreft dev` would carry on serving a project you thought was gone, and a terminal opened in the
6
6
  * old folder would run commands against the Trash. The operating system cannot be asked to refuse the
7
7
  * delete, so Kreft says it loudly instead:
8
8
  * - every command first checks that the folder it runs in is not deleted or in the Trash;
9
- * - `kreftjs dev`, `kreftjs serve` and the queue / schedule workers check every second and stop with a message.
9
+ * - `kreft dev`, `kreft serve` and the queue / schedule workers check every second and stop with a message.
10
10
  */
11
11
  const fs = require('fs');
12
12
  const path = require('path');
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * kreftjs.config.json: { "db": "sqlite:database/app.db", "tables": { "posts": true, "users": { "write": false, "hidden": ["password"] } } }
3
- * Looked for in the folder being served, then its parents (so `kreftjs serve dist` finds the project's file).
3
+ * Looked for in the folder being served, then its parents (so `kreft serve dist` finds the project's file).
4
4
  * "${NAME}" in a value is replaced with that value from .env or the environment.
5
5
  */
6
6
  const fs = require('fs');