forked from rockcarver/frodo-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
feature/extract-idm-scripts: Support exporting and importing idm scri… #73
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
skootrivir
wants to merge
3
commits into
main
Choose a base branch
from
feature/extract-idm-script-rework
base: main
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
3 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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 |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ import { | |
| FullImportOptions, | ||
| FullRealmExportInterface, | ||
| } from '@rockcarver/frodo-lib/types/ops/ConfigOps'; | ||
| import { SyncSkeleton } from '@rockcarver/frodo-lib/types/ops/MappingOps'; | ||
| import { MappingSkeleton, SyncSkeleton } from '@rockcarver/frodo-lib/types/ops/MappingOps'; | ||
| import { CustomNodeExportInterface } from '@rockcarver/frodo-lib/types/ops/NodeOps'; | ||
| import { ScriptExportInterface } from '@rockcarver/frodo-lib/types/ops/ScriptOps'; | ||
| import fs from 'fs'; | ||
|
|
@@ -18,8 +18,16 @@ import { | |
| } from '../utils/Config'; | ||
| import { cleanupProgressIndicators, printError } from '../utils/Console'; | ||
| import { saveServersToFiles } from './classic/ServerOps'; | ||
| import { ManagedSkeleton, writeManagedJsonToDirectory } from './IdmOps'; | ||
| import { writeSyncJsonToDirectory } from './MappingOps'; | ||
| import { | ||
| extractIdmScriptToSameLevel, | ||
| findScriptsFromIdm, | ||
| ManagedSkeleton, | ||
| writeManagedJsonToDirectory, | ||
| } from './IdmOps'; | ||
| import { | ||
| writeMappingJsonToDirectory, | ||
| writeSyncJsonToDirectory, | ||
| } from './MappingOps'; | ||
| import { extractCustomNodeScriptsToFiles } from './NodeOps'; | ||
| import { extractScriptsToFiles } from './ScriptOps'; | ||
| import { errorHandler } from './utils/OpsUtils'; | ||
|
|
@@ -82,17 +90,13 @@ export async function exportEverythingToFile( | |
| /** | ||
| * Export everything to separate files | ||
| * @param {boolean} extract Extracts the scripts from the exports into separate files if true | ||
| * @param {boolean} separateMappings separate sync.idm.json mappings if true, otherwise keep them in a single file | ||
| * @param {boolean} separateObjects separate managed.idm.json objects if true, otherwise keep them in a single file | ||
| * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true | ||
| * @param {boolean} keepModifiedProperties true to keep modified properties, otherwise delete them. Default: false | ||
| * @param {FullExportOptions} options export options | ||
| * @return {Promise<boolean>} a promise that resolves to true if successful, false otherwise | ||
| */ | ||
| export async function exportEverythingToFiles( | ||
| extract: boolean = false, | ||
| separateMappings: boolean = false, | ||
| separateObjects: boolean = false, | ||
| includeMeta: boolean = true, | ||
| keepModifiedProperties: boolean = false, | ||
| options: FullExportOptions = { | ||
|
|
@@ -124,9 +128,7 @@ export async function exportEverythingToFiles( | |
| `${baseDirectory}/global`, | ||
| includeMeta, | ||
| keepModifiedProperties, | ||
| extract, | ||
| separateMappings, | ||
| separateObjects | ||
| extract | ||
| ) | ||
| ); | ||
| Object.entries(exportData.realm).forEach(([realm, data]: [string, any]) => | ||
|
|
@@ -138,9 +140,7 @@ export async function exportEverythingToFiles( | |
| `${baseDirectory}/realm/${realm}`, | ||
| includeMeta, | ||
| keepModifiedProperties, | ||
| extract, | ||
| separateMappings, | ||
| separateObjects | ||
| extract | ||
| ) | ||
| ) | ||
| ); | ||
|
|
@@ -163,8 +163,6 @@ export async function exportEverythingToFiles( | |
| * @param {boolean} includeMeta true to include metadata, false otherwise. Default: true | ||
| * @param {boolean} keepModifiedProperties true to keep modified properties, otherwise delete them. Default: false | ||
| * @param {boolean} extract Extracts the scripts from the exports into separate files if true | ||
| * @param {boolean} separateMappings separate sync.idm.json mappings if true, otherwise keep them in a single file | ||
| * @param {boolean} separateObjects separate managed.idm.json objects if true, otherwise keep them in a single file | ||
| */ | ||
| export function exportItem( | ||
| exportData, | ||
|
|
@@ -173,9 +171,7 @@ export function exportItem( | |
| baseDirectory, | ||
| includeMeta, | ||
| keepModifiedProperties, | ||
| extract, | ||
| separateMappings = false, | ||
| separateObjects = false | ||
| extract | ||
| ) { | ||
| if (!obj || !Object.keys(obj).length) { | ||
| return; | ||
|
|
@@ -264,7 +260,8 @@ export function exportItem( | |
| writeSyncJsonToDirectory( | ||
| obj as SyncSkeleton, | ||
| `${baseDirectory.substring(getWorkingDirectory(false).length + 1)}/${fileType}`, | ||
| includeMeta | ||
| includeMeta, | ||
| extract | ||
| ); | ||
| } else if (type === 'server') { | ||
| saveServersToFiles( | ||
|
|
@@ -274,24 +271,40 @@ export function exportItem( | |
| extract, | ||
| includeMeta | ||
| ); | ||
| } else if (type === 'mapping') { | ||
| for (const [id, mapping] of Object.entries(obj)){ | ||
| writeMappingJsonToDirectory( | ||
| mapping as MappingSkeleton, | ||
| `${baseDirectory.substring(getWorkingDirectory(false).length + 1)}/${fileType}`, | ||
| includeMeta, | ||
| extract | ||
| ); | ||
| } | ||
| } else { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| Object.entries(obj).forEach(([id, value]: [string, any]) => { | ||
| if (type === 'idm') { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Everything inside this if statement is being repeated in IdmOps. We should have a helper function created that does this logic (put the helper function in IDM Ops, and call it something like |
||
| if (value != null) { | ||
| if (separateMappings && id === 'sync') { | ||
| writeSyncJsonToDirectory( | ||
| value as SyncSkeleton, | ||
| `${baseDirectory.substring(getWorkingDirectory(false).length + 1)}/${fileType}/sync`, | ||
| includeMeta | ||
| ); | ||
| } else if (separateObjects && id === 'managed') { | ||
| if (extract && id === 'managed') { | ||
| writeManagedJsonToDirectory( | ||
| value as ManagedSkeleton, | ||
| `${baseDirectory.substring(getWorkingDirectory(false).length + 1)}/${fileType}/managed`, | ||
| includeMeta | ||
| includeMeta, | ||
| extract | ||
| ); | ||
| } else { | ||
| } | ||
| else { | ||
| if (extract) { | ||
| const result = findScriptsFromIdm(value); | ||
| if (result.length !== 0) { | ||
| extractIdmScriptToSameLevel( | ||
| id, | ||
| value, | ||
| result, | ||
| `${baseDirectory.substring(getWorkingDirectory(false).length + 1)}/${fileType}/` | ||
| ); | ||
| } | ||
| } | ||
| const filename = `${id}.idm.json`; | ||
| if (filename.includes('/')) { | ||
| fs.mkdirSync( | ||
|
|
||
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.
This should be options.extract (it should be supported for individual objects). For example, if I want to export only alpha_user, alpha_user may have an onUpdate script, onCreate script, etc.
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.
This one is for -a, and I dont think we want to extract script for -a option