-
Notifications
You must be signed in to change notification settings - Fork 6
Feat/tsemach/add commands for manifest management #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tsemachLi
wants to merge
28
commits into
master
Choose a base branch
from
feat/tsemach/add-command-for-importing-app-manifest
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
d047075
Feat: add command for generating app feature component
112ac16
Merge remote-tracking branch 'origin/master'
b0582dd
Merge remote-tracking branch 'origin/master'
55a7e98
Merge remote-tracking branch 'origin/master'
9a034ef
Merge remote-tracking branch 'origin/master'
c6d4a71
Merge remote-tracking branch 'origin/master'
4e51746
Merge remote-tracking branch 'origin/master'
f7718dc
Merge remote-tracking branch 'origin/master'
4f4fbbf
Feat: new command for importing app manifest
67b861c
Feat: new command for importing app manifest
750e8b4
Feat: new command for exporting app manifest
4aba485
[beta] Feat: new command for exporting app manifest
11bcb5d
[beta] Feat: new command for exporting app manifest
a393bb5
[beta] Feat: new command for exporting app manifest
beb70d0
[beta] Feat: new command for exporting app manifest
4a5ed0b
[beta] Feat: new command for exporting app manifest
d893002
[beta] Feat: bumping version
ba34576
Merge remote-tracking branch 'origin/master'
3805b5c
Merge branch 'refs/heads/master' into feat/tsemach/add-command-for-im…
95a7c0c
[beta] Feat: unzip manifest
228ca32
[beta] Feat: unzip manifest
890db85
[beta] Feat: unzip manifest
e9a3356
[beta] Feat: increase import timeout
7ea427c
Feat/tsemach/support dynamic fields for manifest (#117)
tsemachLi 2f7b151
[beta] Add new validate task to export manifest command (#119)
Shaharshaki2 644c484
Feat/danieljak/support-flag-to-allow-missing-variables (#124)
dh94 7a0fa34
[beta] allow missing variables
Shaharshaki2 31f9011
[beta] Feat/shaharsh/support customize path for import and export man…
Shaharshaki2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| export default { name: "@mondaycom/apps-cli", version: "2.3.5" }; | ||
| export default { name: '@mondaycom/apps-cli', version: '4.3.2' }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import { Flags } from '@oclif/core'; | ||
| import { Listr } from 'listr2'; | ||
|
|
||
| import { AuthenticatedCommand } from 'commands-base/authenticated-command'; | ||
| import { DynamicChoicesService } from 'services/dynamic-choices-service'; | ||
| import * as exportService from 'services/export-manifest-service'; | ||
| import { ExportCommandTasksContext } from 'types/commands/manifest-export'; | ||
| import logger from 'utils/logger'; | ||
|
|
||
| const MESSAGES = { | ||
| appId: 'App id (will export the live version)', | ||
| appVersionId: 'App version id', | ||
| path: 'Path to export your app manifest files to', | ||
| }; | ||
|
|
||
| export default class ManifestExport extends AuthenticatedCommand { | ||
| static description = 'export app manifest.'; | ||
| static withPrintCommand = false; | ||
| static examples = [ | ||
| '<%= config.bin %> <%= command.id %>', | ||
| '<%= config.bin %> <%= command.id %> -p ./exports', | ||
| '<%= config.bin %> <%= command.id %> --manifestPath ./my-manifests', | ||
| ]; | ||
|
|
||
| static flags = ManifestExport.serializeFlags({ | ||
| manifestPath: Flags.string({ | ||
| char: 'p', | ||
| description: MESSAGES.path, | ||
| }), | ||
| appId: Flags.string({ | ||
| char: 'a', | ||
| description: MESSAGES.appId, | ||
| }), | ||
| appVersionId: Flags.integer({ | ||
| char: 'i', | ||
| aliases: ['v'], | ||
| description: MESSAGES.appVersionId, | ||
| }), | ||
| }); | ||
|
|
||
| DEBUG_TAG = 'manifest_export'; | ||
|
|
||
| async getAppVersionId(appVersionId: number | undefined, appId: number | undefined): Promise<number> { | ||
| if (appVersionId) return appVersionId; | ||
|
|
||
| const latestDraftVersion = await DynamicChoicesService.chooseAppAndAppVersion(false, true, { | ||
| appId: Number(appId), | ||
| autoSelectVersion: false, | ||
| }); | ||
|
|
||
| return latestDraftVersion.appVersionId; | ||
| } | ||
|
|
||
| public async run(): Promise<void> { | ||
| try { | ||
| const { flags } = await this.parse(ManifestExport); | ||
| const { manifestPath, appId: appIdAsString, appVersionId: appVersionIdAsString } = flags; | ||
|
|
||
| let appId = appIdAsString ? Number(appIdAsString) : undefined; | ||
| let appVersionId = appVersionIdAsString ? Number(appVersionIdAsString) : undefined; | ||
|
|
||
| if (appVersionId && !appId) { | ||
| logger.error('App id is required when app version id is provided'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| if (!appId && !appVersionId) { | ||
| appId = Number(await DynamicChoicesService.chooseApp()); | ||
| appVersionId = await this.getAppVersionId(undefined, appId); | ||
| } | ||
|
|
||
| this.preparePrintCommand(this, flags); | ||
|
|
||
| const tasks = new Listr<ExportCommandTasksContext>( | ||
| [ | ||
| { title: 'Validate app before exporting manifest', task: exportService.validateManifestTask }, | ||
| { title: 'Export app manifest', task: exportService.downloadManifestTask }, | ||
| ], | ||
| { ctx: { appVersionId, appId: appId!, manifestPath } }, | ||
| ); | ||
|
|
||
| await tasks.run(); | ||
| } catch (error) { | ||
| logger.debug(error, this.DEBUG_TAG); | ||
| process.exit(1); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| import { Flags } from '@oclif/core'; | ||
| import { Listr } from 'listr2'; | ||
|
|
||
| import { AuthenticatedCommand } from 'commands-base/authenticated-command'; | ||
| import { DynamicChoicesService } from 'services/dynamic-choices-service'; | ||
| import * as importService from 'services/import-manifest-service'; | ||
| import { PromptService } from 'services/prompt-service'; | ||
| import { ImportCommandTasksContext } from 'types/commands/manifest-import'; | ||
| import logger from 'utils/logger'; | ||
|
|
||
| const MESSAGES = { | ||
| path: 'Path to your app manifest file on your machine', | ||
| appId: 'App id (will create a new draft version)', | ||
| appVersionId: 'App version id to override', | ||
| newApp: 'Create new app', | ||
| allowMissingVariables: 'Allow missing variables', | ||
| }; | ||
|
|
||
| export default class ManifestImport extends AuthenticatedCommand { | ||
| static description = 'Import manifest with optional template variables.'; | ||
| static withPrintCommand = false; | ||
| static examples = [ | ||
| '<%= config.bin %> <%= command.id %>', | ||
| '<%= config.bin %> <%= command.id %> -p ./manifest.json', | ||
| '<%= config.bin %> <%= command.id %> --manifestPath ./manifest.json', | ||
| ]; | ||
|
|
||
| static flags = ManifestImport.serializeFlags({ | ||
| manifestPath: Flags.string({ | ||
| char: 'p', | ||
| description: MESSAGES.path, | ||
| }), | ||
| appId: Flags.string({ | ||
| char: 'a', | ||
| description: MESSAGES.appId, | ||
| }), | ||
| appVersionId: Flags.integer({ | ||
| char: 'i', | ||
| aliases: ['v'], | ||
| description: MESSAGES.appVersionId, | ||
| }), | ||
| newApp: Flags.boolean({ | ||
| description: MESSAGES.newApp, | ||
| char: 'n', | ||
| aliases: ['new'], | ||
| default: false, | ||
| }), | ||
| allowMissingVariables: Flags.boolean({ | ||
| description: MESSAGES.allowMissingVariables, | ||
| char: 'm', | ||
| aliases: ['allow-missing-variables'], | ||
| default: false, | ||
| }), | ||
| }); | ||
|
|
||
| DEBUG_TAG = 'manifest_import'; | ||
|
|
||
| async getAppVersionId(appVersionId: number | undefined, appId: number | undefined): Promise<number> { | ||
| if (appVersionId) return appVersionId; | ||
|
|
||
| const latestDraftVersion = await DynamicChoicesService.chooseAppAndAppVersion(false, false, { | ||
| appId: Number(appId), | ||
| autoSelectVersion: false, | ||
| }); | ||
|
|
||
| return latestDraftVersion.appVersionId; | ||
| } | ||
|
|
||
| public async run(): Promise<void> { | ||
| try { | ||
| const { flags } = await this.parse(ManifestImport); | ||
| const { manifestPath: initialManifestPath } = flags; | ||
| const { appId: appIdAsString, appVersionId: appVersionIdAsString, newApp, allowMissingVariables } = flags; | ||
| let manifestPath = initialManifestPath; | ||
| let appId = appIdAsString ? Number(appIdAsString) : undefined; | ||
| let appVersionId = appVersionIdAsString ? Number(appVersionIdAsString) : undefined; | ||
|
|
||
| if (!manifestPath) { | ||
| manifestPath = await PromptService.promptFile(MESSAGES.path, ['json', 'yaml']); | ||
| } | ||
|
|
||
| const shouldCreateNewApp = await importService.shouldCreateNewApp({ appId, appVersionId, newApp }); | ||
| if (!shouldCreateNewApp) { | ||
| appId = await DynamicChoicesService.chooseApp(); | ||
| } | ||
|
|
||
| const shouldCreateNewAppVersion = await importService.shouldCreateNewAppVersion({ | ||
| appId, | ||
| appVersionId, | ||
| newApp: shouldCreateNewApp, | ||
| }); | ||
|
|
||
| if (!shouldCreateNewAppVersion && !shouldCreateNewApp) { | ||
| appVersionId = await this.getAppVersionId(appVersionId, appId); | ||
| } | ||
|
|
||
| if (appVersionId && !appId) { | ||
| logger.error('App id is required when app version id is provided', this.DEBUG_TAG); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| this.preparePrintCommand(this, { appVersionId, manifestPath, appId, newApp: shouldCreateNewApp }); | ||
|
|
||
| const ctx = { | ||
| appVersionId, | ||
| appId, | ||
| manifestFilePath: manifestPath, | ||
| allowMissingVariables, | ||
| }; | ||
| const tasks = new Listr<ImportCommandTasksContext>( | ||
| [{ title: 'Importing app manifest', task: importService.uploadManifestTsk }], | ||
| { ctx }, | ||
| ); | ||
|
|
||
| await tasks.run(); | ||
| } catch (error) { | ||
| logger.debug(error, this.DEBUG_TAG); | ||
| process.exit(1); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { processManifestTemplate } from 'services/import-manifest-service'; | ||
| import { loadFile } from 'utils/file-system'; | ||
|
|
||
| jest.mock('utils/file-system'); | ||
|
|
||
| describe('processManifestTemplate', () => { | ||
| const mockLoadFile = loadFile as jest.MockedFunction<typeof loadFile>; | ||
| const mockPath = 'path/to/manifest.json'; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('should process valid manifest with environment variables', async () => { | ||
| process.env.TEST_VAR = 'test-value'; | ||
| mockLoadFile.mockResolvedValue('{"key": "{{TEST_VAR}}"}'); | ||
|
|
||
| const result = await processManifestTemplate(mockPath); | ||
| expect(result).toEqual({ key: 'test-value' }); | ||
| }); | ||
|
|
||
| it('should throw TypeError for invalid JSON', async () => { | ||
| mockLoadFile.mockResolvedValue('invalid json'); | ||
|
|
||
| await expect(processManifestTemplate(mockPath)).rejects.toThrow(TypeError); | ||
| await expect(processManifestTemplate(mockPath)).rejects.toThrow(/Failed to parse manifest file/); | ||
| }); | ||
|
|
||
| it('should throw error for missing environment variables', async () => { | ||
| delete process.env.MISSING_VAR; | ||
| mockLoadFile.mockResolvedValue('{"key": "{{MISSING_VAR}}"}'); | ||
|
|
||
| await expect(processManifestTemplate(mockPath)).rejects.toThrow(/Missing variable/); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,15 @@ | ||
| app: | ||
| scopes: | ||
| - name: "test" | ||
| type: "user" | ||
| - name: 'test' | ||
| type: 'user' | ||
| permissions: | ||
| - "read" | ||
| - "write" | ||
| - 'read' | ||
| - 'write' | ||
| hosting: | ||
| cdn: | ||
| type: upload | ||
| path: "./build" | ||
| path: './build' | ||
| server: | ||
| type: upload | ||
| path: "./server" | ||
| path: './server' | ||
| version: 1.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need the
zipBase64=true?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default is getting the zip in the response as buffer, which is harder to "catch" it programatically.
Here we getting it as base64 string and we can easily dump it to a file