Skip to content

Commit 2337888

Browse files
committed
feat: Switched to using identifying parameters
1 parent c5c3e30 commit 2337888

File tree

9 files changed

+65
-30
lines changed

9 files changed

+65
-30
lines changed

README.md

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $ npm install -g codify
1818
$ codify COMMAND
1919
running command...
2020
$ codify (--version)
21-
codify/0.5.1 darwin-arm64 node-v20.15.1
21+
codify/0.6.0 darwin-arm64 node-v20.15.1
2222
$ codify --help [COMMAND]
2323
USAGE
2424
$ codify COMMAND
@@ -62,7 +62,7 @@ EXAMPLES
6262
$ codify apply --path ~
6363
```
6464

65-
_See code: [src/commands/apply/index.ts](https://github.com/kevinwang5658/codify/blob/v0.5.1/src/commands/apply/index.ts)_
65+
_See code: [src/commands/apply/index.ts](https://github.com/kevinwang5658/codify/blob/v0.6.0/src/commands/apply/index.ts)_
6666

6767
## `codify destroy`
6868

@@ -89,7 +89,7 @@ EXAMPLES
8989
$ codify destroy homebrew nvm
9090
```
9191

92-
_See code: [src/commands/destroy.ts](https://github.com/kevinwang5658/codify/blob/v0.5.1/src/commands/destroy.ts)_
92+
_See code: [src/commands/destroy.ts](https://github.com/kevinwang5658/codify/blob/v0.6.0/src/commands/destroy.ts)_
9393

9494
## `codify help [COMMAND]`
9595

@@ -113,7 +113,7 @@ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.2.1
113113

114114
## `codify import`
115115

116-
Generate codify configs from existing installations
116+
Generate codify configs from already installed packages. Use a list of space separated arguments to specify the resource types to import. Leave blank to import all resource in an existing *.codify.json file.
117117

118118
```
119119
USAGE
@@ -130,13 +130,40 @@ GLOBAL FLAGS
130130
--json Format output as json.
131131
132132
DESCRIPTION
133-
Generate codify configs from existing installations
133+
Generate codify configs from already installed packages. Use a list of space separated arguments to specify the
134+
resource types to import. Leave blank to import all resource in an existing *.codify.json file.
135+
136+
Modes:
137+
1. No args: if no args are specified and an *.codify.json already exists. Then codify will update the existing file
138+
with any new changes to the resources specified in the file/files.
139+
140+
Command: codify import
141+
142+
2. With args: specify specific resources to import using arguments. Wild card matching is supported using '*' and ?
143+
(Note: in zsh * expands to the current dir and needs to be escaped using \* or '*'). A prompt will be shown if more
144+
information is required to complete the import.
145+
146+
Example: codify import nvm asdf\*, codify import \* (for importing all supported resources)
147+
148+
The results can then be saved:
149+
a. To an existing *.codify.json file
150+
b. To a new file
151+
c. Or only printed to console
152+
153+
Codify will try to smartly insert new configs by following existing spacing and formatting.
154+
134155
135156
EXAMPLES
136-
$ codify import homebrew nvm
157+
$ codify import homebrew nvm asdf\*
158+
159+
$ codify import
160+
161+
$ codify import git-clone --path ../my/other/folder
162+
163+
$ codify import \*
137164
```
138165

139-
_See code: [src/commands/import.ts](https://github.com/kevinwang5658/codify/blob/v0.5.1/src/commands/import.ts)_
166+
_See code: [src/commands/import.ts](https://github.com/kevinwang5658/codify/blob/v0.6.0/src/commands/import.ts)_
140167

141168
## `codify plan`
142169

@@ -164,7 +191,7 @@ EXAMPLES
164191
$ codify plan
165192
```
166193

167-
_See code: [src/commands/plan/index.ts](https://github.com/kevinwang5658/codify/blob/v0.5.1/src/commands/plan/index.ts)_
194+
_See code: [src/commands/plan/index.ts](https://github.com/kevinwang5658/codify/blob/v0.6.0/src/commands/plan/index.ts)_
168195

169196
## `codify update [CHANNEL]`
170197

package-lock.json

Lines changed: 10 additions & 10 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
@@ -4,7 +4,7 @@
44
"codify": "./bin/run.js"
55
},
66
"dependencies": {
7-
"@codifycli/ink-form": "0.0.3",
7+
"@codifycli/ink-form": "0.0.5",
88
"@homebridge/node-pty-prebuilt-multiarch": "^0.12.0-beta.5",
99
"@inkjs/ui": "^2",
1010
"@oclif/core": "^4.0.8",
@@ -13,7 +13,7 @@
1313
"ajv": "^8.12.0",
1414
"ajv-formats": "^3.0.1",
1515
"chalk": "^5.3.0",
16-
"codify-schemas": "^1.0.69",
16+
"codify-schemas": "^1.0.70",
1717
"debug": "^4.3.4",
1818
"detect-indent": "^7.0.1",
1919
"diff": "^7.0.0",
@@ -117,7 +117,7 @@
117117
"start:dev": "./bin/dev.js",
118118
"start:vm": "npm run build && npm run pack:macos && npm run start:vm"
119119
},
120-
"version": "0.5.1",
120+
"version": "0.6.0",
121121
"bugs": "https://github.com/kevinwang5658/codify/issues",
122122
"keywords": [
123123
"oclif"

src/commands/import.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ The results can then be saved:
2626
2727
Codify will try to smartly insert new configs by following existing spacing and formatting.
2828
`
29-
static override args = ''
3029

3130
static override examples = [
3231
'<%= config.bin %> <%= command.id %> homebrew nvm asdf\\*',

src/entities/resource-config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,12 @@ export class ResourceConfig implements ConfigBlock {
102102
throw new Error(`checkResourceInfo specified but no resource info provided (${this.type}) (other: ${other.type})`)
103103
}
104104

105-
const thisRequiredKeys = new Set(this.resourceInfo.getRequiredParameters().map((p) => p.name));
106-
const otherRequiredKeys = new Set(other.resourceInfo.getRequiredParameters().map((p) => p.name));
105+
if (!this.resourceInfo.allowMultiple || !other.resourceInfo.allowMultiple) {
106+
return true;
107+
}
108+
109+
const thisRequiredKeys = new Set(this.resourceInfo.allowMultiple.identifyingParameters);
110+
const otherRequiredKeys = new Set(other.resourceInfo.allowMultiple.identifyingParameters);
107111

108112
const thisRequiredParameters = Object.fromEntries(Object.entries(this.parameters)
109113
.filter(([k]) => thisRequiredKeys.has(k))

src/entities/resource-info.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export class ResourceInfo implements GetResourceInfoResponseData {
2020
requiredParameters: null | string[];
2121
} | undefined;
2222

23+
allowMultiple?: {
24+
identifyingParameters: string[];
25+
};
26+
2327
private parametersCache?: ParameterInfo[];
2428

2529
private constructor() {}

src/plugins/plugin-manager.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
GetResourceInfoResponseData,
32
ImportResponseData,
43
ResourceJson,
54
ValidateResponseData,

src/ui/components/default-component.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ export function DefaultComponent(props: {
4545
}
4646
{
4747
renderStatus === RenderStatus.PROGRESS && (
48-
<ProgressDisplay emitter={spinnerEmitter} eventType="data"/>
48+
<Box/>
49+
// <ProgressDisplay emitter={spinnerEmitter} eventType="data"/>
4950
)
5051
}
5152
{
@@ -96,9 +97,10 @@ export function DefaultComponent(props: {
9697
}
9798
{
9899
renderStatus === RenderStatus.DISPLAY_IMPORT_RESULT && (
99-
<Static items={[renderData as { importResult: ImportResult; showConfigs: boolean }]}>{
100-
(renderData, idx) => <ImportResultComponent importResult={renderData.importResult} key={idx} showConfigs={renderData.showConfigs} />
101-
}</Static>
100+
<Box/>
101+
// <Static items={[renderData as { importResult: ImportResult; showConfigs: boolean }]}>{
102+
// (renderData, idx) => <ImportResultComponent importResult={renderData.importResult} key={idx} showConfigs={renderData.showConfigs} />
103+
// }</Static>
102104
)
103105
}
104106
{

src/utils/file-modification-calculator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export class FileModificationCalculator {
227227
const source = sourceMap.lookup(`/${sourceIndex}/${key}`);
228228
if ((Array.isArray(value) || typeof value === 'object') && source && source.value.line === source.valueEnd.line) {
229229
const { value, valueEnd } = parsedSourceMap.lookup(`#/${key}`)!
230-
content = this.splice(content, value.position, valueEnd.position - value.position, JSON.stringify(parsedContent[key]))
230+
content = this.splice(content, value.position, valueEnd.position - value.position, JSON.stringify(parsedContent[key], null, ' '))
231231
}
232232
}
233233

0 commit comments

Comments
 (0)