@contember/cli 1.2.0-alpha.4 → 1.2.0-alpha.5

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 (90) hide show
  1. package/dist/src/commands/deploy/DeployCommand.d.ts +3 -1
  2. package/dist/src/commands/deploy/DeployCommand.d.ts.map +1 -1
  3. package/dist/src/commands/deploy/DeployCommand.js +15 -15
  4. package/dist/src/commands/deploy/DeployCommand.js.map +1 -1
  5. package/dist/src/commands/migrations/MigrationAmendCommand.d.ts +4 -2
  6. package/dist/src/commands/migrations/MigrationAmendCommand.d.ts.map +1 -1
  7. package/dist/src/commands/migrations/MigrationAmendCommand.js +8 -2
  8. package/dist/src/commands/migrations/MigrationAmendCommand.js.map +1 -1
  9. package/dist/src/commands/migrations/MigrationCreateHelper.d.ts +5 -4
  10. package/dist/src/commands/migrations/MigrationCreateHelper.d.ts.map +1 -1
  11. package/dist/src/commands/migrations/MigrationCreateHelper.js +2 -9
  12. package/dist/src/commands/migrations/MigrationCreateHelper.js.map +1 -1
  13. package/dist/src/commands/migrations/MigrationDescribeCommand.d.ts +4 -1
  14. package/dist/src/commands/migrations/MigrationDescribeCommand.d.ts.map +1 -1
  15. package/dist/src/commands/migrations/MigrationDescribeCommand.js +8 -3
  16. package/dist/src/commands/migrations/MigrationDescribeCommand.js.map +1 -1
  17. package/dist/src/commands/migrations/MigrationDiffCommand.d.ts +4 -2
  18. package/dist/src/commands/migrations/MigrationDiffCommand.d.ts.map +1 -1
  19. package/dist/src/commands/migrations/MigrationDiffCommand.js +9 -2
  20. package/dist/src/commands/migrations/MigrationDiffCommand.js.map +1 -1
  21. package/dist/src/commands/migrations/MigrationExecuteCommand.d.ts +4 -2
  22. package/dist/src/commands/migrations/MigrationExecuteCommand.d.ts.map +1 -1
  23. package/dist/src/commands/migrations/MigrationExecuteCommand.js +8 -5
  24. package/dist/src/commands/migrations/MigrationExecuteCommand.js.map +1 -1
  25. package/dist/src/commands/migrations/MigrationRebaseCommand.d.ts +4 -2
  26. package/dist/src/commands/migrations/MigrationRebaseCommand.d.ts.map +1 -1
  27. package/dist/src/commands/migrations/MigrationRebaseCommand.js +8 -2
  28. package/dist/src/commands/migrations/MigrationRebaseCommand.js.map +1 -1
  29. package/dist/src/commands/migrations/MigrationStatusCommand.d.ts +4 -1
  30. package/dist/src/commands/migrations/MigrationStatusCommand.d.ts.map +1 -1
  31. package/dist/src/commands/migrations/MigrationStatusCommand.js +8 -3
  32. package/dist/src/commands/migrations/MigrationStatusCommand.js.map +1 -1
  33. package/dist/src/commands/project/ProjectCreateCommand.d.ts +3 -0
  34. package/dist/src/commands/project/ProjectCreateCommand.d.ts.map +1 -1
  35. package/dist/src/commands/project/ProjectCreateCommand.js +5 -1
  36. package/dist/src/commands/project/ProjectCreateCommand.js.map +1 -1
  37. package/dist/src/commands/project/ProjectGenerateDocumentation.d.ts +4 -2
  38. package/dist/src/commands/project/ProjectGenerateDocumentation.d.ts.map +1 -1
  39. package/dist/src/commands/project/ProjectGenerateDocumentation.js +8 -4
  40. package/dist/src/commands/project/ProjectGenerateDocumentation.js.map +1 -1
  41. package/dist/src/commands/project/ProjectPrintSchemaCommand.d.ts +4 -1
  42. package/dist/src/commands/project/ProjectPrintSchemaCommand.d.ts.map +1 -1
  43. package/dist/src/commands/project/ProjectPrintSchemaCommand.js +8 -4
  44. package/dist/src/commands/project/ProjectPrintSchemaCommand.js.map +1 -1
  45. package/dist/src/commands/project/ProjectValidateCommand.d.ts +4 -2
  46. package/dist/src/commands/project/ProjectValidateCommand.d.ts.map +1 -1
  47. package/dist/src/commands/project/ProjectValidateCommand.js +8 -5
  48. package/dist/src/commands/project/ProjectValidateCommand.js.map +1 -1
  49. package/dist/src/commands/tenant/CreateApiKeyCommand.d.ts +3 -0
  50. package/dist/src/commands/tenant/CreateApiKeyCommand.d.ts.map +1 -1
  51. package/dist/src/commands/tenant/CreateApiKeyCommand.js +5 -2
  52. package/dist/src/commands/tenant/CreateApiKeyCommand.js.map +1 -1
  53. package/dist/src/commands/tenant/InviteCommand.d.ts +3 -0
  54. package/dist/src/commands/tenant/InviteCommand.d.ts.map +1 -1
  55. package/dist/src/commands/tenant/InviteCommand.js +5 -2
  56. package/dist/src/commands/tenant/InviteCommand.js.map +1 -1
  57. package/dist/src/commands/tenant/ResetPasswordCommand.d.ts +3 -0
  58. package/dist/src/commands/tenant/ResetPasswordCommand.d.ts.map +1 -1
  59. package/dist/src/commands/tenant/ResetPasswordCommand.js +5 -2
  60. package/dist/src/commands/tenant/ResetPasswordCommand.js.map +1 -1
  61. package/dist/src/commands/tenant/SignInCommand.d.ts +3 -0
  62. package/dist/src/commands/tenant/SignInCommand.d.ts.map +1 -1
  63. package/dist/src/commands/tenant/SignInCommand.js +5 -2
  64. package/dist/src/commands/tenant/SignInCommand.js.map +1 -1
  65. package/dist/src/commands/workspace/WorkspaceUpdateApiCommand.d.ts +3 -1
  66. package/dist/src/commands/workspace/WorkspaceUpdateApiCommand.d.ts.map +1 -1
  67. package/dist/src/commands/workspace/WorkspaceUpdateApiCommand.js +5 -1
  68. package/dist/src/commands/workspace/WorkspaceUpdateApiCommand.js.map +1 -1
  69. package/dist/src/run.js +22 -23
  70. package/dist/src/run.js.map +1 -1
  71. package/dist/src/tsconfig.tsbuildinfo +1 -1
  72. package/package.json +10 -10
  73. package/src/commands/deploy/DeployCommand.ts +20 -15
  74. package/src/commands/migrations/MigrationAmendCommand.ts +12 -3
  75. package/src/commands/migrations/MigrationCreateHelper.ts +2 -7
  76. package/src/commands/migrations/MigrationDescribeCommand.ts +11 -3
  77. package/src/commands/migrations/MigrationDiffCommand.ts +14 -4
  78. package/src/commands/migrations/MigrationExecuteCommand.ts +11 -6
  79. package/src/commands/migrations/MigrationRebaseCommand.ts +13 -3
  80. package/src/commands/migrations/MigrationStatusCommand.ts +11 -3
  81. package/src/commands/project/ProjectCreateCommand.ts +7 -1
  82. package/src/commands/project/ProjectGenerateDocumentation.ts +12 -7
  83. package/src/commands/project/ProjectPrintSchemaCommand.ts +11 -4
  84. package/src/commands/project/ProjectValidateCommand.ts +11 -6
  85. package/src/commands/tenant/CreateApiKeyCommand.ts +7 -1
  86. package/src/commands/tenant/InviteCommand.ts +7 -1
  87. package/src/commands/tenant/ResetPasswordCommand.ts +7 -1
  88. package/src/commands/tenant/SignInCommand.ts +7 -1
  89. package/src/commands/workspace/WorkspaceUpdateApiCommand.ts +7 -1
  90. package/src/run.ts +24 -26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contember/cli",
