kreftjs 0.0.3-beta → 0.0.5-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.
- package/LICENSE +95 -0
- package/README.md +13 -13
- package/bin/add.js +11 -11
- package/bin/artisan-more.js +41 -41
- package/bin/artisan.js +41 -41
- package/bin/backend/command.js +1 -1
- package/bin/backend/factory.js +1 -1
- package/bin/backend/index.js +3 -3
- package/bin/backend/model.js +2 -2
- package/bin/backend/notifications.js +1 -1
- package/bin/backend/queue.js +2 -2
- package/bin/backend/schedule.js +2 -2
- package/bin/backend/seo-pages.js +1 -1
- package/bin/backend/storage.js +1 -1
- package/bin/backend/support.js +4 -4
- package/bin/backend/typescript.js +1 -1
- package/bin/build.js +11 -11
- package/bin/db-api.js +3 -3
- package/bin/db.js +1 -1
- package/bin/deps.js +6 -6
- package/bin/electron.js +11 -11
- package/bin/env.js +2 -2
- package/bin/guard.js +2 -2
- package/bin/kreftjs-config.js +1 -1
- package/bin/kreftjs.js +105 -105
- package/bin/layout.js +1 -1
- package/bin/no-auth.js +4 -4
- package/bin/prerender.js +4 -4
- package/bin/server-routes.js +2 -2
- package/bin/ssr.js +2 -2
- package/bin/terminal.js +1 -1
- package/bin/to-ts.js +1 -1
- package/bin/update.js +14 -14
- package/bin/urls-file.js +1 -1
- package/bin/vite.js +11 -11
- package/docs/Docs.kreftjs +1 -1
- package/docs/README.md +140 -123
- package/kreftjs.d.ts +1 -1
- package/kreftjs.js +18 -18
- package/package.json +2 -1
- package/templates/app/README.md +20 -20
- package/templates/app/backend/database/migrations/0001_01_01_000000_create_users_table.js +1 -1
- package/templates/app/backend/database/migrations/0001_01_01_000002_create_jobs_table.js +1 -1
- package/templates/app/backend/database/seeders/DatabaseSeeder.js +1 -1
- package/templates/app/backend/routes/api.js +1 -1
- package/templates/app/backend/routes/console.js +2 -2
- package/templates/app/frontend/errors/ErrorMonitor.kreftjs +2 -2
- package/templates/app/frontend/index.html +1 -1
- package/templates/app/frontend/kreftjs.d.ts +1 -1
- package/templates/app/frontend/kreftjs.js +18 -18
- package/templates/app/frontend/pages/Dashboard.kreftjs +1 -1
- package/templates/app/frontend/pages/ErrorMonitor.kreftjs +1 -1
- package/templates/app/frontend/pages/Home.kreftjs +2 -2
- package/templates/errors/ErrorMonitor.kreftjs +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
Copyright 2026 Maxamuud Xuseen
|
|
2
|
+
|
|
3
|
+
Elastic License 2.0
|
|
4
|
+
|
|
5
|
+
URL: https://www.elastic.co/licensing/elastic-license
|
|
6
|
+
|
|
7
|
+
## Acceptance
|
|
8
|
+
|
|
9
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
10
|
+
|
|
11
|
+
## Copyright License
|
|
12
|
+
|
|
13
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide,
|
|
14
|
+
non-sublicensable, non-transferable license to use, copy, distribute, make
|
|
15
|
+
available, and prepare derivative works of the software, in each case subject to
|
|
16
|
+
the limitations and conditions below.
|
|
17
|
+
|
|
18
|
+
## Limitations
|
|
19
|
+
|
|
20
|
+
You may not provide the software to third parties as a hosted or managed
|
|
21
|
+
service, where the service provides users with access to any substantial set of
|
|
22
|
+
the features or functionality of the software.
|
|
23
|
+
|
|
24
|
+
You may not move, change, disable, or circumvent the license key functionality
|
|
25
|
+
in the software, and you may not remove or obscure any functionality in the
|
|
26
|
+
software that is protected by the license key.
|
|
27
|
+
|
|
28
|
+
You may not alter, remove, or obscure any licensing, copyright, or other notices
|
|
29
|
+
of the licensor in the software. Any use of the licensor’s trademarks is subject
|
|
30
|
+
to applicable law.
|
|
31
|
+
|
|
32
|
+
## Patents
|
|
33
|
+
|
|
34
|
+
The licensor grants you a license, under any patent claims the licensor can
|
|
35
|
+
license, or becomes able to license, to make, have made, use, sell, offer for
|
|
36
|
+
sale, import and have imported the software, in each case subject to the
|
|
37
|
+
limitations and conditions in this license. This license does not cover any
|
|
38
|
+
patent claims that you cause to be infringed by modifications or additions to
|
|
39
|
+
the software. If you or your company make any written claim that the software
|
|
40
|
+
infringes or contributes to infringement of any patent, your patent license for
|
|
41
|
+
the software granted under these terms ends immediately. If your company makes
|
|
42
|
+
such a claim, your patent license ends immediately for work on behalf of your
|
|
43
|
+
company.
|
|
44
|
+
|
|
45
|
+
## Notices
|
|
46
|
+
|
|
47
|
+
You must ensure that anyone who gets a copy of any part of the software from you
|
|
48
|
+
also gets a copy of these terms.
|
|
49
|
+
|
|
50
|
+
If you modify the software, you must include in any modified copies of the
|
|
51
|
+
software prominent notices stating that you have modified the software.
|
|
52
|
+
|
|
53
|
+
## No Other Rights
|
|
54
|
+
|
|
55
|
+
These terms do not imply any licenses other than those expressly granted in
|
|
56
|
+
these terms.
|
|
57
|
+
|
|
58
|
+
## Termination
|
|
59
|
+
|
|
60
|
+
If you use the software in violation of these terms, such use is not licensed,
|
|
61
|
+
and your licenses will automatically terminate. If the licensor provides you
|
|
62
|
+
with a notice of your violation, and you cease all violation of this license no
|
|
63
|
+
later than 30 days after you receive that notice, your licenses will be
|
|
64
|
+
reinstated retroactively. However, if you violate these terms after such
|
|
65
|
+
reinstatement, any additional violation of these terms will cause your licenses
|
|
66
|
+
to terminate automatically and permanently.
|
|
67
|
+
|
|
68
|
+
## No Liability
|
|
69
|
+
|
|
70
|
+
*As far as the law allows, the software comes as is, without any warranty or
|
|
71
|
+
condition, and the licensor will not be liable to you for any damages arising
|
|
72
|
+
out of these terms or the use or nature of the software, under any kind of
|
|
73
|
+
legal claim.*
|
|
74
|
+
|
|
75
|
+
## Definitions
|
|
76
|
+
|
|
77
|
+
The **licensor** is the entity offering these terms, and the **software** is the
|
|
78
|
+
software the licensor makes available under these terms, including any portion
|
|
79
|
+
of it.
|
|
80
|
+
|
|
81
|
+
**you** refers to the individual or entity agreeing to these terms.
|
|
82
|
+
|
|
83
|
+
**your company** is any legal entity, sole proprietorship, or other kind of
|
|
84
|
+
organization that you work for, plus all organizations that have control over,
|
|
85
|
+
are under the control of, or are under common control with that
|
|
86
|
+
organization. **control** means ownership of substantially all the assets of an
|
|
87
|
+
entity, or the power to direct its management and policies by vote, contract, or
|
|
88
|
+
otherwise. Control can be direct or indirect.
|
|
89
|
+
|
|
90
|
+
**your licenses** are all the licenses granted to you for the software under
|
|
91
|
+
these terms.
|
|
92
|
+
|
|
93
|
+
**use** means anything you do with the software requiring one of your licenses.
|
|
94
|
+
|
|
95
|
+
**trademark** means trademarks, service marks, and similar rights.
|
package/README.md
CHANGED
|
@@ -22,8 +22,8 @@ action add() { count++ }
|
|
|
22
22
|
You need [Node.js](https://nodejs.org) 22.5 or newer.
|
|
23
23
|
|
|
24
24
|
```bash
|
|
25
|
-
npm i -g kreftjs # once: makes the `
|
|
26
|
-
|
|
25
|
+
npm i -g kreftjs # once: makes the `kreft` command available everywhere
|
|
26
|
+
kreft new my-app # asks: JavaScript or TypeScript?
|
|
27
27
|
cd my-app
|
|
28
28
|
npm run dev
|
|
29
29
|
```
|
|
@@ -38,7 +38,7 @@ Open the address in the terminal (normally `http://localhost:8000`). A new proje
|
|
|
38
38
|
| **Router** | Nested routes, layouts, guards, error pages, clean URLs. |
|
|
39
39
|
| **Backend** | `Route`, controllers, form requests, policies, models with relations, soft deletes and scopes, migrations, seeders, factories, jobs, mail, notifications, cache, Redis, file storage, scheduling. |
|
|
40
40
|
| **Authentication** | Cookie sessions with CSRF protection, API tokens with permissions, device list, two-factor codes, email verification, account lockout. |
|
|
41
|
-
| **Tooling** | `
|
|
41
|
+
| **Tooling** | `kreft dev` with hot reload, DevTools, an error monitor, `kreft build` (CSP-safe), prerendering, TypeScript, Vite and Electron support, a safer `kreft add`, an MCP server for AI agents. |
|
|
42
42
|
|
|
43
43
|
## Learn more
|
|
44
44
|
|
|
@@ -49,7 +49,7 @@ Open the address in the terminal (normally `http://localhost:8000`). A new proje
|
|
|
49
49
|
| Add an API and a database | [Routing](docs/README.md#routing), [Models](docs/README.md#models-and-the-database), [Migrations](docs/README.md#migrations-seeders-and-factories) |
|
|
50
50
|
| Understand sign-in | [Authentication](docs/README.md#authentication) |
|
|
51
51
|
| Go to production | [Build and deploy](docs/README.md#build-and-deploy), [Production checklist](docs/README.md#production-checklist) |
|
|
52
|
-
| Look up a command | [Command line](docs/README.md#command-line), then `
|
|
52
|
+
| Look up a command | [Command line](docs/README.md#command-line), then `kreft list` |
|
|
53
53
|
|
|
54
54
|
## The demo
|
|
55
55
|
|
|
@@ -60,9 +60,9 @@ In this repository, `npm run dev` serves live examples of every feature at **htt
|
|
|
60
60
|
```text
|
|
61
61
|
kreftjs.js, kreftjs.d.ts the browser runtime and its TypeScript types
|
|
62
62
|
server.js, server.d.ts the backend entry point: require('kreftjs/server')
|
|
63
|
-
bin/ the `
|
|
63
|
+
bin/ the `kreft` command and the backend modules (bin/backend/)
|
|
64
64
|
tools/ hot reload client, DevTools, Vite plugin
|
|
65
|
-
templates/app/ the project that `
|
|
65
|
+
templates/app/ the project that `kreft new` creates
|
|
66
66
|
editors/vscode/ syntax colours and snippets for .kreftjs files
|
|
67
67
|
demo/ the interactive demo
|
|
68
68
|
docs/ the manual (README.md) and its viewer (Docs.kreftjs)
|
|
@@ -71,23 +71,23 @@ test/ security regression tests: npm test
|
|
|
71
71
|
|
|
72
72
|
## Security
|
|
73
73
|
|
|
74
|
-
Views are escaped, logins use HttpOnly cookies with CSRF protection, passwords use scrypt, and `
|
|
74
|
+
Views are escaped, logins use HttpOnly cookies with CSRF protection, passwords use scrypt, and `kreft dev` only answers your own computer. The manual has a [Security overview](docs/README.md#security-overview) and a [Production checklist](docs/README.md#production-checklist). Run `npm test` to run the security regression tests.
|
|
75
75
|
|
|
76
76
|
## Migrating from Som.js
|
|
77
77
|
|
|
78
|
-
Kreft is Som.js under a new name: the package is `kreftjs` (version 0.0.
|
|
78
|
+
Kreft is Som.js under a new name: the package is `kreftjs` (version 0.0.5-beta), the command is `kreft` (`kreftjs` works too), the global is `Kreftjs` and component files end in `.kreftjs`. The old names keep working, so an existing project runs without edits. New files and everything the tools write use the new names. Move over when it suits you. (`kreft` was an earlier spelling of the new name; it is accepted in the same places.)
|
|
79
79
|
|
|
80
80
|
| Som.js | Kreft | Still works? |
|
|
81
81
|
|---|---|---|
|
|
82
|
-
| `npm i -g somjs` | `npm i -g kreftjs` | `
|
|
83
|
-
| `som dev`, `som build`, `som make:page` … | `
|
|
82
|
+
| `npm i -g somjs` | `npm i -g kreftjs` | `kreftjs` is another name for `kreft`. Kreft does not install a `som` command, so it does not clash with an old Som.js (remove that with `npm rm -g somjs`). |
|
|
83
|
+
| `som dev`, `som build`, `som make:page` … | `kreft dev`, `kreft build`, `kreft make:page` … | Replace `som` with `kreftjs`. |
|
|
84
84
|
| `Counter.som` (and `Counter.kreft`) | `Counter.kreftjs` | Yes. All three extensions compile; a name that is missing with one extension is tried with the others (`layouts/app.kreftjs` finds `layouts/app.som`). |
|
|
85
85
|
| `s-if`, `s-each`, `s-model` … (every `s-` directive) | `k-if`, `k-each`, `k-model` … | Yes. Both prefixes are read in templates. |
|
|
86
86
|
| `<som-view>`, `<som-link>`, `<som-wait>`, `<som-component>`, `<som-yield>`, `<som-section>`, `<som-portal>` | `<kreft-view>`, `<kreft-link>` … | Yes. Both tag names work. |
|
|
87
87
|
| `Som` (global object) | `Kreftjs` | `Som` and `Kreft` point to the same object. `Som` is deprecated. |
|
|
88
88
|
| `Som.compileSom(source)` | `Kreftjs.compile(source)` | `compileSom` is kept as an alias. |
|
|
89
89
|
| `window.somDesktop` | `window.kreftDesktop` | Same object under both names. |
|
|
90
|
-
| `som.js`, `som.d.ts` in your project | `kreftjs.js`, `kreftjs.d.ts` | An existing `som.js` (or `kreft.js`) keeps working; `
|
|
90
|
+
| `som.js`, `som.d.ts` in your project | `kreftjs.js`, `kreftjs.d.ts` | An existing `som.js` (or `kreft.js`) keeps working; `kreft update` rewrites it in place with the new runtime. |
|
|
91
91
|
| `som.config.json`, `config/som.json` | `kreftjs.config.json`, `config/kreftjs.json` | Yes: `kreft.config.json` and `som.config.json` are read too (the new name wins). |
|
|
92
92
|
| `require('somjs/server')` | `require('kreftjs/server')` | Also accepted: `kreft/server`, `@kreft/server`, `somjs/server`, `som/server`, `@somjs/server`. |
|
|
93
93
|
| `som_session`, `som_2fa`, `som_bypass` cookies | `kreft_session`, `kreft_2fa`, `kreft_bypass` | `app/Auth/Session.js` belongs to your project, so an existing project keeps its `som_` names until you edit that file. The framework's CSRF check and the maintenance-mode bypass accept both. New projects use the new names. |
|
|
@@ -95,10 +95,10 @@ Kreft is Som.js under a new name: the package is `kreftjs` (version 0.0.3-beta),
|
|
|
95
95
|
| `window.__SOM_ENV__`, `__SOM_DEV__`, `__SOM_LANG__`, `__SOM_VITE__` | `__KREFT_ENV__` … | Read by the runtime under both names. |
|
|
96
96
|
| `/__som/…` dev-server addresses | `/__kreft/…` | The dev server answers both. |
|
|
97
97
|
| Vite: `import som from 'somjs/vite'` | `import kreftjs from 'kreftjs/vite'` | The plugin also exports `kreft`, `som` and `somPlugin`, and handles `.kreft` and `.som` files. |
|
|
98
|
-
| VS Code extension `.som` language | `.kreftjs` language | The new extension colours `.kreft` and `.som` files as well. Run `
|
|
98
|
+
| VS Code extension `.som` language | `.kreftjs` language | The new extension colours `.kreft` and `.som` files as well. Run `kreft vscode` to install it. |
|
|
99
99
|
|
|
100
100
|
Kept on purpose, with a TODO for 3.1: the `som_migrations` table (renaming it would lose the migration history of every deployed database), the `som:` prefix of `saved`/`Kreftjs.storage` keys in `localStorage`, and the `som:queue:` / `som:delayed:` Redis keys of the queue. Renaming them needs a migration with a fallback read, so it waits for a minor release.
|
|
101
101
|
|
|
102
102
|
## License
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
Kreft is released under the [Elastic License 2.0](LICENSE). You may use it, including to build and sell your own applications, copy it and change it. You may not offer Kreft itself to others as a hosted or managed service, and you may not remove or hide its license notices.
|
package/bin/add.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
*
|
|
2
|
+
* kreft add <packages...> / kreft install <packages...>
|
|
3
3
|
*
|
|
4
4
|
* Enterprise-Grade Security Gatekeeper & Package Installer for Kreft:
|
|
5
5
|
*
|
|
@@ -63,7 +63,7 @@ const BUILTIN_ALTERNATIVES = {
|
|
|
63
63
|
dotenv: 'Kreft automatically parses .env into process.env & Kreftjs.env natively out of the box.',
|
|
64
64
|
'body-parser': 'Kreft natively parses JSON, form-data, and raw payloads in request.js.',
|
|
65
65
|
cors: 'Kreft routes and dev server include built-in CORS origin and preflight validation.',
|
|
66
|
-
nodemon: 'Kreft includes built-in file watching, hot reloading, and dev tools (
|
|
66
|
+
nodemon: 'Kreft includes built-in file watching, hot reloading, and dev tools (kreft dev).',
|
|
67
67
|
sqlite3: 'Kreft includes a native zero-dependency SQLite driver (built-in). Use better-sqlite3 only if you need C-bindings.',
|
|
68
68
|
'cookie-parser': 'Kreft natively parses, signs, and sets cookies on request/response objects.',
|
|
69
69
|
multer: 'Kreft natively handles multipart file uploads via request.file() and request.files().',
|
|
@@ -889,7 +889,7 @@ function displayPackageInfoCards(projectDir, evaluationReports, auditData) {
|
|
|
889
889
|
type: 'update',
|
|
890
890
|
icon: yellow('🔔 Update Available:'),
|
|
891
891
|
message: `Version v${latestVersion} is out! (Installed: v${installedVersion})`,
|
|
892
|
-
action: `Run "
|
|
892
|
+
action: `Run "kreft update ${name}" to upgrade to the latest version.`,
|
|
893
893
|
});
|
|
894
894
|
} else {
|
|
895
895
|
notifications.push({
|
|
@@ -1029,18 +1029,18 @@ function runSecurityAudit(npmCmd, project, auditData) {
|
|
|
1029
1029
|
|
|
1030
1030
|
function printHelp() {
|
|
1031
1031
|
console.log(`
|
|
1032
|
-
${bold('
|
|
1032
|
+
${bold('kreft add <packages...>') } (alias: ${dim('kreft install')}, ${dim('kreft i')})
|
|
1033
1033
|
|
|
1034
1034
|
Enterprise-Grade Security Gatekeeper & Package Installer for Kreft.
|
|
1035
1035
|
|
|
1036
1036
|
Usage:
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1037
|
+
kreft add <packages...> Install package(s) with full security gatekeeper verification
|
|
1038
|
+
kreft add pg mysql2 Install verified database drivers
|
|
1039
|
+
kreft add -D vitest Install as devDependency
|
|
1040
|
+
kreft add --check <pkg> Inspect package security report without installing (alias: --dry-run)
|
|
1041
|
+
kreft add -y <pkg> Auto-confirm unverified packages in CI/CD (alias: --yes)
|
|
1042
|
+
kreft add --allow-scripts <pkg> Allow lifecycle scripts (postinstall/build)
|
|
1043
|
+
kreft add --force <pkg> Bypass security warnings & redundancy checks
|
|
1044
1044
|
|
|
1045
1045
|
Security Protections & Verification Rules:
|
|
1046
1046
|
1. Zero-Dependency Redundancy Guard:
|
package/bin/artisan-more.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Full-stack CLI commands:
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
4
|
+
* kreft list every command (yours too)
|
|
5
|
+
* kreft about versions, settings, folders
|
|
6
|
+
* kreft tinker a console with your models, DB, Cache… (await works)
|
|
7
|
+
* kreft key:generate a new APP_KEY in .env
|
|
8
|
+
* kreft down [--secret=x] / kreft up maintenance mode
|
|
9
|
+
* kreft db:wipe drop every table
|
|
10
|
+
* kreft migrate:refresh [--seed] undo every migration, then run them again
|
|
11
|
+
* kreft migrate:reset undo every migration
|
|
12
|
+
* kreft queue:work [--queue=a,b] [--once] [--stop-when-empty]
|
|
13
|
+
* kreft queue:failed / queue:retry <id|all> / queue:flush / queue:table
|
|
14
|
+
* kreft schedule:work / schedule:run / schedule:list
|
|
15
|
+
* kreft cache:clear / cache:table
|
|
16
|
+
* kreft notifications:table
|
|
17
|
+
* kreft event:list
|
|
18
|
+
* kreft make:job, make:event, make:listener, make:mail, make:notification, make:policy, make:request,
|
|
19
19
|
* make:resource, make:factory, make:rule, make:command, make:observer
|
|
20
|
-
* Your own commands: app/Console/Commands/*.js (
|
|
20
|
+
* Your own commands: app/Console/Commands/*.js (kreft make:command SendReport)
|
|
21
21
|
*/
|
|
22
22
|
const fs = require('fs');
|
|
23
23
|
const path = require('path');
|
|
@@ -42,7 +42,7 @@ async function withApp(o, ctx, fn) {
|
|
|
42
42
|
|
|
43
43
|
/* ------------------------------------------------------------------ built-in migration tables */
|
|
44
44
|
const tableStubs = {
|
|
45
|
-
jobs: `// The queue's tables: jobs waiting (
|
|
45
|
+
jobs: `// The queue's tables: jobs waiting (kreft queue:work, or kreft dev, runs them) and jobs that failed
|
|
46
46
|
module.exports = {
|
|
47
47
|
up(schema) {
|
|
48
48
|
schema.create('jobs', (table) => {
|
|
@@ -110,7 +110,7 @@ function tableCommand(kind, fileName) {
|
|
|
110
110
|
const exists = fs.existsSync(dir) && fs.readdirSync(dir).some((f) => f.includes(fileName));
|
|
111
111
|
if (exists) return console.log(` There is already a ${fileName} migration.`);
|
|
112
112
|
write(path.join(dir, `${nextStamp(dir)}_${fileName}.js`), tableStubs[kind]);
|
|
113
|
-
console.log(dim(' Then:
|
|
113
|
+
console.log(dim(' Then: kreft migrate'));
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
116
|
commands['queue:table'] = tableCommand('jobs', 'create_jobs_table');
|
|
@@ -124,7 +124,7 @@ commands['queue:work'] = async function (args) {
|
|
|
124
124
|
const queues = (raw.split('=')[1] || 'default').split(',');
|
|
125
125
|
await withApp(o, ctx, async () => {
|
|
126
126
|
const q = require('./backend/queue.js');
|
|
127
|
-
if (!(await q.tablesReady())) return console.error(' No jobs table. Make it with:
|
|
127
|
+
if (!(await q.tablesReady())) return console.error(' No jobs table. Make it with: kreft queue:table, then kreft migrate');
|
|
128
128
|
console.log(` Working on the ${queues.join(', ')} queue${queues.length > 1 ? 's' : ''}. Stop with Ctrl+C.\n`);
|
|
129
129
|
await q.work({ queues, once: o.flags.has('once'), stopWhenEmpty: o.flags.has('stop-when-empty'), log: console.log });
|
|
130
130
|
});
|
|
@@ -135,13 +135,13 @@ commands['queue:failed'] = async function (args) {
|
|
|
135
135
|
const rows = await db.query('SELECT id, queue, payload, exception, failed_at FROM failed_jobs ORDER BY id DESC LIMIT 50');
|
|
136
136
|
if (!rows.length) return console.log(' No failed jobs.');
|
|
137
137
|
for (const r of rows) console.log(` ${String(r.id).padEnd(5)} ${String(r.failed_at).slice(0, 19)} ${JSON.parse(r.payload).class} ${dim(String(r.exception).split('\n')[0].slice(0, 90))}`);
|
|
138
|
-
console.log(dim('\n Try one again:
|
|
138
|
+
console.log(dim('\n Try one again: kreft queue:retry <id> (or all)'));
|
|
139
139
|
});
|
|
140
140
|
};
|
|
141
141
|
commands['queue:retry'] = async function (args) {
|
|
142
142
|
const o = options(args), ctx = context(o);
|
|
143
143
|
const which = o._[0];
|
|
144
|
-
if (!which) return console.error('
|
|
144
|
+
if (!which) return console.error(' kreft queue:retry <id> or kreft queue:retry all');
|
|
145
145
|
await withDb(o, ctx, async (db) => {
|
|
146
146
|
const { Builder } = require('./backend/query.js');
|
|
147
147
|
const rows = which === 'all' ? await new Builder('failed_jobs').get() : await new Builder('failed_jobs').where('id', which).get();
|
|
@@ -169,10 +169,10 @@ commands['queue:stop'] = async function (args) {
|
|
|
169
169
|
q.stop(target);
|
|
170
170
|
if (target === 'all' || target === '*') {
|
|
171
171
|
console.log(` ${red('STOPPED')} All running queues have been stopped.`);
|
|
172
|
-
console.log(dim(' Resume anytime with:
|
|
172
|
+
console.log(dim(' Resume anytime with: kreft queue:resume --all'));
|
|
173
173
|
} else {
|
|
174
174
|
console.log(` ${yellow('STOPPED')} Queue "${target}" has been stopped.`);
|
|
175
|
-
console.log(dim(` Resume with:
|
|
175
|
+
console.log(dim(` Resume with: kreft queue:resume ${target}`));
|
|
176
176
|
}
|
|
177
177
|
};
|
|
178
178
|
commands['queue:pause'] = commands['queue:stop'];
|
|
@@ -417,7 +417,7 @@ commands['sitemap'] = async function (args) {
|
|
|
417
417
|
}
|
|
418
418
|
bar.complete(`${routes.length} URLs indexed`);
|
|
419
419
|
|
|
420
|
-
if (/^https?:\/\/(localhost|127\.0\.0\.1|\[::1\])(:|\/|$)/.test(baseUrl)) console.log(` WARN The sitemap uses ${baseUrl}. Search engines need your real address:
|
|
420
|
+
if (/^https?:\/\/(localhost|127\.0\.0\.1|\[::1\])(:|\/|$)/.test(baseUrl)) console.log(` WARN The sitemap uses ${baseUrl}. Search engines need your real address: kreft sitemap --url https://example.com (or set APP_URL)`);
|
|
421
421
|
const { SEO } = require('./backend/support.js');
|
|
422
422
|
const xml = SEO.sitemap(routes, { baseUrl });
|
|
423
423
|
const robots = SEO.robots({ allow: '/', sitemapUrl: `${baseUrl.replace(/\/+$/, '')}/sitemap.xml` });
|
|
@@ -602,7 +602,7 @@ commands.down = function (args) {
|
|
|
602
602
|
const data = { time: Math.floor(Date.now() / 1000), retry: Number(get('retry')) || null, message: get('message') || 'We are making the site better. Please come back soon.', secret };
|
|
603
603
|
fs.mkdirSync(path.dirname(downFile(ctx)), { recursive: true });
|
|
604
604
|
fs.writeFileSync(downFile(ctx), JSON.stringify(data, null, 2), { mode: 0o600 });
|
|
605
|
-
console.log(` ${yellow('DOWN')} The app is in maintenance mode: visitors see a 503 page.${secret ? `\n You can still use it at: /${secret} (once; a cookie remembers you)` : ''}\n Back with:
|
|
605
|
+
console.log(` ${yellow('DOWN')} The app is in maintenance mode: visitors see a 503 page.${secret ? `\n You can still use it at: /${secret} (once; a cookie remembers you)` : ''}\n Back with: kreft up`);
|
|
606
606
|
};
|
|
607
607
|
commands.up = function (args) {
|
|
608
608
|
const o = options(args), ctx = context(o);
|
|
@@ -621,7 +621,7 @@ commands.about = function (args) {
|
|
|
621
621
|
row('Node.js', process.version);
|
|
622
622
|
row('App name', process.env.APP_NAME || '-');
|
|
623
623
|
row('App URL', process.env.APP_URL || '-');
|
|
624
|
-
row('APP_KEY', process.env.APP_KEY ? green('set') : red('missing (
|
|
624
|
+
row('APP_KEY', process.env.APP_KEY ? green('set') : red('missing (kreft key:generate)'));
|
|
625
625
|
row('TypeScript', ok(has(path.join(ctx.project, 'tsconfig.json'))));
|
|
626
626
|
row('Maintenance mode', has(downFile(ctx)) ? yellow('down') : 'live');
|
|
627
627
|
console.log('\n Drivers');
|
|
@@ -653,7 +653,7 @@ commands.tinker = async function (args) {
|
|
|
653
653
|
const stub = {
|
|
654
654
|
job: (n) => `const { Job } = require('kreftjs/server')
|
|
655
655
|
|
|
656
|
-
// dispatch(new ${n}(…)) puts it on the queue;
|
|
656
|
+
// dispatch(new ${n}(…)) puts it on the queue; kreft queue:work (or kreft dev) runs handle()
|
|
657
657
|
class ${n} extends Job {
|
|
658
658
|
static tries = 3 // try again after an error, up to 3 times
|
|
659
659
|
static backoff = 10 // seconds between tries
|
|
@@ -728,7 +728,7 @@ class ${n} extends Notification {
|
|
|
728
728
|
}
|
|
729
729
|
|
|
730
730
|
via(notifiable) {
|
|
731
|
-
return ['mail', 'database'] // 'database' needs the notifications table:
|
|
731
|
+
return ['mail', 'database'] // 'database' needs the notifications table: kreft notifications:table
|
|
732
732
|
}
|
|
733
733
|
|
|
734
734
|
toMail(notifiable) {
|
|
@@ -894,21 +894,21 @@ function makeIn(folder, suffix, build, usage) {
|
|
|
894
894
|
return build(o, ctx, dirs, name, path.join(ctx.base, ...folder.split('/'), ...dirs, name + '.js'));
|
|
895
895
|
};
|
|
896
896
|
}
|
|
897
|
-
make.job = makeIn('app/Jobs', '', (o, c, d, n, f) => write(f, stub.job(n)), '
|
|
898
|
-
make.event = makeIn('app/Events', '', (o, c, d, n, f) => write(f, stub.event(n)), '
|
|
899
|
-
make.listener = makeIn('app/Listeners', '', (o, c, d, n, f) => write(f, stub.listener(n, o.event)), '
|
|
900
|
-
make.mail = makeIn('app/Mail', 'Mail', (o, c, d, n, f) => write(f, stub.mail(n)), '
|
|
901
|
-
make.notification = makeIn('app/Notifications', '', (o, c, d, n, f) => write(f, stub.notification(n)), '
|
|
902
|
-
make.policy = makeIn('app/Policies', 'Policy', (o, c, d, n, f) => write(f, stub.policy(n, o.model || n.replace(/Policy$/, ''))), '
|
|
903
|
-
make.request = make.request || makeIn('app/Http/Requests', 'Request', (o, c, d, n, f) => write(f, stub.request(n)), '
|
|
904
|
-
make.resource = make.resource || makeIn('app/Http/Resources', 'Resource', (o, c, d, n, f) => write(f, stub.resource(n)), '
|
|
905
|
-
make.rule = make.rule || makeIn('app/Rules', '', (o, c, d, n, f) => write(f, stub.rule(n)), '
|
|
906
|
-
make.observer = makeIn('app/Observers', 'Observer', (o, c, d, n, f) => write(f, stub.observer(n, o.model || n.replace(/Observer$/, ''))), '
|
|
907
|
-
make.command = makeIn('app/Console/Commands', '', (o, c, d, n, f) => write(f, stub.command(n, o.command || n.replace(/Command$/, '').replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase().replace(/-/, ':'))), '
|
|
897
|
+
make.job = makeIn('app/Jobs', '', (o, c, d, n, f) => write(f, stub.job(n)), 'kreft make:job SendWelcomeEmail');
|
|
898
|
+
make.event = makeIn('app/Events', '', (o, c, d, n, f) => write(f, stub.event(n)), 'kreft make:event OrderShipped');
|
|
899
|
+
make.listener = makeIn('app/Listeners', '', (o, c, d, n, f) => write(f, stub.listener(n, o.event)), 'kreft make:listener SendShipmentNotice --event OrderShipped');
|
|
900
|
+
make.mail = makeIn('app/Mail', 'Mail', (o, c, d, n, f) => write(f, stub.mail(n)), 'kreft make:mail WelcomeMail');
|
|
901
|
+
make.notification = makeIn('app/Notifications', '', (o, c, d, n, f) => write(f, stub.notification(n)), 'kreft make:notification InvoicePaid');
|
|
902
|
+
make.policy = makeIn('app/Policies', 'Policy', (o, c, d, n, f) => write(f, stub.policy(n, o.model || n.replace(/Policy$/, ''))), 'kreft make:policy PostPolicy [--model Post]');
|
|
903
|
+
make.request = make.request || makeIn('app/Http/Requests', 'Request', (o, c, d, n, f) => write(f, stub.request(n)), 'kreft make:request StorePostRequest');
|
|
904
|
+
make.resource = make.resource || makeIn('app/Http/Resources', 'Resource', (o, c, d, n, f) => write(f, stub.resource(n)), 'kreft make:resource PostResource');
|
|
905
|
+
make.rule = make.rule || makeIn('app/Rules', '', (o, c, d, n, f) => write(f, stub.rule(n)), 'kreft make:rule Uppercase');
|
|
906
|
+
make.observer = makeIn('app/Observers', 'Observer', (o, c, d, n, f) => write(f, stub.observer(n, o.model || n.replace(/Observer$/, ''))), 'kreft make:observer PostObserver [--model Post]');
|
|
907
|
+
make.command = makeIn('app/Console/Commands', '', (o, c, d, n, f) => write(f, stub.command(n, o.command || n.replace(/Command$/, '').replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase().replace(/-/, ':'))), 'kreft make:command SendReport [--command report:send]');
|
|
908
908
|
make.factory = function (args) {
|
|
909
909
|
const o = options(args), ctx = context(o);
|
|
910
910
|
let { name } = nested(o._[0]);
|
|
911
|
-
if (!name) return console.error('
|
|
911
|
+
if (!name) return console.error(' kreft make:factory PostFactory [--model Post]');
|
|
912
912
|
if (!name.endsWith('Factory')) name += 'Factory';
|
|
913
913
|
const model = o.model ? nested(o.model) : { dirs: [], name: name.replace(/Factory$/, '') };
|
|
914
914
|
write(path.join(ctx.base, 'database', 'factories', name + '.js'), stub.factory(name, model.name, '../../app/Models/' + [...model.dirs, model.name].join('/')));
|
|
@@ -979,7 +979,7 @@ commands.list = function (args) {
|
|
|
979
979
|
const groups = {};
|
|
980
980
|
for (const c of builtIn) (groups[c.includes(':') ? c.split(':')[0] : ''] = groups[c.includes(':') ? c.split(':')[0] : ''] || []).push(c);
|
|
981
981
|
console.log(`\n Kreft ${pkg.version}\n\n Commands:`);
|
|
982
|
-
console.log(' new dev serve build update db vscode (
|
|
982
|
+
console.log(' new dev serve build update db vscode (kreft help for their options)');
|
|
983
983
|
console.log(' ' + (groups[''] || []).join(' '));
|
|
984
984
|
for (const [g, list] of Object.entries(groups)) if (g) console.log(` ${g}\n ${list.join(' ')}`);
|
|
985
985
|
const mine = customCommands(ctx.base);
|