Skip to content

Commit

Permalink
feat(cmds): add as-commands based best practice for commands
Browse files Browse the repository at this point in the history
  • Loading branch information
uladkasach committed Jul 26, 2024
1 parent 9bef916 commit 57882ab
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 3 deletions.
111 changes: 110 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"@ehmpathy/error-fns": "1.3.1",
"expect": "29.4.2",
"flat": "5.0.2",
"lodash.uniq": "4.5.0",
"type-fns": "0.8.1"
"lodash.uniq": "4.5.0"
},
"peerDependencies": {
"declapract": "0.11.2"
Expand Down Expand Up @@ -70,6 +69,9 @@
"prettier": "2.8.1",
"ts-jest": "29.0.3",
"ts-node": "10.9.1",
"type-fns": "0.8.1",
"@ehmpathy/as-command": "1.0.1",
"visualogic": "1.2.1",
"typescript": "4.9.4"
},
"config": {
Expand Down
6 changes: 6 additions & 0 deletions src/practices/commands/best-practice/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"visualogic": "@declapract{check.minVersion('1.0.1')}",
"@ehmpathy/as-command": "@declapract{check.minVersion('1.2.1')}"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { FileCheckType } from 'declapract';

export const check = FileCheckType.CONTAINS;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!directory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const COMMANDS_OUTPUT_DIRECTORY = __dirname
.split('/')
.slice(0, -1)
.join('/');
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { asCommand } from '@ehmpathy/as-command';
import { UnexpectedCodePathError } from '@ehmpathy/error-fns';
import { ProcedureInput, getResourceNameFromFileName } from 'visualogic';

import { stage } from '../../utils/environment';
import { log } from '../../utils/logger';
import { COMMANDS_OUTPUT_DIRECTORY } from './__tmp__/directory';

const command = asCommand(
{
name: getResourceNameFromFileName(__filename),
stage,
dir: COMMANDS_OUTPUT_DIRECTORY,
log,
},
async () => console.log('hello world'),
);

// STAGE=prod npx tsx src/contract/commands/sayHello.ts
if (require.main === module) void command({});

0 comments on commit 57882ab

Please sign in to comment.