@stacksjs/actions 0.70.87 → 0.70.90
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/action.js +78 -2
- package/dist/actions.js +2 -2
- package/dist/add.js +20 -2
- package/dist/ai/request-model-access.js +10 -2
- package/dist/auth/client.js +44 -3
- package/dist/auth/prune.js +35 -2
- package/dist/auth/setup.js +152 -36
- package/dist/auth/token.js +10 -2
- package/dist/blog-admin.d.ts +55 -0
- package/dist/blog-admin.js +156 -0
- package/dist/blog.d.ts +11 -0
- package/dist/blog.js +306 -56
- package/dist/build/cli.js +6 -2
- package/dist/build/component-libs.js +7 -2
- package/dist/build/core.js +55 -2
- package/dist/build/desktop.js +5 -2
- package/dist/build/docs.js +5 -2
- package/dist/build/frontend-static.js +123 -8
- package/dist/build/server.js +6 -2
- package/dist/build/stacks.js +8 -2
- package/dist/build/views.js +11 -2
- package/dist/build.js +64 -2
- package/dist/bump.js +162 -7
- package/dist/cdn/invalidate-cache.js +0 -1
- package/dist/changelog.js +27 -3
- package/dist/check/ports.js +16 -2
- package/dist/clean.js +4 -2
- package/dist/commit.js +12 -2
- package/dist/copy-types.js +10 -3
- package/dist/database/seed.js +26 -2
- package/dist/deploy/create-receipt-rule.js +36 -2
- package/dist/deploy/index.js +1318 -44
- package/dist/dev/api.js +94 -6
- package/dist/dev/components.js +7 -2
- package/dist/dev/dashboard-globals.js +89 -3
- package/dist/dev/dashboard-utils.js +380 -2
- package/dist/dev/dashboard.js +435 -8
- package/dist/dev/desktop.js +5 -2
- package/dist/dev/docs.js +24 -2
- package/dist/dev/index.js +29 -2
- package/dist/dev/migrate-watcher.js +74 -2
- package/dist/dev/system-tray.js +5 -2
- package/dist/dev/views.js +147 -2
- package/dist/discover-packages.js +32 -2
- package/dist/domains/add.js +61 -2
- package/dist/domains/purchase.js +66 -2
- package/dist/domains/remove.js +24 -2
- package/dist/examples.js +34 -2
- package/dist/find-projects.js +16 -2
- package/dist/fresh.js +17 -2
- package/dist/generate/action-types.js +9 -4
- package/dist/generate/component-meta.js +9 -3
- package/dist/generate/custom-cli-file.js +20 -3
- package/dist/generate/env-files.js +46 -6
- package/dist/generate/ide-helpers.js +8 -3
- package/dist/generate/index.js +158 -2
- package/dist/generate/lib-entries.js +16 -3
- package/dist/generate/pantry-file.js +46 -2
- package/dist/generate/symlink-core.js +2 -2
- package/dist/generate/types.js +3 -2
- package/dist/generate/vscode-custom-data.js +9 -3
- package/dist/generate/web-types.js +0 -1
- package/dist/helpers/component-meta.js +295 -2
- package/dist/helpers/index.js +1 -2
- package/dist/helpers/lib-entries.js +73 -2
- package/dist/helpers/package-json.js +45 -14
- package/dist/helpers/utils.js +105 -2
- package/dist/helpers/vscode-custom-data.js +30 -2
- package/dist/index.d.ts +13 -0
- package/dist/index.js +50 -2
- package/dist/key-generate.js +24 -2
- package/dist/lint/fix.js +4 -3
- package/dist/lint/index.js +4 -3
- package/dist/lint/lint.js +34 -2
- package/dist/make-command.js +64 -14
- package/dist/make-job.js +41 -16
- package/dist/make-policy.js +74 -26
- package/dist/make-resource.js +50 -21
- package/dist/make.js +328 -2
- package/dist/migrate/database.js +16 -2
- package/dist/migrate/fresh.js +31 -2
- package/dist/orm/base.js +0 -2
- package/dist/orm/test.js +0 -1
- package/dist/prepublish.js +16 -2
- package/dist/queue/clear.js +42 -2
- package/dist/queue/dlq-purge.js +28 -2
- package/dist/queue/dlq-retry.js +35 -2
- package/dist/queue/dlq.js +55 -5
- package/dist/queue/failed.js +69 -5
- package/dist/queue/flush.js +49 -3
- package/dist/queue/inspect.js +154 -8
- package/dist/queue/list.js +69 -5
- package/dist/queue/monitor.js +94 -6
- package/dist/queue/pause.js +28 -2
- package/dist/queue/quarantine.js +42 -3
- package/dist/queue/resume.js +27 -2
- package/dist/queue/retry.js +41 -2
- package/dist/queue/schedule-list.js +33 -5
- package/dist/queue/schedule.js +12 -2
- package/dist/queue/status.js +68 -5
- package/dist/queue/table.js +10 -2
- package/dist/queue/unquarantine.js +27 -2
- package/dist/queue/work.js +57 -2
- package/dist/release.js +21 -3
- package/dist/route/list.js +78 -3
- package/dist/run-action.js +1 -2
- package/dist/saas/setup.js +9 -2
- package/dist/scaffold-crud.js +164 -40
- package/dist/schedule/run.js +7 -2
- package/dist/search/flush.js +10 -2
- package/dist/search/import.js +10 -2
- package/dist/search/settings-list.js +10 -2
- package/dist/search/settings.js +9 -2
- package/dist/serve/api.js +35 -2
- package/dist/setup/index.js +1 -2
- package/dist/setup/ssl.js +271 -2
- package/dist/stacks.js +265 -2
- package/dist/templates.js +301 -2
- package/dist/test/feature.js +11 -2
- package/dist/test/index.js +11 -2
- package/dist/test/ui.js +4 -2
- package/dist/test/unit.js +11 -2
- package/dist/typecheck.js +4 -2
- package/dist/types.js +16 -2
- package/dist/upgrade/binary.js +29 -2
- package/dist/upgrade/bun.js +0 -1
- package/dist/upgrade/dependencies.js +0 -2
- package/dist/upgrade/framework-utils.js +193 -2
- package/dist/upgrade/framework.js +310 -7
- package/dist/upgrade/index.js +17 -2
- package/dist/upgrade/packages.js +99 -12
- package/dist/upgrade/shell.js +40 -4
- package/dist/upgrade.js +38 -2
- package/package.json +16 -16
- package/dist/chunk-0c8sd1t6.js +0 -2
- package/dist/chunk-0g2nzhx9.js +0 -240
- package/dist/chunk-0gadhvn7.js +0 -3
- package/dist/chunk-0h27aa4r.js +0 -93
- package/dist/chunk-3peh8kqs.js +0 -851
- package/dist/chunk-62gdfav8.js +0 -3
- package/dist/chunk-6bk53y02.js +0 -3
- package/dist/chunk-78c5n3s2.js +0 -3
- package/dist/chunk-c74qv38e.js +0 -17
- package/dist/chunk-cdk2r2jd.js +0 -1
- package/dist/chunk-dbz9dp2h.js +0 -3
- package/dist/chunk-e142dheq.js +0 -3
- package/dist/chunk-ec4gky40.js +0 -3
- package/dist/chunk-h3d81wrg.js +0 -3
- package/dist/chunk-m3q0x4h0.js +0 -688
- package/dist/chunk-mqgbyhph.js +0 -5
- package/dist/chunk-n24m8prb.js +0 -3
- package/dist/chunk-n5eqwhck.js +0 -7
- package/dist/chunk-nsvnqv8y.js +0 -5
- package/dist/chunk-nty6mmx4.js +0 -283
- package/dist/chunk-s735m9mg.js +0 -1
- package/dist/chunk-tpb8jgsk.js +0 -7
- package/dist/chunk-tsbk5vne.js +0 -3
- package/dist/chunk-xg9xscqz.js +0 -1
- package/dist/chunk-y6e448he.js +0 -7
|
@@ -1,26 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
import{
|
|
3
|
-
|
|
1
|
+
import { log } from "@stacksjs/logging";
|
|
2
|
+
import { packageJsonPath } from "@stacksjs/path";
|
|
3
|
+
import { writeTextFile } from "@stacksjs/storage";
|
|
4
|
+
import library from "~/config/library";
|
|
5
|
+
export async function generatePackageJson(type) {
|
|
6
|
+
let name, description, directory, keywords, config, prettyName;
|
|
7
|
+
if (type === "web-components") {
|
|
8
|
+
name = library.webComponents?.name;
|
|
9
|
+
description = library.webComponents?.description;
|
|
10
|
+
directory = "components";
|
|
11
|
+
keywords = library.webComponents?.keywords;
|
|
12
|
+
config = "web-components";
|
|
13
|
+
} else if (type === "functions") {
|
|
14
|
+
name = library.functions?.name;
|
|
15
|
+
description = library.functions?.description;
|
|
16
|
+
directory = "functions";
|
|
17
|
+
keywords = library.functions?.keywords;
|
|
18
|
+
config = "functions";
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
await writeTextFile({
|
|
22
|
+
path: packageJsonPath(type),
|
|
23
|
+
data: `{
|
|
24
|
+
"name": "${name}",
|
|
4
25
|
"type": "module",
|
|
5
26
|
"version": "",
|
|
6
27
|
"packageManager": "bun",
|
|
7
|
-
"description": "${
|
|
8
|
-
"author": "${
|
|
28
|
+
"description": "${description}",
|
|
29
|
+
"author": "${library.author}",
|
|
9
30
|
"license": "MIT",
|
|
10
|
-
"homepage": "https://github.com/${
|
|
31
|
+
"homepage": "https://github.com/${library.repository}/tree/main/${directory}#readme",
|
|
11
32
|
"repository": {
|
|
12
33
|
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/${
|
|
14
|
-
"directory": "${
|
|
34
|
+
"url": "git+https://github.com/${library.repository}.git",
|
|
35
|
+
"directory": "${directory}"
|
|
15
36
|
},
|
|
16
37
|
"bugs": {
|
|
17
|
-
"url": "https://github.com/${
|
|
38
|
+
"url": "https://github.com/${library.repository}/issues"
|
|
18
39
|
},
|
|
19
|
-
"keywords": ${JSON.stringify(
|
|
20
|
-
"contributors": ${JSON.stringify(
|
|
40
|
+
"keywords": ${JSON.stringify(keywords)},
|
|
41
|
+
"contributors": ${JSON.stringify(library.contributors)},
|
|
21
42
|
"exports": {
|
|
22
43
|
".": {
|
|
23
|
-
"types": "./dist/index.d.
|
|
44
|
+
"types": "./dist/index.d.js",
|
|
24
45
|
"require": "./dist/index.cjs",
|
|
25
46
|
"import": "./dist/index.js"
|
|
26
47
|
}
|
|
@@ -33,11 +54,21 @@ import{Gb as q}from"../chunk-tsbk5vne.js";import"../chunk-h3d81wrg.js";import{lo
|
|
|
33
54
|
"README.md"
|
|
34
55
|
],
|
|
35
56
|
"scripts": {
|
|
36
|
-
"build": "vite build -c ../build/${
|
|
57
|
+
"build": "vite build -c ../build/${config}.ts",
|
|
37
58
|
"prepublishOnly": "bun run build"
|
|
38
59
|
},
|
|
39
60
|
"devDependencies": {
|
|
40
61
|
"stacks": "workspace:*"
|
|
41
62
|
}
|
|
42
63
|
}
|
|
43
|
-
`
|
|
64
|
+
`
|
|
65
|
+
});
|
|
66
|
+
if (type === "web-components")
|
|
67
|
+
prettyName = "Web Component library";
|
|
68
|
+
else if (type === "functions")
|
|
69
|
+
prettyName = "Function Library";
|
|
70
|
+
log.success(`Created ${prettyName} package.json file`);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
log.error(`There was an error creating the ${prettyName} package.json`, err);
|
|
73
|
+
}
|
|
74
|
+
}
|
package/dist/helpers/utils.js
CHANGED
|
@@ -1,2 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
import{
|
|
1
|
+
var {require}=import.meta;import { existsSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { buddyOptions, runCommand, runCommands } from "@stacksjs/cli";
|
|
6
|
+
import { err } from "@stacksjs/error-handling";
|
|
7
|
+
import { log } from "@stacksjs/logging";
|
|
8
|
+
import * as p from "@stacksjs/path";
|
|
9
|
+
async function resolveActionFile(action) {
|
|
10
|
+
const candidates = [];
|
|
11
|
+
candidates.push(p.actionsPath(`src/${action}.ts`));
|
|
12
|
+
try {
|
|
13
|
+
const pkgUrl = import.meta.resolve("@stacksjs/actions/package.json");
|
|
14
|
+
if (pkgUrl) {
|
|
15
|
+
const pkgPath = new URL(pkgUrl).pathname, pkgRoot = pkgPath.slice(0, pkgPath.lastIndexOf("/"));
|
|
16
|
+
candidates.push(`${pkgRoot}/dist/${action}.js`);
|
|
17
|
+
candidates.push(`${pkgRoot}/dist/src/${action}.js`);
|
|
18
|
+
candidates.push(`${pkgRoot}/src/${action}.ts`);
|
|
19
|
+
}
|
|
20
|
+
} catch {}
|
|
21
|
+
for (const candidate of candidates)
|
|
22
|
+
if (await Bun.file(candidate).exists())
|
|
23
|
+
return candidate;
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
export async function runAction(action, options) {
|
|
27
|
+
log.debug(`[action] Running: ${action}`);
|
|
28
|
+
if (action === "dev/views")
|
|
29
|
+
try {
|
|
30
|
+
const pantryPath = p.projectPath("pantry");
|
|
31
|
+
if (!process.env.NODE_PATH?.includes(pantryPath)) {
|
|
32
|
+
process.env.NODE_PATH = process.env.NODE_PATH ? `${pantryPath}:${process.env.NODE_PATH}` : pantryPath;
|
|
33
|
+
require("module").Module._initPaths?.();
|
|
34
|
+
}
|
|
35
|
+
const viewsEntries = [
|
|
36
|
+
p.projectPath("storage/framework/core/actions/src/dev/views.ts"),
|
|
37
|
+
p.frameworkPath("actions/src/dev/views.ts")
|
|
38
|
+
];
|
|
39
|
+
for (const entry of viewsEntries)
|
|
40
|
+
if (existsSync(entry)) {
|
|
41
|
+
await import(entry);
|
|
42
|
+
return { ok: !0, value: {} };
|
|
43
|
+
}
|
|
44
|
+
return err("dev/views entry not found");
|
|
45
|
+
} catch (error) {
|
|
46
|
+
return err(`Failed to start dev server: ${error}`);
|
|
47
|
+
}
|
|
48
|
+
if (!(action.includes("/") || ["dev", "build", "install", "upgrade", "migrate"].some((prefix) => action.startsWith(prefix)))) {
|
|
49
|
+
const glob = new Bun.Glob("**/*.{ts,js}"), scanOptions = { cwd: p.userActionsPath(), onlyFiles: !0, absolute: !0 }, matchingFiles = [], basePath = p.userActionsPath();
|
|
50
|
+
for await (const file of glob.scan(scanOptions)) {
|
|
51
|
+
if (file.replace(`${basePath}/`, "").replace(/\.(ts|js)$/, "") === action || file.endsWith(`${action}.ts`) || file.endsWith(`${action}.js`)) {
|
|
52
|
+
log.debug(`[action] Resolved: ${action} \u2192 ${file}`);
|
|
53
|
+
return await (await import(file)).default.handle(void 0);
|
|
54
|
+
}
|
|
55
|
+
matchingFiles.push(file);
|
|
56
|
+
}
|
|
57
|
+
for (const file of matchingFiles)
|
|
58
|
+
try {
|
|
59
|
+
const a = await import(file);
|
|
60
|
+
if (a.name === action) {
|
|
61
|
+
log.debug(`[action] Resolved: ${action} \u2192 ${file}`);
|
|
62
|
+
return await a.handle();
|
|
63
|
+
}
|
|
64
|
+
} catch (error) {}
|
|
65
|
+
}
|
|
66
|
+
const path = await resolveActionFile(action);
|
|
67
|
+
if (!path)
|
|
68
|
+
return err(`Action '${action}' not found in storage/framework/core/actions/src or @stacksjs/actions`);
|
|
69
|
+
log.debug(`[action] Resolved: ${action} \u2192 ${path}`);
|
|
70
|
+
const isDevAction = action.startsWith("dev/"), watchFlag = isDevAction ? "--watch" : "", opts = isDevAction ? "" : buddyOptions(options) || "", cmd = `bun ${watchFlag} ${path} ${opts}`.trimEnd(), pantryNodePath = p.projectPath("pantry"), existingNodePath = process.env.NODE_PATH, nodePath = existingNodePath ? `${pantryNodePath}:${existingNodePath}` : pantryNodePath, shouldInherit = options?.verbose || isDevAction && !options?.quiet, optionsWithCwd = {
|
|
71
|
+
cwd: options?.cwd || p.projectPath(),
|
|
72
|
+
...options,
|
|
73
|
+
stdout: shouldInherit ? "inherit" : void 0,
|
|
74
|
+
stderr: shouldInherit ? "inherit" : void 0,
|
|
75
|
+
env: { ...options?.env, NODE_PATH: nodePath, ...isDevAction ? { STACKS_DEV_SERVER: "1" } : {} }
|
|
76
|
+
}, result = await runCommand(cmd, optionsWithCwd);
|
|
77
|
+
log.debug(`[action] Completed: ${action}`);
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
export async function runActions(actions, options) {
|
|
81
|
+
if (!actions.length)
|
|
82
|
+
return err("No actions were specified");
|
|
83
|
+
for (const action of actions)
|
|
84
|
+
if (!hasAction(action))
|
|
85
|
+
return err(`The specified action "${action}" does not exist`);
|
|
86
|
+
const opts = buddyOptions(options) || "", o = {
|
|
87
|
+
cwd: options?.cwd || p.projectPath(),
|
|
88
|
+
...options
|
|
89
|
+
}, commands = actions.map((action) => `bun ${p.relativeActionsPath(`src/${action}.ts`)} ${opts}`);
|
|
90
|
+
return await runCommands(commands, o);
|
|
91
|
+
}
|
|
92
|
+
export function hasAction(action) {
|
|
93
|
+
const userActionPatterns = [
|
|
94
|
+
`${action}.ts`,
|
|
95
|
+
`${action}`,
|
|
96
|
+
`Dashboard/${action}.ts`,
|
|
97
|
+
`Dashboard/${action}`,
|
|
98
|
+
`Buddy/${action}.ts`,
|
|
99
|
+
`Buddy/${action}`
|
|
100
|
+
], actionPatterns = [`src/${action}.ts`, `src/${action}`, `${action}.ts`, `${action}`];
|
|
101
|
+
return [
|
|
102
|
+
...userActionPatterns.map((pattern) => p.userActionsPath(pattern)),
|
|
103
|
+
...actionPatterns.map((pattern) => p.actionsPath(pattern))
|
|
104
|
+
].some((candidate) => existsSync(candidate));
|
|
105
|
+
}
|
|
@@ -1,2 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
import{
|
|
1
|
+
import { err, ok } from "@stacksjs/error-handling";
|
|
2
|
+
import { log } from "@stacksjs/logging";
|
|
3
|
+
import { customElementsDataPath } from "@stacksjs/path";
|
|
4
|
+
import { writeTextFile } from "@stacksjs/storage";
|
|
5
|
+
import library from "~/config/library";
|
|
6
|
+
function generateComponentInfoData() {
|
|
7
|
+
return `{
|
|
8
|
+
"version": 1.1,
|
|
9
|
+
"tags": ${JSON.stringify(library.webComponents?.tags)}
|
|
10
|
+
}
|
|
11
|
+
`;
|
|
12
|
+
}
|
|
13
|
+
export async function generateVsCodeCustomData() {
|
|
14
|
+
try {
|
|
15
|
+
log.info("Generating custom-elements.json...");
|
|
16
|
+
await writeTextFile({
|
|
17
|
+
path: customElementsDataPath(),
|
|
18
|
+
data: generateComponentInfoData()
|
|
19
|
+
});
|
|
20
|
+
log.success("Generated custom-elements.json for IDEs.");
|
|
21
|
+
return ok(void 0);
|
|
22
|
+
} catch (e) {
|
|
23
|
+
log.error("There was an error generating the custom-elements.json file.", e);
|
|
24
|
+
return err("There was an error generating the custom-elements.json file.");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export async function generateWebTypes() {
|
|
28
|
+
log.info("Generating web-types.json...");
|
|
29
|
+
log.info("This feature is not yet implemented.");
|
|
30
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,19 @@ export type { CrudField } from './scaffold-crud';
|
|
|
2
2
|
export type { DiscoveredPackagesManifest, PackageStacksMeta } from './discover-packages';
|
|
3
3
|
export * from './action';
|
|
4
4
|
export { add as runAdd } from './add';
|
|
5
|
+
// The write side of the markdown blog (content/blog/*.md), used by the
|
|
6
|
+
// dashboard's blog actions. The read/render side lives in ./blog and stays out
|
|
7
|
+
// of this barrel because it lazy-loads BunPress.
|
|
8
|
+
export {
|
|
9
|
+
type BlogPost,
|
|
10
|
+
BlogAdminError,
|
|
11
|
+
type BlogPostInput,
|
|
12
|
+
deleteBlogPost,
|
|
13
|
+
getBlogPost,
|
|
14
|
+
listBlogPosts,
|
|
15
|
+
saveBlogPost,
|
|
16
|
+
slugify as blogSlugify,
|
|
17
|
+
} from './blog-admin';
|
|
5
18
|
export { commit as runCommit } from './commit';
|
|
6
19
|
export * from './dev/index';
|
|
7
20
|
export * from './generate/index';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export * from "./action";
|
|
2
|
+
export { add as runAdd } from "./add";
|
|
3
|
+
export {
|
|
4
|
+
BlogAdminError,
|
|
5
|
+
deleteBlogPost,
|
|
6
|
+
getBlogPost,
|
|
7
|
+
listBlogPosts,
|
|
8
|
+
saveBlogPost,
|
|
9
|
+
slugify as blogSlugify
|
|
10
|
+
} from "./blog-admin";
|
|
11
|
+
export { commit as runCommit } from "./commit";
|
|
12
|
+
export * from "./dev";
|
|
13
|
+
export * from "./generate";
|
|
14
|
+
export * from "./helpers";
|
|
15
|
+
export { formatProject, lintFix, lintProject } from "./lint/lint";
|
|
16
|
+
export * from "./setup";
|
|
17
|
+
export {
|
|
18
|
+
createComponent,
|
|
19
|
+
createDatabase,
|
|
20
|
+
createFactory,
|
|
21
|
+
createFunction,
|
|
22
|
+
createLanguage,
|
|
23
|
+
createMiddleware,
|
|
24
|
+
createMigration,
|
|
25
|
+
createModel,
|
|
26
|
+
createMail,
|
|
27
|
+
createNotification,
|
|
28
|
+
createPage,
|
|
29
|
+
isDryRunActive,
|
|
30
|
+
makeAction,
|
|
31
|
+
makeCertificate,
|
|
32
|
+
makeComponent,
|
|
33
|
+
makeDatabase,
|
|
34
|
+
makeFunction,
|
|
35
|
+
makeLanguage,
|
|
36
|
+
makeMail,
|
|
37
|
+
makeNotification,
|
|
38
|
+
makePage,
|
|
39
|
+
makeQueueTable,
|
|
40
|
+
makeStack,
|
|
41
|
+
make as runMake,
|
|
42
|
+
setDryRun
|
|
43
|
+
} from "./make";
|
|
44
|
+
export { discoverPackages } from "./discover-packages";
|
|
45
|
+
export { parseFields, scaffoldCrud } from "./scaffold-crud";
|
|
46
|
+
export { installStack, uninstallStack, listStacks } from "./stacks";
|
|
47
|
+
export { makeJob } from "./make-job";
|
|
48
|
+
export { makeCommand } from "./make-command";
|
|
49
|
+
export { makePolicy } from "./make-policy";
|
|
50
|
+
export { makeResource } from "./make-resource";
|
package/dist/key-generate.js
CHANGED
|
@@ -1,2 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
import{
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { runCommand } from "@stacksjs/cli";
|
|
3
|
+
import { generateKeypair } from "@stacksjs/env";
|
|
4
|
+
import { projectPath } from "@stacksjs/path";
|
|
5
|
+
import { generateAppKey } from "@stacksjs/security";
|
|
6
|
+
import { existsSync } from "@stacksjs/storage";
|
|
7
|
+
import { setEnvValue } from "@stacksjs/utils";
|
|
8
|
+
if (!existsSync(".env"))
|
|
9
|
+
await runCommand("cp .env.example .env", { cwd: projectPath() });
|
|
10
|
+
await setEnvValue("APP_KEY", generateAppKey());
|
|
11
|
+
const envText = (() => {
|
|
12
|
+
try {
|
|
13
|
+
return readFileSync(projectPath(".env"), "utf-8");
|
|
14
|
+
} catch {
|
|
15
|
+
return "";
|
|
16
|
+
}
|
|
17
|
+
})(), hasPublic = /^DOTENV_PUBLIC_KEY=.+$/m.test(envText), hasPrivate = /^DOTENV_PRIVATE_KEY=.+$/m.test(envText);
|
|
18
|
+
if (!hasPublic || !hasPrivate) {
|
|
19
|
+
const { publicKey, privateKey } = generateKeypair();
|
|
20
|
+
if (!hasPublic)
|
|
21
|
+
await setEnvValue("DOTENV_PUBLIC_KEY", publicKey);
|
|
22
|
+
if (!hasPrivate)
|
|
23
|
+
await setEnvValue("DOTENV_PRIVATE_KEY", privateKey);
|
|
24
|
+
}
|
package/dist/lint/fix.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import { lintFix } from "./lint";
|
|
3
|
+
const { ok } = await lintFix();
|
|
4
|
+
process.exit(ok ? 0 : 1);
|
package/dist/lint/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import { lintProject } from "./lint";
|
|
3
|
+
const { ok } = await lintProject();
|
|
4
|
+
process.exit(ok ? 0 : 1);
|
package/dist/lint/lint.js
CHANGED
|
@@ -1,2 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
import{
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import { log } from "@stacksjs/cli";
|
|
3
|
+
import { execSync } from "node:child_process";
|
|
4
|
+
import { runFormat, runLint } from "pickier";
|
|
5
|
+
const lintableFile = /\.(?:ts|js|json|md|yaml|yml)$/i, ignoredPath = /(?:^|\/)(?:node_modules|dist|pantry|storage\/framework\/cache|\.git|\.stx|\.stx-serve)(?:\/|$)/;
|
|
6
|
+
function trackedFiles(cwd) {
|
|
7
|
+
try {
|
|
8
|
+
return execSync("git ls-files -z", { cwd, encoding: "utf8" }).split("\x00").filter((file) => lintableFile.test(file) && !ignoredPath.test(file));
|
|
9
|
+
} catch {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export async function lintProject(options = {}) {
|
|
14
|
+
const cwd = options.cwd ?? process.cwd();
|
|
15
|
+
log.info(options.fix ? "Ensuring Code Style..." : "Checking Code Style...");
|
|
16
|
+
const files = trackedFiles(cwd);
|
|
17
|
+
if (!files.length) {
|
|
18
|
+
log.success("Linted");
|
|
19
|
+
return { ok: !0 };
|
|
20
|
+
}
|
|
21
|
+
const ok = await runLint(files, { maxWarnings: 9999, fix: options.fix }) === 0;
|
|
22
|
+
if (ok)
|
|
23
|
+
log.success("Linted");
|
|
24
|
+
return { ok };
|
|
25
|
+
}
|
|
26
|
+
export function lintFix(options = {}) {
|
|
27
|
+
return lintProject({ ...options, fix: !0 });
|
|
28
|
+
}
|
|
29
|
+
export async function formatProject(options = {}) {
|
|
30
|
+
const cwd = options.cwd ?? process.cwd(), files = trackedFiles(cwd);
|
|
31
|
+
if (!files.length)
|
|
32
|
+
return { ok: !0 };
|
|
33
|
+
return { ok: await runFormat(files, { write: options.write, check: options.check }) === 0 };
|
|
34
|
+
}
|
package/dist/make-command.js
CHANGED
|
@@ -1,45 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
import { log } from "@stacksjs/logging";
|
|
2
|
+
import * as p from "@stacksjs/path";
|
|
3
|
+
import { get, writeFile } from "@stacksjs/storage";
|
|
4
|
+
export async function makeCommand(options) {
|
|
5
|
+
const name = options.name;
|
|
6
|
+
if (!name) {
|
|
7
|
+
log.error("Command name is required");
|
|
8
|
+
return !1;
|
|
9
|
+
}
|
|
10
|
+
const commandName = toPascalCase(name), content = generateCommandContent(commandName, options), filePath = p.commandsPath(`${commandName}.ts`);
|
|
11
|
+
try {
|
|
12
|
+
await writeFile(filePath, content);
|
|
13
|
+
log.success(`Created command: ${filePath}`);
|
|
14
|
+
if (options.register !== !1)
|
|
15
|
+
await registerCommand(commandName, options.signature || toKebabCase(name));
|
|
16
|
+
return !0;
|
|
17
|
+
} catch (error) {
|
|
18
|
+
log.error(`Failed to create command: ${error.message}`);
|
|
19
|
+
return !1;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function generateCommandContent(name, options) {
|
|
23
|
+
const signature = options.signature || toKebabCase(name), description = options.description || `The ${signature} command`;
|
|
24
|
+
return `import type { CLI } from '@stacksjs/types'
|
|
3
25
|
import { log } from '@stacksjs/cli'
|
|
4
26
|
|
|
5
27
|
/**
|
|
6
|
-
* ${
|
|
28
|
+
* ${name} Command
|
|
7
29
|
*
|
|
8
|
-
* ${
|
|
30
|
+
* ${description}
|
|
9
31
|
*/
|
|
10
32
|
|
|
11
|
-
interface ${
|
|
33
|
+
interface ${name}Options {
|
|
12
34
|
verbose: boolean
|
|
13
35
|
// Add your command options here
|
|
14
36
|
}
|
|
15
37
|
|
|
16
38
|
export default function (cli: CLI) {
|
|
17
39
|
cli
|
|
18
|
-
.command('${
|
|
40
|
+
.command('${signature}', '${description}')
|
|
19
41
|
.option('--verbose', 'Enable verbose output', { default: false })
|
|
20
42
|
// Add more options here
|
|
21
43
|
// .option('-n, --name <name>', 'Your name')
|
|
22
|
-
.action(async (options: ${
|
|
44
|
+
.action(async (options: ${name}Options) => {
|
|
23
45
|
try {
|
|
24
46
|
if (options.verbose) {
|
|
25
|
-
log.info('Running ${
|
|
47
|
+
log.info('Running ${signature} command...')
|
|
26
48
|
}
|
|
27
49
|
|
|
28
50
|
log.info('No command logic implemented yet. Update this command action to add behavior.')
|
|
29
51
|
|
|
30
|
-
log.success('${
|
|
52
|
+
log.success('${signature} completed successfully!')
|
|
31
53
|
}
|
|
32
54
|
catch (error) {
|
|
33
|
-
log.error('${
|
|
55
|
+
log.error('${signature} failed:', error)
|
|
34
56
|
throw error
|
|
35
57
|
}
|
|
36
58
|
})
|
|
37
59
|
|
|
38
60
|
// Handle unknown subcommands
|
|
39
|
-
cli.on('${
|
|
61
|
+
cli.on('${signature}:*', () => {
|
|
40
62
|
log.error('Invalid command: %s\\nSee --help for a list of available commands.', cli.args.join(' '))
|
|
41
63
|
})
|
|
42
64
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
65
|
+
`;
|
|
66
|
+
}
|
|
67
|
+
async function registerCommand(name, signature) {
|
|
68
|
+
const commandsPath = p.appPath("Commands.ts");
|
|
69
|
+
try {
|
|
70
|
+
let content = await get(commandsPath);
|
|
71
|
+
const exportMatch = content.match(/export default \{([\s\S]*)\} satisfies/);
|
|
72
|
+
if (exportMatch) {
|
|
73
|
+
const existingCommands = exportMatch[1] ?? "";
|
|
74
|
+
if (existingCommands.includes(`'${signature}'`)) {
|
|
75
|
+
log.info(`Command '${signature}' already registered in Commands.ts`);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const newCommand = ` '${signature}': '${name}',
|
|
79
|
+
`, updatedCommands = `${existingCommands.trimEnd()}
|
|
80
|
+
${newCommand}`;
|
|
81
|
+
content = content.replace(/export default \{[\s\S]*\} satisfies/, `export default {${updatedCommands}} satisfies`);
|
|
82
|
+
await writeFile(commandsPath, content);
|
|
83
|
+
log.success(`Registered command '${signature}' in Commands.ts`);
|
|
84
|
+
}
|
|
85
|
+
} catch (error) {
|
|
86
|
+
log.warn(`Could not register command in Commands.ts: ${error.message}`);
|
|
87
|
+
log.info("You may need to manually add it to app/Commands.ts");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function toPascalCase(str) {
|
|
91
|
+
return str.replace(/[-_](.)/g, (_, char) => char.toUpperCase()).replace(/^(.)/, (_, char) => char.toUpperCase());
|
|
92
|
+
}
|
|
93
|
+
function toKebabCase(str) {
|
|
94
|
+
return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[_\s]+/g, "-").toLowerCase();
|
|
95
|
+
}
|
package/dist/make-job.js
CHANGED
|
@@ -1,31 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
import { log } from "@stacksjs/logging";
|
|
2
|
+
import * as p from "@stacksjs/path";
|
|
3
|
+
import { writeFile } from "@stacksjs/storage";
|
|
4
|
+
export async function makeJob(options) {
|
|
5
|
+
const jobOptions = options, name = options.name;
|
|
6
|
+
if (!name) {
|
|
7
|
+
log.error("Job name is required");
|
|
8
|
+
return !1;
|
|
9
|
+
}
|
|
10
|
+
const jobName = name.endsWith("Job") ? name : `${name}Job`, content = jobOptions.class ?? !1 ? generateClassBasedJob(jobName, jobOptions) : generateFunctionBasedJob(jobName, jobOptions), filePath = p.userJobsPath(`${jobName}.ts`);
|
|
11
|
+
try {
|
|
12
|
+
await writeFile(filePath, content);
|
|
13
|
+
log.success(`Created job: ${filePath}`);
|
|
14
|
+
return !0;
|
|
15
|
+
} catch (error) {
|
|
16
|
+
log.error(`Failed to create job: ${error.message}`);
|
|
17
|
+
return !1;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function generateFunctionBasedJob(name, options) {
|
|
21
|
+
const queue = options.queue ?? "default", tries = options.tries ?? 3, backoff = options.backoff ?? 3;
|
|
22
|
+
return `import { Job } from '@stacksjs/queue'
|
|
3
23
|
|
|
4
24
|
export default new Job({
|
|
5
25
|
/**
|
|
6
26
|
* The job name (optional, defaults to filename)
|
|
7
27
|
*/
|
|
8
|
-
name: '${
|
|
28
|
+
name: '${name}',
|
|
9
29
|
|
|
10
30
|
/**
|
|
11
31
|
* A description of what this job does (optional)
|
|
12
32
|
*/
|
|
13
|
-
description: '${
|
|
33
|
+
description: '${name} job',
|
|
14
34
|
|
|
15
35
|
/**
|
|
16
36
|
* The queue this job should be dispatched to
|
|
17
37
|
*/
|
|
18
|
-
queue: '${
|
|
38
|
+
queue: '${queue}',
|
|
19
39
|
|
|
20
40
|
/**
|
|
21
41
|
* Number of times to retry if the job fails
|
|
22
42
|
*/
|
|
23
|
-
tries: ${
|
|
43
|
+
tries: ${tries},
|
|
24
44
|
|
|
25
45
|
/**
|
|
26
46
|
* Seconds to wait between retry attempts
|
|
27
47
|
*/
|
|
28
|
-
backoff: ${
|
|
48
|
+
backoff: ${backoff},
|
|
29
49
|
|
|
30
50
|
/**
|
|
31
51
|
* Cron expression for scheduled jobs (optional)
|
|
@@ -58,14 +78,18 @@ export default new Job({
|
|
|
58
78
|
return { success: true }
|
|
59
79
|
},
|
|
60
80
|
})
|
|
61
|
-
|
|
81
|
+
`;
|
|
82
|
+
}
|
|
83
|
+
function generateClassBasedJob(name, options) {
|
|
84
|
+
const queue = options.queue ?? "default", tries = options.tries ?? 3;
|
|
85
|
+
return `import { log } from '@stacksjs/logging'
|
|
62
86
|
|
|
63
87
|
/**
|
|
64
|
-
* ${
|
|
88
|
+
* ${name}
|
|
65
89
|
*
|
|
66
90
|
* Generated job class.
|
|
67
91
|
*/
|
|
68
|
-
export default class ${
|
|
92
|
+
export default class ${name} {
|
|
69
93
|
/**
|
|
70
94
|
* Job configuration
|
|
71
95
|
*/
|
|
@@ -73,7 +97,7 @@ export default class ${v} {
|
|
|
73
97
|
/**
|
|
74
98
|
* The queue this job should be dispatched to
|
|
75
99
|
*/
|
|
76
|
-
queue: '${
|
|
100
|
+
queue: '${queue}',
|
|
77
101
|
|
|
78
102
|
/**
|
|
79
103
|
* Cron expression for scheduled jobs (optional)
|
|
@@ -97,7 +121,7 @@ export default class ${v} {
|
|
|
97
121
|
/**
|
|
98
122
|
* Number of retry attempts
|
|
99
123
|
*/
|
|
100
|
-
retries: ${
|
|
124
|
+
retries: ${tries},
|
|
101
125
|
|
|
102
126
|
/**
|
|
103
127
|
* Delay between retries in seconds
|
|
@@ -111,19 +135,20 @@ export default class ${v} {
|
|
|
111
135
|
*/
|
|
112
136
|
public static async handle(payload?: Record<string, unknown>): Promise<{ success: boolean }> {
|
|
113
137
|
try {
|
|
114
|
-
log.info('${
|
|
138
|
+
log.info('${name}: Starting job execution')
|
|
115
139
|
|
|
116
140
|
// Add your job logic here.
|
|
117
141
|
console.log('Processing with payload:', payload)
|
|
118
142
|
|
|
119
|
-
log.info('${
|
|
143
|
+
log.info('${name}: Job completed successfully')
|
|
120
144
|
|
|
121
145
|
return { success: true }
|
|
122
146
|
}
|
|
123
147
|
catch (error) {
|
|
124
|
-
log.error('${
|
|
148
|
+
log.error('${name}: Job failed:', error)
|
|
125
149
|
throw error
|
|
126
150
|
}
|
|
127
151
|
}
|
|
128
152
|
}
|
|
129
|
-
|
|
153
|
+
`;
|
|
154
|
+
}
|