Skip to content

Commit

Permalink
Merge pull request #10 from futura-dev/fix/commands-in-code
Browse files Browse the repository at this point in the history
fix: entrypoint for code import
  • Loading branch information
faridevnz authored Oct 30, 2024
2 parents 8e7a1ab + 362cf20 commit 312d9a5
Show file tree
Hide file tree
Showing 19 changed files with 132 additions and 32 deletions.
5 changes: 5 additions & 0 deletions examples/commands-in-code/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { migrate, MigrateDevCommand, MigrateDeployCommand, MigrateResetCommand } from "@futura-dev/cosmoprism/migrate";

migrate.dev({ mode: 'all' } satisfies MigrateDevCommand)
migrate.deploy({ mode: 'tenant', tenant: 'fake-tenant' } satisfies MigrateDeployCommand)
migrate.reset({ mode: 'central' } satisfies MigrateResetCommand)
64 changes: 64 additions & 0 deletions examples/commands-in-code/package-lock.json

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

17 changes: 17 additions & 0 deletions examples/commands-in-code/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
"typescript": "^5.6.3"
},
"dependencies": {
"@futura-dev/cosmoprism": "file:../.."
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
"homepage": "https://github.com/futura-dev/cosmoprism",
"license": "MIT",
"files": [
"/bin",
"/dist"
],
"main": "./dist/commands.js",
"exports": {
"./migrate": "./dist/cmd/migrate/index.js"
},
"bin": {
"@futura-dev/cosmoprism": "dist/cli.js"
},
Expand Down
4 changes: 2 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { init } from "./cmd/init/init";
import { generate } from "./cmd/generate/generate";
import { validate } from "./cmd/validate/validate";
import { format } from "./cmd/format/format";
import { db } from "./cmd/db/db";
import { db } from "./cmd/db";
import { studio } from "./cmd/studio/studio";
import { migrate } from "./cmd/migrate/migrate";
import { migrate } from "./cmd/migrate";
import { loadExternalEnv } from "./utils/functions";

// TODO: add custom options processing
Expand Down
3 changes: 0 additions & 3 deletions src/cmd/db/db.ts

This file was deleted.

4 changes: 4 additions & 0 deletions src/cmd/db/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { seed, SeedCommand } from "./seed";

export const db = { seed };
export type { SeedCommand };
1 change: 1 addition & 0 deletions src/cmd/db/seed/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./seed";
9 changes: 6 additions & 3 deletions src/cmd/db/seed/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ interface SeedCommandAll {
mode: "all";
}

export const seed = async (
command: SeedCommandAll | SeedCommandCentral | SeedCommandTenant
): Promise<void> => {
export type SeedCommand =
| SeedCommandAll
| SeedCommandCentral
| SeedCommandTenant;

export const seed = async (command: SeedCommand): Promise<void> => {
if (command.mode === "central" || command.mode === "all") {
console.log(`\nrunning db seed for central ...`);
// run 'npx tsx prisma/central/seed.ts'
Expand Down
9 changes: 6 additions & 3 deletions src/cmd/migrate/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ interface DeployCommandAll {
mode: "all";
}

export const deploy = async (
command: DeployCommandAll | DeployCommandCentral | DeployCommandTenant
): Promise<void> => {
export type DeployCommand =
| DeployCommandAll
| DeployCommandCentral
| DeployCommandTenant;

export const deploy = async (command: DeployCommand): Promise<void> => {
if (command.mode === "central" || command.mode === "all") {
console.log(`\nrunning 'migrate deploy' for central ...`);
// run 'npx prisma migrate deploy --schema=./prisma/central/schema.prisma'
Expand Down
1 change: 1 addition & 0 deletions src/cmd/migrate/deploy/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./deploy";
6 changes: 3 additions & 3 deletions src/cmd/migrate/dev/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ interface DevCommandAll {
skipGenerate?: boolean;
}

export const dev = async (
command: DevCommandAll | DevCommandCentral | DevCommandTenant
): Promise<void> => {
export type DevCommand = DevCommandAll | DevCommandCentral | DevCommandTenant;

export const dev = async (command: DevCommand): Promise<void> => {
if (command.mode === "central" || command.mode === "all") {
console.log(`\nrunning 'migrate dev' for central ...`);
// run 'npx prisma migrate dev --schema=./prisma/central/schema.prisma'
Expand Down
1 change: 1 addition & 0 deletions src/cmd/migrate/dev/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./dev";
10 changes: 10 additions & 0 deletions src/cmd/migrate/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { dev, DevCommand as MigrateDevCommand } from "./dev";
import { reset, ResetCommand as MigrateResetCommand } from "./reset";
import { deploy, DeployCommand as MigrateDeployCommand } from "./deploy";

export type { MigrateDevCommand, MigrateResetCommand, MigrateDeployCommand };
export const migrate = {
dev,
reset,
deploy
};
9 changes: 0 additions & 9 deletions src/cmd/migrate/migrate.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/cmd/migrate/reset/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./reset";
9 changes: 6 additions & 3 deletions src/cmd/migrate/reset/reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ interface ResetCommandAll {
skipGenerate?: boolean;
}

export const reset = async (
command: ResetCommandAll | ResetCommandCentral | ResetCommandTenant
): Promise<void> => {
export type ResetCommand =
| ResetCommandAll
| ResetCommandCentral
| ResetCommandTenant;

export const reset = async (command: ResetCommand): Promise<void> => {
if (command.mode === "central" || command.mode === "all") {
console.log(`\nrunning 'migrate reset' for central ...`);
// run 'npx prisma migrate reset --schema=./prisma/central/schema.prisma'
Expand Down
3 changes: 0 additions & 3 deletions src/commands.ts

This file was deleted.

3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"strict": true,
"skipLibCheck": true,
"declaration": true
}
},
"exclude": ["./examples"]
}

0 comments on commit 312d9a5

Please sign in to comment.