Skip to content

Commit 267413d

Browse files
committed
feat: Updated to importAndDestroy and added filtering for preventImport
1 parent 750f9d4 commit 267413d

File tree

10 files changed

+57
-30
lines changed

10 files changed

+57
-30
lines changed

package-lock.json

Lines changed: 22 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
"ajv": "^8.12.0",
1414
"ajv-formats": "^3.0.1",
1515
"chalk": "^5.3.0",
16-
"codify-schemas": "^1.0.63",
16+
"codify-schemas": "^1.0.69",
1717
"debug": "^4.3.4",
1818
"detect-indent": "^7.0.1",
1919
"diff": "^7.0.0",
20-
"ink": "^5",
20+
"ink": "^5.1.0",
2121
"jotai": "^2.11.1",
2222
"js-yaml": "^4.1.0",
2323
"js-yaml-source-map": "^0.2.2",
@@ -42,7 +42,7 @@
4242
"@types/semver": "^7.5.4",
4343
"@types/strip-ansi": "^5.2.1",
4444
"@typescript-eslint/eslint-plugin": "^8.16.0",
45-
"codify-plugin-lib": "^1.0.132",
45+
"codify-plugin-lib": "^1.0.140",
4646
"esbuild": "^0.24.0",
4747
"esbuild-plugin-copy": "^2.1.1",
4848
"eslint": "^8.51.0",