3
- "version": "1.2.0-alpha.4",
3
+ "version": "1.2.0-alpha.5",
4
4
  "license": "Apache-2.0",
5
5
  "bin": {
6
6
  "contember": "./dist/src/run.js"
@@ -18,15 +18,15 @@
18
18
  "tailwindcss": "^3.0.24"
19
19
  },
20
20
  "dependencies": {
21
- "@contember/cli-common": "^1.2.0-alpha.4",
22
- "@contember/config-loader": "^1.2.0-alpha.4",
23
- "@contember/database-migrations": "^1.2.0-alpha.4",
24
- "@contember/dic": "^1.2.0-alpha.4",
25
- "@contember/engine-content-api": "^1.2.0-alpha.4",
26
- "@contember/schema": "^1.2.0-alpha.4",
27
- "@contember/schema-definition": "^1.2.0-alpha.4",
28
- "@contember/schema-migrations": "^1.2.0-alpha.4",
29
- "@contember/schema-utils": "^1.2.0-alpha.4",
21
+ "@contember/cli-common": "^1.2.0-alpha.5",
22
+ "@contember/config-loader": "^1.2.0-alpha.5",
23
+ "@contember/database-migrations": "^1.2.0-alpha.5",
24
+ "@contember/dic": "^1.2.0-alpha.5",
25
+ "@contember/engine-content-api": "^1.2.0-alpha.5",
26
+ "@contember/schema": "^1.2.0-alpha.5",
27
+ "@contember/schema-definition": "^1.2.0-alpha.5",
28
+ "@contember/schema-migrations": "^1.2.0-alpha.5",
29
+ "@contember/schema-utils": "^1.2.0-alpha.5",
30
30
  "chalk": "^4.1.2",
31
31
  "chalk-table": "^1.0.2",
32
32
  "esbuild": "0.14.31",
@@ -13,7 +13,7 @@ import { MigrationsContainerFactory } from '../../MigrationsContainer'
13
13
  import { AdminClient, readAdminFiles } from '../../utils/admin'
14
14
  import { URL } from 'url'
15
15
  import prompts from 'prompts'
16
- import { printMigrationDescription } from '../../utils/migrations'
16
+ import { createMigrationStatusTable } from '../../utils/migrations'
17
17
  import { maskToken } from '../../utils/token'
18
18
 
19
19
  type Args = {
@@ -26,32 +26,31 @@ type Options = ExecuteMigrationOptions & {
26
26
  }
27
27
 
28
28
  export class DeployCommand extends Command<Args, Options> {
29
+ constructor(
30
+ private readonly workspace: Workspace,
31
+ ) {
32
+ super()
33
+ }
34
+
29
35
  protected configure(configuration: CommandConfiguration<Args, Options>): void {
30
36
  configuration.description('Deploy Contember project')
31
37
  configuration.argument('dsn')
32
- configuration.argument('project').optional()
38
+ if (!this.workspace.isSingleProjectMode()) {
39
+ configuration.argument('project').optional()
40
+ }
33
41
  configuration.option('admin').valueRequired()
34
42
  configureExecuteMigrationCommand(configuration)
35
43
  }
36
44
 
37
45
  protected async execute(input: Input<Args, Options>): Promise<void | number> {
38
46
  const [dsn, projectName] = this.getNormalizedInput(input)
39
- const workspace = await Workspace.get(process.cwd())
40
- let project: Project
47
+ const project = await this.workspace.projects.getProject(projectName, { fuzzy: true })
41
48
 
42
49
  let apiUrl = input.getOption('instance')
43
50
  let adminEndpoint = input.getOption('admin')
44
51
 
45
52
  let apiTokenFromDsn: string | undefined = undefined
46
- if (projectName) {
47
- project = await workspace.projects.getProject(projectName, { fuzzy: true })
48
- } else {
49
- const projects = await workspace.projects.listProjects()
50
- if (projects.length !== 1) {
51
- throw 'Please specify a local name project'
52
- }
53
- project = projects[0]
54
- }
53
+
55
54
  let remoteProject = input.getOption('remote-project') || project.name
56
55
  if (dsn) {
57
56
  const uri = new URL(dsn)
@@ -62,8 +61,8 @@ export class DeployCommand extends Command<Args, Options> {
62
61
  apiTokenFromDsn = uri.password
63
62
  adminEndpoint = (uri.protocol === 'contember-unsecure:' ? 'http://' : 'https://') + uri.host
64
63
  }
65
- const instance = await interactiveResolveInstanceEnvironmentFromInput(workspace, apiUrl ?? (adminEndpoint ? adminEndpoint + '/_api' : undefined))
66
- const apiToken = await interactiveResolveApiToken({ workspace, instance, apiToken: apiTokenFromDsn })
64
+ const instance = await interactiveResolveInstanceEnvironmentFromInput(this.workspace, apiUrl ?? (adminEndpoint ? adminEndpoint + '/_api' : undefined))
65
+ const apiToken = await interactiveResolveApiToken({ workspace: this.workspace, instance, apiToken: apiTokenFromDsn })
67
66
  console.log('')
68
67
  console.log('Contember project deployment configuration:')
69
68
  console.log(`Local project name: ${project.name}`)
@@ -86,6 +85,12 @@ export class DeployCommand extends Command<Args, Options> {
86
85
  }
87
86
 
88
87
  const status = await resolveMigrationStatus(systemClient, container.migrationsResolver, false)
88
+
89
+ if (status.errorMigrations.length > 0) {
90
+ console.error(createMigrationStatusTable(status.errorMigrations))
91
+ throw `Cannot execute migrations`
92
+ }
93
+
89
94
  if (status.migrationsToExecute.length === 0 && !adminEndpoint) {
90
95
  console.log('Nothing to do.')
91
96
  return 0
@@ -1,4 +1,4 @@
1
- import { Command, CommandConfiguration, Input } from '@contember/cli-common'
1
+ import { Command, CommandConfiguration, Input, Workspace } from '@contember/cli-common'
2
2
  import { printValidationErrors } from '../../utils/schema'
3
3
  import { InvalidSchemaException } from '@contember/schema-migrations'
4
4
  import { executeCreateMigrationCommand } from './MigrationCreateHelper'
@@ -16,7 +16,7 @@ import { validateMigrations } from './MigrationValidationHelper'
16
16
  import { loadSchema } from '../../utils/project/loadSchema'
17
17
 
18
18
  type Args = {
19
- project: string
19
+ project?: string
20
20
  migration?: string
21
21
  }
22
22
 
@@ -26,9 +26,17 @@ type Options = {
26
26
  }
27
27
 
28
28
  export class MigrationAmendCommand extends Command<Args, Options> {
29
+ constructor(
30
+ private readonly workspace: Workspace,
31
+ ) {
32
+ super()
33
+ }
34
+
29
35
  protected configure(configuration: CommandConfiguration<Args, Options>): void {
30
36
  configuration.description('Amends latest migration')
31
- configuration.argument('project')
37
+ if (!this.workspace.isSingleProjectMode()) {
38
+ configuration.argument('project')
39
+ }
32
40
  configuration.argument('migration').optional()
33
41
  configuration.option('force').description('Ignore migrations order and missing migrations (dev only)')
34
42
  configuration //
@@ -40,6 +48,7 @@ export class MigrationAmendCommand extends Command<Args, Options> {
40
48
  protected async execute(input: Input<Args, Options>): Promise<number> {
41
49
  return await executeCreateMigrationCommand(
42
50
  input,
51
+ { workspace: this.workspace },
43
52
  async ({
44
53
  schemaVersionBuilder,
45
54
  migrationsResolver,
@@ -11,19 +11,15 @@ import {
11
11
  import { Workspace, Project } from '@contember/cli-common'
12
12
 
13
13
  type Args = {
14
- project: string
14
+ project?: string
15
15
  migrationName: string
16
16
  }
17
17
 
18
18
  type Options = {}
19
19
 
20
- export const configureCreateMigrationCommand = (configuration: CommandConfiguration<Args, Options>) => {
21
- configuration.argument('project')
22
- configuration.argument('migrationName')
23
- }
24
-
25
20
  export const executeCreateMigrationCommand = async (
26
21
  input: Input<Pick<Args, 'project'>, Options>,
22
+ { workspace }: {workspace: Workspace},
27
23
  createMigrationCallback: (args: {
28
24
  workspace: Workspace
29
25
  project: Project
@@ -36,7 +32,6 @@ export const executeCreateMigrationCommand = async (
36
32
  }) => Promise<number>,
37
33
  ) => {
38
34
  const projectName = input.getArgument('project')
39
- const workspace = await Workspace.get(process.cwd())
40
35
  const allProjects = projectName === '.'
41
36
  const projects = allProjects
42
37
  ? await workspace.projects.listProjects()
@@ -7,7 +7,7 @@ import { Schema } from '@contember/schema'
7
7
  import { Workspace } from '@contember/cli-common'
8
8
 
9
9
  type Args = {
10
- project: string
10
+ project?: string
11
11
  migration?: string
12
12
  }
13
13
 
@@ -48,9 +48,17 @@ let printMigrationDescription = async function (
48
48
  }
49
49
 
50
50
  export class MigrationDescribeCommand extends Command<Args, Options> {
51
+ constructor(
52
+ private readonly workspace: Workspace,
53
+ ) {
54
+ super()
55
+ }
56
+
51
57
  protected configure(configuration: CommandConfiguration<Args, Options>): void {
52
58
  configuration.description('Describes a migration')
53
- configuration.argument('project')
59
+ if (!this.workspace.isSingleProjectMode()) {
60
+ configuration.argument('project')
61
+ }
54
62
  configuration.argument('migration').optional()
55
63
  configuration.option('sql-only').valueNone()
56
64
  configuration.option('no-sql').valueNone()
@@ -59,7 +67,7 @@ export class MigrationDescribeCommand extends Command<Args, Options> {
59
67
  protected async execute(input: Input<Args, Options>): Promise<void> {
60
68
  const projectName = input.getArgument('project')
61
69
 
62
- const workspace = await Workspace.get(process.cwd())
70
+ const workspace = this.workspace
63
71
  const project = await workspace.projects.getProject(projectName, { fuzzy: true })
64
72
  const migrationsDir = await project.migrationsDir
65
73
  const container = new MigrationsContainerFactory(migrationsDir).create()
@@ -1,7 +1,7 @@
1
- import { Command, CommandConfiguration, Input } from '@contember/cli-common'
1
+ import { Command, CommandConfiguration, Input, Workspace } from '@contember/cli-common'
2
2
  import { printValidationErrors } from '../../utils/schema'
3
3
  import { InvalidSchemaException } from '@contember/schema-migrations'
4
- import { configureCreateMigrationCommand, executeCreateMigrationCommand } from './MigrationCreateHelper'
4
+ import { executeCreateMigrationCommand } from './MigrationCreateHelper'
5
5
  import { createMigrationStatusTable, printMigrationDescription } from '../../utils/migrations'
6
6
  import { executeMigrations, resolveMigrationStatus } from './MigrationExecuteHelper'
7
7
  import prompts from 'prompts'
@@ -11,7 +11,7 @@ import { SystemClient } from '../../utils/system'
11
11
  import { loadSchema } from '../../utils/project/loadSchema'
12
12
 
13
13
  type Args = {
14
- project: string
14
+ project?: string
15
15
  migrationName: string
16
16
  }
17
17
 
@@ -21,9 +21,18 @@ type Options = {
21
21
  }
22
22
 
23
23
  export class MigrationDiffCommand extends Command<Args, Options> {
24
+ constructor(
25
+ private readonly workspace: Workspace,
26
+ ) {
27
+ super()
28
+ }
29
+
24
30
  protected configure(configuration: CommandConfiguration<Args, Options>): void {
25
31
  configuration.description('Creates schema migration diff for given project')
26
- configureCreateMigrationCommand(configuration)
32
+ if (!this.workspace.isSingleProjectMode()) {
33
+ configuration.argument('project')
34
+ }
35
+ configuration.argument('migrationName')
27
36
  configuration.option('execute').valueNone()
28
37
  configuration //
29
38
  .option('yes')
@@ -34,6 +43,7 @@ export class MigrationDiffCommand extends Command<Args, Options> {
34
43
  protected async execute(input: Input<Args, Options>): Promise<number> {
35
44
  return await executeCreateMigrationCommand(
36
45
  input,
46
+ { workspace: this.workspace },
37
47
  async ({
38
48
  schemaVersionBuilder,
39
49
  migrationsResolver,
@@ -13,7 +13,7 @@ import { interactiveResolveApiToken, TenantClient } from '../../utils/tenant'
13
13
  import { SystemClient } from '../../utils/system'
14
14
 
15
15
  type Args = {
16
- project: string
16
+ project?: string
17
17
  migration?: string
18
18
  }
19
19
 
@@ -22,9 +22,17 @@ type Options = ExecuteMigrationOptions & {
22
22
  }
23
23
 
24
24
  export class MigrationExecuteCommand extends Command<Args, Options> {
25
+ constructor(
26
+ private readonly workspace: Workspace,
27
+ ) {
28
+ super()
29
+ }
30
+
25
31
  protected configure(configuration: CommandConfiguration<Args, Options>): void {
26
32
  configuration.description('Executes migrations on an instance')
27
- configuration.argument('project')
33
+ if (!this.workspace.isSingleProjectMode()) {
34
+ configuration.argument('project')
35
+ }
28
36
  configuration.argument('migration').optional()
29
37
  configuration.option('force').description('Ignore migrations order and missing migrations (dev only)')
30
38
  configureExecuteMigrationCommand(configuration)
@@ -33,12 +41,9 @@ export class MigrationExecuteCommand extends Command<Args, Options> {
33
41
  protected async execute(input: Input<Args, Options>): Promise<number> {
34
42
  const projectName = input.getArgument('project')
35
43
 
36
- const workspace = await Workspace.get(process.cwd())
44
+ const workspace = this.workspace
37
45
 
38
46
  const allProjects = projectName === '.'
39
- if (!allProjects) {
40
- validateProjectName(projectName)
41
- }
42
47
  const remoteProjectOption = input?.getOption('remote-project')
43
48
  if (remoteProjectOption && allProjects) {
44
49
  throw 'Option remote-project can be used only for a single project'
@@ -1,4 +1,4 @@
1
- import { Command, CommandConfiguration, Input } from '@contember/cli-common'
1
+ import { Command, CommandConfiguration, Input, Workspace } from '@contember/cli-common'
2
2
  import { MigrationVersionHelper } from '@contember/schema-migrations'
3
3
  import { executeCreateMigrationCommand } from './MigrationCreateHelper'
4
4
  import { getMigrationByName } from '../../utils/migrations'
@@ -7,7 +7,7 @@ import { emptySchema } from '@contember/schema-utils'
7
7
  import { validateMigrations } from './MigrationValidationHelper'
8
8
 
9
9
  type Args = {
10
- project: string
10
+ project?: string
11
11
  migration: string[]
12
12
  }
13
13
 
@@ -16,9 +16,18 @@ type Options = {
16
16
  }
17
17
 
18
18
  export class MigrationRebaseCommand extends Command<Args, Options> {
19
+ constructor(
20
+ private readonly workspace: Workspace,
21
+ ) {
22
+ super()
23
+ }
24
+
25
+
19
26
  protected configure(configuration: CommandConfiguration<Args, Options>): void {
20
27
  configuration.description('Rebase migrations on filesystem and in local instance')
21
- configuration.argument('project')
28
+ if (!this.workspace.isSingleProjectMode()) {
29
+ configuration.argument('project')
30
+ }
22
31
  configuration.argument('migration').variadic()
23
32
  configuration //
24
33
  .option('yes')
@@ -29,6 +38,7 @@ export class MigrationRebaseCommand extends Command<Args, Options> {
29
38
  protected async execute(input: Input<Args, Options>): Promise<number> {
30
39
  return await executeCreateMigrationCommand(
31
40
  input,
41
+ { workspace: this.workspace },
32
42
  async ({
33
43
  schemaVersionBuilder,
34
44
  migrationsResolver,
@@ -8,7 +8,7 @@ import chalk from 'chalk'
8
8
  import { Workspace } from '@contember/cli-common'
9
9
 
10
10
  type Args = {
11
- project: string
11
+ project?: string
12
12
  }
13
13
 
14
14
  type Options = {
@@ -20,9 +20,17 @@ type Options = {
20
20
  }
21
21
 
22
22
  export class MigrationStatusCommand extends Command<Args, Options> {
23
+ constructor(
24
+ private readonly workspace: Workspace,
25
+ ) {
26
+ super()
27
+ }
28
+
23
29
  protected configure(configuration: CommandConfiguration<Args, Options>): void {
24
30
  configuration.description('Shows status of executed migrations on an instance & sync status')
25
- configuration.argument('project')
31
+ if (!this.workspace.isSingleProjectMode()) {
32
+ configuration.argument('project')
33
+ }
26
34
  configuration //
27
35
  .option('instance')
28
36
  .valueRequired()
@@ -48,7 +56,7 @@ export class MigrationStatusCommand extends Command<Args, Options> {
48
56
  protected async execute(input: Input<Args, Options>): Promise<number> {
49
57
  const projectName = input.getArgument('project')
50
58
 
51
- const workspace = await Workspace.get(process.cwd())
59
+ const workspace = this.workspace
52
60
  const project = await workspace.projects.getProject(projectName, { fuzzy: true })
53
61
  const migrationsDir = await project.migrationsDir
54
62
  const container = new MigrationsContainerFactory(migrationsDir).create()
@@ -10,6 +10,12 @@ type Options = {
10
10
  }
11
11
 
12
12
  export class ProjectCreateCommand extends Command<Args, Options> {
13
+ constructor(
14
+ private readonly workspace: Workspace,
15
+ ) {
16
+ super()
17
+ }
18
+
13
19
  protected configure(configuration: CommandConfiguration<Args, Options>): void {
14
20
  configuration.description('Creates a new Contember project')
15
21
  configuration.argument('project')
@@ -19,7 +25,7 @@ export class ProjectCreateCommand extends Command<Args, Options> {
19
25
  protected async execute(input: Input<Args, Options>): Promise<void> {
20
26
  const [projectName] = [input.getArgument('project')]
21
27
  validateProjectName(projectName)
22
- const workspace = await Workspace.get(process.cwd())
28
+ const workspace = this.workspace
23
29
 
24
30
  const template = input.getOption('template')
25
31
  await workspace.projects.createProject(projectName, { template })
@@ -1,4 +1,4 @@
1
- import { Command, CommandConfiguration, Input, validateProjectName, Workspace } from '@contember/cli-common'
1
+ import { Command, CommandConfiguration, Input, Workspace } from '@contember/cli-common'
2
2
  import { validateSchemaAndPrintErrors } from '../../utils/schema'
3
3
  import { loadSchema } from '../../utils/project/loadSchema'
4
4
  import { renderProjectInfoHtml } from '../../utils/project/projectDescribe'
@@ -6,7 +6,7 @@ import { writeFile } from 'fs/promises'
6
6
  import { join } from 'path'
7
7
 
8
8
  type Args = {
9
- project: string
9
+ project?: string
10
10
  }
11
11
 
12
12
  type Options = {
@@ -14,18 +14,23 @@ type Options = {
14
14
  }
15
15
 
16
16
  export class ProjectGenerateDocumentation extends Command<Args, Options> {
17
+ constructor(
18
+ private readonly workspace: Workspace,
19
+ ) {
20
+ super()
21
+ }
22
+
17
23
  protected configure(configuration: CommandConfiguration<Args, Options>): void {
18
24
  configuration.description('Generates HTML documentation from project schema')
19
- configuration.argument('project')
25
+ if (!this.workspace.isSingleProjectMode()) {
26
+ configuration.argument('project')
27
+ }
20
28
  configuration.option('output').valueRequired().description('file name or "stdout"')
21
29
  }
22
30
 
23
31
  protected async execute(input: Input<Args, Options>): Promise<number> {
24
32
  const projectName = input.getArgument('project')
25
- const workspace = await Workspace.get(process.cwd())
26
-
27
- validateProjectName(projectName)
28
- const project = await workspace.projects.getProject(projectName, { fuzzy: true })
33
+ const project = await this.workspace.projects.getProject(projectName, { fuzzy: true })
29
34
  const schema = await loadSchema(project)
30
35
  if (!validateSchemaAndPrintErrors(schema, 'Defined schema is invalid:')) {
31
36
  return 1
@@ -14,7 +14,7 @@ import { mergeSchemas } from '@graphql-tools/schema'
14
14
  import { loadSchema } from '../../utils/project/loadSchema'
15
15
 
16
16
  type Args = {
17
- project: string
17
+ project?: string
18
18
  }
19
19
 
20
20
  type Options = {
@@ -23,19 +23,26 @@ type Options = {
23
23
  }
24
24
 
25
25
  export class ProjectPrintSchemaCommand extends Command<Args, Options> {
26
+ constructor(
27
+ private readonly workspace: Workspace,
28
+ ) {
29
+ super()
30
+ }
31
+
26
32
  protected configure(configuration: CommandConfiguration<Args, Options>): void {
27
33
  configuration.description('Prints project schema')
28
- configuration.argument('project')
34
+ if (!this.workspace.isSingleProjectMode()) {
35
+ configuration.argument('project')
36
+ }
29
37
  configuration.option('format').valueRequired().description('graphql|introspection|schema')
30
38
  configuration.option('role').valueArray()
31
39
  }
32
40
 
33
41
  protected async execute(input: Input<Args, Options>): Promise<number> {
34
42
  const projectName = input.getArgument('project')
35
- const workspace = await Workspace.get(process.cwd())
43
+ const workspace = this.workspace
36
44
  const format = input.getOption('format') || 'graphql'
37
45
 
38
- validateProjectName(projectName)
39
46
  const project = await workspace.projects.getProject(projectName, { fuzzy: true })
40
47
  const schema = await loadSchema(project)
41
48
  if (!validateSchemaAndPrintErrors(schema, 'Defined schema is invalid:')) {
@@ -6,25 +6,30 @@ import { validateMigrations } from '../migrations/MigrationValidationHelper'
6
6
  import { loadSchema } from '../../utils/project/loadSchema'
7
7
 
8
8
  type Args = {
9
- project: string
9
+ project?: string
10
10
  }
11
11
 
12
12
  type Options = {}
13
13
 
14
14
  export class ProjectValidateCommand extends Command<Args, Options> {
15
+ constructor(
16
+ private readonly workspace: Workspace,
17
+ ) {
18
+ super()
19
+ }
20
+
15
21
  protected configure(configuration: CommandConfiguration<Args, Options>): void {
16
22
  configuration.description('Validates project schema')
17
- configuration.argument('project')
23
+ if (!this.workspace.isSingleProjectMode()) {
24
+ configuration.argument('project')
25
+ }
18
26
  }
19
27
 
20
28
  protected async execute(input: Input<Args, Options>): Promise<number> {
21
29
  const [projectName] = [input.getArgument('project')]
22
- const workspace = await Workspace.get(process.cwd())
30
+ const workspace = this.workspace
23
31
 
24
32
  const allProjects = projectName === '.'
25
- if (!allProjects) {
26
- validateProjectName(projectName)
27
- }
28
33
  const projects = allProjects
29
34
  ? await workspace.projects.listProjects()
30
35
  : [await workspace.projects.getProject(projectName, { fuzzy: true })]
@@ -10,6 +10,12 @@ type Args = {
10
10
  type Options = {}
11
11
 
12
12
  export class CreateApiKeyCommand extends Command<Args, Options> {
13
+ constructor(
14
+ private readonly workspace: Workspace,
15
+ ) {
16
+ super()
17
+ }
18
+
13
19
  protected configure(configuration: CommandConfiguration<Args, Options>): void {
14
20
  configuration.description('Creates an API key')
15
21
  configuration //
@@ -22,7 +28,7 @@ export class CreateApiKeyCommand extends Command<Args, Options> {
22
28
  if (!process.stdin.isTTY) {
23
29
  throw 'This command is interactive and requires TTY'
24
30
  }
25
- const workspace = await Workspace.get(process.cwd())
31
+ const workspace = this.workspace
26
32
  const instance = await interactiveResolveInstanceEnvironmentFromInput(workspace, input.getArgument('instance'))
27
33
  const apiToken = await interactiveResolveApiToken({ workspace, instance })
28
34
  const tenantClient = TenantClient.create(instance.baseUrl, apiToken)
@@ -10,6 +10,12 @@ type Args = {
10
10
  type Options = {}
11
11
 
12
12
  export class InviteCommand extends Command<Args, Options> {
13
+ constructor(
14
+ private readonly workspace: Workspace,
15
+ ) {
16
+ super()
17
+ }
18
+
13
19
  protected configure(configuration: CommandConfiguration<Args, Options>): void {
14
20
  configuration.description('Invites a user by an email')
15
21
  configuration //
@@ -22,7 +28,7 @@ export class InviteCommand extends Command<Args, Options> {
22
28
  if (!process.stdin.isTTY) {
23
29
  throw 'This command is interactive and requires TTY'
24
30
  }
25
- const workspace = await Workspace.get(process.cwd())
31
+ const workspace = this.workspace
26
32
  const instance = await interactiveResolveInstanceEnvironmentFromInput(workspace, input.getArgument('instance'))
27
33
  const apiToken = await interactiveResolveApiToken({ workspace, instance })
28
34
  const tenantClient = TenantClient.create(instance.baseUrl, apiToken)
@@ -10,6 +10,12 @@ type Args = {
10
10
  type Options = {}
11
11
 
12
12
  export class ResetPasswordCommand extends Command<Args, Options> {
13
+ constructor(
14
+ private readonly workspace: Workspace,
15
+ ) {
16
+ super()
17
+ }
18
+
13
19
  protected configure(configuration: CommandConfiguration<Args, Options>): void {
14
20
  configuration.description('Resets user password')
15
21
  configuration //
@@ -22,7 +28,7 @@ export class ResetPasswordCommand extends Command<Args, Options> {
22
28
  if (!process.stdin.isTTY) {
23
29
  throw 'This command is interactive and requires TTY'
24
30
  }
25
- const workspace = await Workspace.get(process.cwd())
31
+ const workspace = this.workspace
26
32
  const instance = await interactiveResolveInstanceEnvironmentFromInput(workspace, input.getArgument('instance'))
27
33
  const loginToken = await interactiveResolveLoginToken(workspace)
28
34
  await interactiveResetPassword({ apiUrl: instance.baseUrl, loginToken })
@@ -10,6 +10,12 @@ type Args = {
10
10
  type Options = {}
11
11
 
12
12
  export class SignInCommand extends Command<Args, Options> {
13
+ constructor(
14
+ private readonly workspace: Workspace,
15
+ ) {
16
+ super()
17
+ }
18
+
13
19
  protected configure(configuration: CommandConfiguration<Args, Options>): void {
14
20
  configuration.description('Signs in a user')
15
21
  configuration //
@@ -22,7 +28,7 @@ export class SignInCommand extends Command<Args, Options> {
22
28
  if (!process.stdin.isTTY) {
23
29
  throw 'This command is interactive and requires TTY'
24
30
  }
25
- const workspace = await Workspace.get(process.cwd())
31
+ const workspace = this.workspace
26
32
  const instance = await interactiveResolveInstanceEnvironmentFromInput(workspace, input.getArgument('instance'))
27
33
  const loginToken = await interactiveResolveLoginToken(workspace)
28
34
  const { sessionToken } = await interactiveSignIn({ apiUrl: instance.baseUrl, loginToken })
@@ -10,6 +10,12 @@ type Args = {
10
10
  type Options = {}
11
11
 
12
12
  export class WorkspaceUpdateApiCommand extends Command<Args, Options> {
13
+ constructor(
14
+ private readonly workspace: Workspace,
15
+ ) {
16
+ super()
17
+ }
18
+
13
19
  protected configure(configuration: CommandConfiguration<Args, Options>): void {
14
20
  configuration.description('Updates Contember API version and all related packages')
15
21
  configuration.argument('version')
@@ -17,7 +23,7 @@ export class WorkspaceUpdateApiCommand extends Command<Args, Options> {
17
23
 
18
24
  protected async execute(input: Input<Args, Options>): Promise<void> {
19
25
  const version = input.getArgument('version')
20
- const workspace = await Workspace.get(process.cwd())
26
+ const workspace = this.workspace
21
27
  const upgradablePackages = ['@contember/schema', '@contember/schema-definition', '@contember/cli']
22
28
 
23
29
  await updateNpmPackages(upgradablePackages.map(it => ({ name: it, version })), workspace.directory)