@appweaver/cli 1.0.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.
Files changed (76) hide show
  1. package/LICENSE +1 -0
  2. package/README.md +7 -0
  3. package/build/build-command.d.ts +2 -0
  4. package/build/build-command.js +15 -0
  5. package/build/build-project.d.ts +8 -0
  6. package/build/build-project.js +19 -0
  7. package/build/index.d.ts +2 -0
  8. package/build/index.js +18 -0
  9. package/generate/generate-command.d.ts +2 -0
  10. package/generate/generate-command.js +38 -0
  11. package/generate/generate-schema.d.ts +12 -0
  12. package/generate/generate-schema.js +475 -0
  13. package/generate/generate-types.d.ts +10 -0
  14. package/generate/generate-types.js +86 -0
  15. package/generate/index.d.ts +3 -0
  16. package/generate/index.js +19 -0
  17. package/migrate/index.d.ts +1 -0
  18. package/migrate/index.js +17 -0
  19. package/migrate/migrate-command.d.ts +2 -0
  20. package/migrate/migrate-command.js +13 -0
  21. package/migration/index.d.ts +1 -0
  22. package/migration/index.js +17 -0
  23. package/migration/migration-command.d.ts +2 -0
  24. package/migration/migration-command.js +34 -0
  25. package/openapi/index.d.ts +1 -0
  26. package/openapi/index.js +17 -0
  27. package/openapi/openapi-command.d.ts +2 -0
  28. package/openapi/openapi-command.js +46 -0
  29. package/package.json +56 -0
  30. package/seed/index.d.ts +1 -0
  31. package/seed/index.js +17 -0
  32. package/seed/seed-command.d.ts +2 -0
  33. package/seed/seed-command.js +33 -0
  34. package/skill/GUIDELINES.md +298 -0
  35. package/skill/SKILL.md +593 -0
  36. package/skill/references/cache.md +207 -0
  37. package/skill/references/cli.md +213 -0
  38. package/skill/references/client.md +507 -0
  39. package/skill/references/configuration.md +402 -0
  40. package/skill/references/database.md +134 -0
  41. package/skill/references/dependency-injection.md +214 -0
  42. package/skill/references/events.md +152 -0
  43. package/skill/references/mailer.md +235 -0
  44. package/skill/references/queue.md +196 -0
  45. package/skill/references/resources.md +961 -0
  46. package/skill/references/scheduler.md +184 -0
  47. package/skill/references/security.md +694 -0
  48. package/skill/references/storage.md +251 -0
  49. package/start/index.d.ts +2 -0
  50. package/start/index.js +18 -0
  51. package/start/start-command.d.ts +2 -0
  52. package/start/start-command.js +17 -0
  53. package/start/start-project.d.ts +8 -0
  54. package/start/start-project.js +147 -0
  55. package/testing/index.d.ts +1 -0
  56. package/testing/index.js +17 -0
  57. package/testing/testing-command.d.ts +2 -0
  58. package/testing/testing-command.js +96 -0
  59. package/update/index.d.ts +2 -0
  60. package/update/index.js +18 -0
  61. package/update/update-command.d.ts +2 -0
  62. package/update/update-command.js +84 -0
  63. package/update/update-packages.d.ts +10 -0
  64. package/update/update-packages.js +45 -0
  65. package/update/update-skill.d.ts +8 -0
  66. package/update/update-skill.js +93 -0
  67. package/utils/index.d.ts +3 -0
  68. package/utils/index.js +19 -0
  69. package/utils/loader-util.d.ts +29 -0
  70. package/utils/loader-util.js +132 -0
  71. package/utils/path-util.d.ts +41 -0
  72. package/utils/path-util.js +98 -0
  73. package/utils/process-util.d.ts +39 -0
  74. package/utils/process-util.js +92 -0
  75. package/weaver.d.ts +2 -0
  76. package/weaver.js +53 -0
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generateTypes = generateTypes;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const promises_1 = __importDefault(require("node:fs/promises"));
9
+ const prettier_1 = __importDefault(require("prettier"));
10
+ const typebox_1 = require("@sinclair/typebox");
11
+ const typebox_codegen_1 = require("@sinclair/typebox-codegen");
12
+ const common_1 = require("@appweaver/common");
13
+ const utils_1 = require("../utils");
14
+ /**
15
+ * Generates TypeScript type definitions for the given resource models and writes them to a specified directory.
16
+ *
17
+ * @param {Record<string, ResourceModel>} models - A set of resource models for which TypeScript types will be generated.
18
+ * @param {string} typesPath - The relative path to the directory where the generated types will be written.
19
+ * @param {boolean} [quiet=false] - If true, suppresses detailed logging during the operation.
20
+ * @return {Promise<number>} A promise that resolves to a status code: `0` for success, `2` for failure.
21
+ */
22
+ async function generateTypes(models, typesPath, quiet = false) {
23
+ const cwd = process.cwd();
24
+ try {
25
+ await (0, utils_1.ensureDirExists)(node_path_1.default.join(cwd, typesPath));
26
+ const resourceModels = {};
27
+ for (const [name, schema] of Object.entries(models)) {
28
+ if (schema.config.generateTypes === false) {
29
+ continue;
30
+ }
31
+ resourceModels[name] = transformUnsafeTypes(schema.readModel);
32
+ resourceModels[`${name}Single`] = transformUnsafeTypes(schema.readOneModel);
33
+ resourceModels[`${name}Multiple`] = transformUnsafeTypes(schema.readManyModel);
34
+ resourceModels[`${name}Create`] = transformUnsafeTypes(schema.createOneModel);
35
+ resourceModels[`${name}Update`] = transformUnsafeTypes(schema.updateOneModel);
36
+ }
37
+ const module = typebox_1.Type.Module(resourceModels);
38
+ const typesContent = [
39
+ `// Generated by Appweaver. Please do not edit this file manually.`,
40
+ ``
41
+ ];
42
+ for (const name of Object.keys(resourceModels)) {
43
+ typesContent.push(generateTypeScriptType(module, name), ``);
44
+ }
45
+ const outputPath = node_path_1.default.join(cwd, typesPath);
46
+ const prettierConfig = await prettier_1.default.resolveConfig(outputPath);
47
+ const formattedTypes = await prettier_1.default.format(typesContent.join('\n'), {
48
+ ...prettierConfig,
49
+ filepath: outputPath
50
+ });
51
+ await promises_1.default.writeFile(outputPath, formattedTypes);
52
+ console.log(`Types generated to ${node_path_1.default.relative(cwd, outputPath)}`);
53
+ return 0;
54
+ }
55
+ catch (error) {
56
+ console.error(`Types generation failed.${quiet ? ' Start with --verbose flag to see error details.' : ''}`);
57
+ if (!quiet) {
58
+ console.error(error);
59
+ }
60
+ return 2;
61
+ }
62
+ }
63
+ function generateTypeScriptType(module, name) {
64
+ const model = module.Import(name);
65
+ const schema = model.$defs[name];
66
+ return typebox_codegen_1.ModelToTypeScript.GenerateType({ types: [schema] }, name);
67
+ }
68
+ function transformUnsafeTypes(schema) {
69
+ const properties = {};
70
+ for (const [name, field] of Object.entries(schema.properties)) {
71
+ if (field.type === 'string' && (0, common_1.isArray)(field.enum)) {
72
+ properties[name] = (0, common_1.EnumType)(field.enum);
73
+ }
74
+ else if (field.type === 'string' &&
75
+ ['date-time', 'date'].includes(field.format)) {
76
+ properties[name] = (0, common_1.DateType)(field);
77
+ }
78
+ else {
79
+ properties[name] = field;
80
+ }
81
+ if (field.nullable === true) {
82
+ properties[name] = (0, common_1.NullType)(properties[name]);
83
+ }
84
+ }
85
+ return typebox_1.Type.Object(properties, { ...schema });
86
+ }
@@ -0,0 +1,3 @@
1
+ export * from './generate-command';
2
+ export * from './generate-schema';
3
+ export * from './generate-types';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./generate-command"), exports);
18
+ __exportStar(require("./generate-schema"), exports);
19
+ __exportStar(require("./generate-types"), exports);
@@ -0,0 +1 @@
1
+ export * from './migrate-command';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./migrate-command"), exports);
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare function migrateCommand(program: Command): void;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.migrateCommand = migrateCommand;
4
+ const utils_1 = require("../utils");
5
+ function migrateCommand(program) {
6
+ program
7
+ .command('migrate')
8
+ .alias('mge')
9
+ .description('Run database migrations.')
10
+ .action(async () => {
11
+ process.exit(await (0, utils_1.runProcess)('prisma', ['migrate', 'deploy']));
12
+ });
13
+ }
@@ -0,0 +1 @@
1
+ export * from './migration-command';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./migration-command"), exports);
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare function migrationCommand(program: Command): void;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.migrationCommand = migrationCommand;
4
+ const utils_1 = require("../utils");
5
+ function migrationCommand(program) {
6
+ const migration = program
7
+ .command('migration')
8
+ .alias('mgn')
9
+ .description('Database migration commands.');
10
+ migration
11
+ .command('new <name>')
12
+ .description('Create a new database migration.')
13
+ .action(async (name) => {
14
+ process.exit(await (0, utils_1.runProcess)('prisma', ['migrate', 'dev', '--name', name]));
15
+ });
16
+ migration
17
+ .command('reset')
18
+ .description('Reset the database.')
19
+ .option('-f, --force', 'Force reset for non-development environments')
20
+ .option('-y, --yes', 'Skip confirmation prompt')
21
+ .action(async (_, command) => {
22
+ const force = command.getOptionValue('force');
23
+ const yes = command.getOptionValue('yes');
24
+ if (!force) {
25
+ (0, utils_1.assertEnvs)(['dev', 'test'], '"weaver migration reset" can be called only in "dev" or "test" ' +
26
+ 'environments (NODE_ENV=dev). Use --force flag to reset anyway.');
27
+ }
28
+ const args = ['migrate', 'reset'];
29
+ if (yes || force) {
30
+ args.push('--force');
31
+ }
32
+ process.exit(await (0, utils_1.runProcess)('prisma', args));
33
+ });
34
+ }
@@ -0,0 +1 @@
1
+ export * from './openapi-command';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./openapi-command"), exports);
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare function openapiCommand(program: Command): void;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.openapiCommand = openapiCommand;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const promises_1 = __importDefault(require("node:fs/promises"));
9
+ const commander_1 = require("commander");
10
+ const core_1 = require("@appweaver/core");
11
+ const utils_1 = require("../utils");
12
+ const formats = ['json', 'yaml'];
13
+ function openapiCommand(program) {
14
+ program
15
+ .command('openapi')
16
+ .alias('oa')
17
+ .description("Generate application's OpenAPI specification schema.")
18
+ .option('-o, --outputPath [path]', 'Output path for generated OpenAPI specification.', './openapi.json')
19
+ .option('-f, --format [format]', `Output format for generated OpenAPI specification (${formats.join(', ')}).`, parseFormat, 'json')
20
+ .action(async (_, command) => {
21
+ const format = command.getOptionValue('format');
22
+ const rawOutputPath = command.getOptionValue('outputPath');
23
+ const outputPath = rawOutputPath === './openapi.json' && format === 'yaml'
24
+ ? './openapi.yaml'
25
+ : rawOutputPath;
26
+ try {
27
+ const app = await (0, core_1.createApp)({ autoStart: false });
28
+ const spec = await app.spec(format);
29
+ await (0, utils_1.ensureDirExists)(outputPath);
30
+ await promises_1.default.writeFile(outputPath, spec, 'utf8');
31
+ console.log(`Schema generated to ${node_path_1.default.relative(process.cwd(), outputPath)}`);
32
+ process.exit(0);
33
+ }
34
+ catch (error) {
35
+ console.error('Schema generation failed', error);
36
+ process.exit(1);
37
+ }
38
+ });
39
+ }
40
+ function parseFormat(value) {
41
+ const lowerFormat = value.toLowerCase();
42
+ if (!formats.includes(lowerFormat)) {
43
+ throw new commander_1.InvalidOptionArgumentError(`Must be one of following: ${formats.join(', ')}.`);
44
+ }
45
+ return lowerFormat;
46
+ }
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@appweaver/cli",
3
+ "version": "1.0.0",
4
+ "description": "Appweaver - simple, fast, and reliable web application builder tool (@cli)",
5
+ "author": "Luka Matosevic",
6
+ "license": "UNLICENSED",
7
+ "main": "./weaver.js",
8
+ "types": "./weaver.d.ts",
9
+ "bin": {
10
+ "weaver": "./weaver.js"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/lmatosevic/appweaver.git",
15
+ "directory": "packages/cli"
16
+ },
17
+ "maintainers": [
18
+ {
19
+ "name": "Luka Matosevic",
20
+ "email": "lukamatosevic5@gmail.com",
21
+ "web": "https://lukamatosevic.com"
22
+ }
23
+ ],
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "engines": {
28
+ "node": ">= 20"
29
+ },
30
+ "scripts": {
31
+ "weaver": "node ./dist/weaver.js"
32
+ },
33
+ "dependencies": {
34
+ "@sinclair/typebox": "0.34.47",
35
+ "@sinclair/typebox-codegen": "0.11.1",
36
+ "commander": "14.0.3",
37
+ "glob": "13.0.1",
38
+ "prettier": "3.8.1",
39
+ "rimraf": "6.1.2",
40
+ "tree-kill": "1.2.2",
41
+ "ts-node": "10.9.2",
42
+ "tsc-alias": "1.8.16",
43
+ "tsc-watch": "7.2.0"
44
+ },
45
+ "devDependencies": {
46
+ "@appweaver/core": "^1.0.0",
47
+ "@appweaver/common": "^1.0.0",
48
+ "@types/bun": "^1.3.11"
49
+ },
50
+ "peerDependencies": {
51
+ "@appweaver/core": "^1.0.0",
52
+ "@appweaver/common": "^1.0.0",
53
+ "prisma": "^7.3.0",
54
+ "typescript": "^5.9.0"
55
+ }
56
+ }
@@ -0,0 +1 @@
1
+ export * from './seed-command';
package/seed/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./seed-command"), exports);
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare function seedCommand(program: Command): void;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.seedCommand = seedCommand;
4
+ const core_1 = require("@appweaver/core");
5
+ const build_1 = require("../build");
6
+ function seedCommand(program) {
7
+ program
8
+ .command('seed')
9
+ .alias('sd')
10
+ .description('Seed the database.')
11
+ .option('--seedersPath [path]', 'Seeders directory path. (default: from config or env).')
12
+ .option('-b, --buildProject', 'Build the project before seeding.')
13
+ .option('-p, --project [path]', 'TypeScript project config file.', 'tsconfig.build.json')
14
+ .option('-c, --continueOnError', 'Continue seeder execution if error is thrown.')
15
+ .option('-f, --fixWarnings', 'Fix all seeder warnings like wrong checksum or deleted seeder files.')
16
+ .action(async (_, command) => {
17
+ const seedersPath = command.getOptionValue('seedersPath');
18
+ const projectFile = command.getOptionValue('project');
19
+ const continueOnError = command.getOptionValue('continueOnError');
20
+ const fixWarnings = command.getOptionValue('fixWarnings');
21
+ if (command.getOptionValue('buildProject')) {
22
+ await (0, build_1.buildProject)(projectFile);
23
+ }
24
+ const seeder = await (0, core_1.createSeeder)({
25
+ seedersPath,
26
+ continueOnError,
27
+ fixWarnings
28
+ });
29
+ await seeder.close();
30
+ // Exit process in case there are any open handlers left
31
+ process.exit(0);
32
+ });
33
+ }