src/entities/resource-info.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export class ResourceInfo implements GetResourceInfoResponseData {
1515
type!: string;
1616
schema?: Record<string, unknown> | undefined;
1717
dependencies?: string[] | undefined;
18-
import?: { requiredParameters: null | string[]; } | undefined;
18+
importAndDestroy?: {
19+
preventImport?: boolean;
20+
requiredParameters: null | string[];
21+
} | undefined;
1922

2023
private parametersCache?: ParameterInfo[];
2124

@@ -24,6 +27,10 @@ export class ResourceInfo implements GetResourceInfoResponseData {
2427
get description(): string | undefined {
2528
return this.schema?.description as string | undefined;
2629
}
30+
31+
get canImport(): boolean {
32+
return this.importAndDestroy?.preventImport !== true;
33+
}
2734

2835
static fromResponseData(data: GetResourceInfoResponseData): ResourceInfo {
2936
const resourceInfo = new ResourceInfo()
@@ -57,7 +64,7 @@ export class ResourceInfo implements GetResourceInfoResponseData {
5764

5865
this.parametersCache = Object.entries(properties)
5966
.map(([propertyName, info]) => {
60-
const isRequired = this.import?.requiredParameters?.some((name) => name === propertyName)
67+
const isRequired = this.importAndDestroy?.requiredParameters?.some((name) => name === propertyName)
6168
?? (required as string[] | undefined)?.includes(propertyName)
6269
?? false;
6370

src/orchestrators/import.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ export class ImportOrchestrator {
6767
const matchedTypes = this.matchTypeIds(typeIds, [...typeIdsToDependenciesMap.keys()])
6868
await ImportOrchestrator.validate(matchedTypes, project, pluginManager, typeIdsToDependenciesMap);
6969

70-
const resourceInfoList = await pluginManager.getMultipleResourceInfo(matchedTypes);
70+
const resourceInfoList = (await pluginManager.getMultipleResourceInfo(matchedTypes))
71+
.filter((info) => info.canImport)
72+
7173
const resourcesToImport = await ImportOrchestrator.getImportParameters(reporter, project, resourceInfoList);
7274
const importResult = await ImportOrchestrator.import(pluginManager, resourcesToImport);
7375

@@ -318,7 +320,7 @@ ${JSON.stringify(unsupportedTypeIds)}`);
318320

319321
reporter.displayFileModifications([{ file: filePath, modification: { newFile, diff } }]);
320322

321-
const shouldSave = await reporter.promptConfirmation('Save the changes?');
323+
const shouldSave = await reporter.promptConfirmation(`Save the changes? (${filePath})`);
322324
if (!shouldSave) {
323325
reporter.displayMessage('\nSkipping save! Exiting...');
324326

@@ -338,15 +340,19 @@ ${JSON.stringify(unsupportedTypeIds)}`);
338340
private static async generateNewImportFileName(): Promise<string> {
339341
const cwd = process.cwd();
340342

341-
let fileName = path.join(cwd, 'import.codify.json')
343+
// Save codify to a new folder so it doesn't interfere with the current project
344+
const folderPath = path.join(cwd, 'codify-imports')
345+
await FileUtils.createFolder(folderPath)
346+
347+
let fileName = path.join(folderPath, 'import.codify.json')
342348
let counter = 1;
343349

344350
while(true) {
345351
if (!(await FileUtils.fileExists(fileName))) {
346352
return fileName;
347353
}
348354

349-
fileName = path.join(cwd, `import-${counter}.codify.json`);
355+
fileName = path.join(folderPath, `import-${counter}.codify.json`);
350356
counter++;
351357
}
352358
}

src/ui/components/progress/progress-display.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ export function SubProgressDisplay(
6262
subProgresses && subProgresses
6363
// Sort the subprocesses so that in progress ones are always at the bottom
6464
.sort((a, b) => a.status === ProgressStatus.IN_PROGRESS ? 1 : -1)
65-
// Limit the max number of subprocesses to 7. Too many doesn't look good and causes a wasm memory access error (yoga)
66-
.slice(Math.max(0, subProgresses.length - 7), subProgresses.length)
65+
// Limit the max number of subprocesses to 5. Too many doesn't look good and causes a wasm memory access error (yoga)
66+
.slice(Math.max(0, subProgresses.length - 5), subProgresses.length)
6767
.map((s, idx) =>
6868
s.status === ProgressStatus.IN_PROGRESS
6969
? <Spinner eventEmitter={emitter} eventType={eventType} key={idx} label={s.label} type="circleHalves"/>

src/utils/file-modification-calculator.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ function generateResourceInfo(type: string, requiredParameters?: string[]): Reso
526526
return ResourceInfo.fromResponseData({
527527
plugin: 'plugin',
528528
type,
529-
import: { requiredParameters }
529+
importAndDestroy: { requiredParameters }
530530
})
531531
}
532532

src/utils/file.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,9 @@ export class FileUtils {
3636
const resolvedPath = path.resolve(filePath);
3737
await fs.writeFile(resolvedPath, contents, 'utf8')
3838
}
39+
40+
static async createFolder(dirPath: string): Promise<void> {
41+
const resolvedPath = path.resolve(dirPath);
42+
await fs.mkdir(resolvedPath, { recursive: true });
43+
}
3944
}

test/orchestrator/import/import.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ vi.mock('../mocks/get-mock-resources.js', async () => {
1818
const orgSettings = super.getSettings();
1919
return {
2020
...orgSettings,
21-
import: {
21+
importAndDestroy: {
2222
requiredParameters: ['propA', 'propB'],
2323
refreshKeys: ['propA', 'propB', 'directory'],
2424
}
@@ -59,7 +59,7 @@ vi.mock('../mocks/get-mock-resources.js', async () => {
5959
parameterSettings: {
6060
add: { type: 'array' },
6161
},
62-
import: {
62+
importAndDestroy: {
6363
requiredParameters: ['requiredProp'],
6464
refreshKeys: ['add', 'global', 'requiredProp'],
6565
}
@@ -87,7 +87,7 @@ vi.mock('../mocks/get-mock-resources.js', async () => {
8787
parameterSettings: {
8888
add: { type: 'array' },
8989
},
90-
import: {
90+
importAndDestroy: {
9191
requiredParameters: ['alias'],
9292
refreshKeys: ['alias', 'value'],
9393
}

test/orchestrator/mocks/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { GetResourceInfoResponseData, ImportResponseData, InitializeResponseData
55
import { ResourcePlan } from '../../../src/entities/plan.js';
66
import { ResourceConfig } from '../../../src/entities/resource-config.js';
77
import { IPlugin } from '../../../src/plugins/plugin.js';
8-
import { getMockResources } from './get-mock-resources';
8+
import { getMockResources } from './get-mock-resources.js';
99

1010
export class MockPlugin implements IPlugin {
1111
name = 'default';

test/orchestrator/mocks/resource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class MockResource extends Resource<MockResourceConfig> {
2222
directory: { type: 'directory' },
2323
array: { type: 'array', canModify: true }
2424
},
25-
import: {
25+
importAndDestroy: {
2626
requiredParameters: ['propB'],
2727
refreshKeys: ['propB', 'directory'],
2828
}

0 commit comments

Comments
 (0)