Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "default",
"version": "0.11.0",
"version": "0.12.3",
"description": "",
"main": "dist/index.js",
"scripts": {
Expand All @@ -23,7 +23,7 @@
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
"semver": "^7.6.0",
"codify-plugin-lib": "1.0.132",
"codify-plugin-lib": "1.0.166",
"codify-schemas": "1.0.63",
"chalk": "^5.3.0",
"debug": "^4.3.4",
Expand All @@ -50,7 +50,7 @@
"@types/debug": "4.1.12",
"@types/plist": "^3.0.5",
"@types/lodash.isequal": "^4.5.8",
"codify-plugin-test": "0.0.47",
"codify-plugin-test": "0.0.49",
"commander": "^12.1.0",
"eslint": "^8.51.0",
"eslint-config-oclif": "^5",
Expand Down
3 changes: 2 additions & 1 deletion scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,15 @@ const mergedSchemas = [...schemasMap.entries()].map(([type, schema]) => {

delete resourceSchema.$id;
delete resourceSchema.$schema;
resourceSchema.description = `Resource type: "${type}" | ${resourceSchema.title}`;
delete resourceSchema.title;
delete resourceSchema.oneOf;
delete resourceSchema.properties.type;

if (schema) {
delete schema.$id;
delete schema.$schema;
delete schema.title;
delete schema.oneOf;
}

return mergeJsonSchemas([schema ?? {}, resourceSchema, { properties: { type: { const: type, type: 'string' } } }]);
Expand Down
5 changes: 4 additions & 1 deletion src/resources/android/android-studio-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
"$id": "https://www.codifycli.com/pgcli.json",
"title": "Android studios resource",
"type": "object",
"description": "Install Android Studios.",
"properties": {
"version": {
"type": "string",
"description": "Android studios version. Visit: https://developer.android.com/studio/releases for version info"
},
"directory": {

"type": "string",
"description": "The directory to install Android Studios into. Defaults to /Applications",
"default": "/Applications"
}
},
"additionalProperties": false
Expand Down
1 change: 1 addition & 0 deletions src/resources/asdf/asdf-global-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"$id": "https://www.codifycli.com/asdf-global-schema.json",
"title": "Asdf plugin global resource",
"type": "object",
"description": "Manage the asdf global version for a tool. An asdf-global or asdf-local resource must be specified before a tool installed with asdf is active in the shell.",
"properties": {
"plugin": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion src/resources/asdf/asdf-global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class AsdfGlobalResource extends Resource<AsdfGlobalConfig> {
id: 'asdf-global',
dependencies: ['asdf', 'asdf-plugin'],
schema: AsdfGlobalSchema,
import: {
importAndDestroy:{
requiredParameters: ['plugin'],
refreshKeys: ['plugin', 'version'],
defaultRefreshValues: {
Expand Down
1 change: 1 addition & 0 deletions src/resources/asdf/asdf-install-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"$id": "https://www.codifycli.com/asdf-install-schema.json",
"title": "Asdf plugin resource",
"type": "object",
"description": "Install a .tools-version file or directly install an asdf plugin + tool version.",
"properties": {
"plugin": {
"type": "string",
Expand Down
4 changes: 2 additions & 2 deletions src/resources/asdf/asdf-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export class AsdfInstallResource extends Resource<AsdfInstallConfig> {
dependencies: ['asdf'],
schema: AsdfInstallSchema,
parameterSettings: {
directory: { type: 'directory', inputTransformation: (input) => untildify(input) },
directory: { type: 'directory' },
versions: { type: 'array' }
},
import: {
importAndDestroy:{
requiredParameters: ['directory'],
refreshKeys: ['directory']
},
Expand Down
1 change: 1 addition & 0 deletions src/resources/asdf/asdf-local-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "https://www.codifycli.com/asdf-local-schema.json",
"title": "Asdf plugin local resource",
"description": "Manage the asdf local version for a tool. An asdf-global or asdf-local resource must be specified before a tool installed with asdf is active in the shell.",
"type": "object",
"properties": {
"plugin": {
Expand Down
12 changes: 3 additions & 9 deletions src/resources/asdf/asdf-local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,13 @@ export class AsdfLocalResource extends Resource<AsdfLocalConfig> {
dependencies: ['asdf', 'asdf-plugin'],
schema: AsdfLocalSchema,
parameterSettings: {
directory: {
inputTransformation: (input) => untildify(input),
},
directories: {
type: 'array',
canModify: true,
inputTransformation: (input) => input.map((i: any) => untildify(i)),
},
directory: { type: 'directory' },
directories: { type: 'array', canModify: true, itemType: 'directory' },
version: {
canModify: true,
}
},
import: {
importAndDestroy:{
requiredParameters: ['plugin', 'directory'],
refreshKeys: ['plugin', 'version', 'directory'],
defaultRefreshValues: {
Expand Down
1 change: 1 addition & 0 deletions src/resources/asdf/asdf-plugin-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "https://www.codifycli.com/asdf-plugin-schema.json",
"title": "Asdf plugin resource",
"description": "Installs a plugin and manages specific tool versions.",
"type": "object",
"properties": {
"plugin": {
Expand Down
1 change: 1 addition & 0 deletions src/resources/asdf/asdf-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"$id": "https://www.codifycli.com/asdf-schema.json",
"title": "Asdf resource",
"type": "object",
"description": "Installs asdf and manages asdf plugins. Use 'asdf-install' or 'asdf-plugin' to install the actual tool. Use 'asdf-global' or 'asdf-local' to activate the tool in the shell.",
"properties": {
"plugins": {
"type": "array",
Expand Down
1 change: 1 addition & 0 deletions src/resources/aws-cli/cli/aws-cli-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"$id": "https://www.codifycli.com/aws-cli.json",
"title": "Aws-CLI resource",
"type": "object",
"description": "Installs aws-cli.",
"properties": {},
"additionalProperties": false
}
1 change: 1 addition & 0 deletions src/resources/aws-cli/profile/aws-profile-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"$id": "https://www.codifycli.com/aws-profile.json",
"title": "Aws-CLI configure resource",
"type": "object",
"description": "Configures AWS profiles.",
"properties": {
"profile": {
"type": "string",
Expand Down
22 changes: 13 additions & 9 deletions src/resources/aws-cli/profile/aws-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import path from 'node:path';

import { SpawnStatus, codifySpawn } from '../../../utils/codify-spawn.js';
import Schema from './aws-profile-schema.json'
import { CSVCredentialsParameter } from './csv-credentials-parameter.js';
import { CSVCredentialsTransformation } from './csv-credentials-transformation.js';

export interface AwsProfileConfig extends StringIndexedObject {
awsAccessKeyId: string;
Expand All @@ -37,24 +37,28 @@ export class AwsProfileResource extends Resource<AwsProfileConfig> {
parameterSettings: {
awsAccessKeyId: { canModify: true },
awsSecretAccessKey: { canModify: true },
csvCredentials: { type: 'directory', setting: true }, // Type setting means it won't be included in the plan calculation
output: { default: 'json', canModify: true },
profile: { default: 'default', canModify: true },
metadataServiceNumAttempts: { canModify: true },
metadataServiceTimeout: { canModify: true },
},
inputTransformation: CSVCredentialsParameter.transform,
import: {
transformation: CSVCredentialsTransformation,
importAndDestroy:{
refreshKeys: ['output', 'profile', 'awsAccessKeyId', 'awsSecretAccessKey', 'region'],
requiredParameters: ['profile']
},
allowMultiple: {
identifyingParameters: ['profile']
}
};
}

override async validate(parameters: Partial<AwsProfileConfig>): Promise<void> {
if (parameters.csvCredentials
&& (parameters.awsAccessKeyId || parameters.awsSecretAccessKey)) {
throw new Error('Csv credentials cannot be added together with awsAccessKeyId or awsSecretAccessKey')
}
// if (parameters.csvCredentials
// && (parameters.awsAccessKeyId || parameters.awsSecretAccessKey)) {
// throw new Error('Csv credentials cannot be added together with awsAccessKeyId or awsSecretAccessKey')
// }
}

override async refresh(parameters: Partial<AwsProfileConfig>): Promise<Partial<AwsProfileConfig> | null> {
Expand Down Expand Up @@ -83,11 +87,11 @@ export class AwsProfileResource extends Resource<AwsProfileConfig> {
profile,
};

if (parameters.region) {
if (parameters.region !== undefined) {
result.region = await this.getAwsConfigureValueOrNull('region', profile);
}

if (parameters.output) {
if (parameters.output !== undefined) {
result.output = await this.getAwsConfigureValueOrNull('output', profile);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { type InputTransformation } from 'codify-plugin-lib';
import * as fsSync from 'node:fs';
import * as fs from 'node:fs/promises';
import path from 'node:path';

import { untildify } from '../../../utils/untildify.js';
import { AwsProfileConfig } from './aws-profile.js';

export const CSVCredentialsParameter = {

async transform(input: Partial<AwsProfileConfig>): Promise<Partial<AwsProfileConfig>> {
export const CSVCredentialsTransformation: InputTransformation = {
async to(input: Partial<AwsProfileConfig>): Promise<Partial<AwsProfileConfig>> {
if (!input.csvCredentials) {
return input;
}
Expand All @@ -30,13 +30,19 @@ export const CSVCredentialsParameter = {
throw new Error(`File ${csvPath} is not properly formatted. It must be a csv in the format: awsAccessKeyId, awsSecretAccessKey`);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { csvCredentials: _, awsAccessKeyId: __, awsSecretAccessKey: ___, ...restOfParameters } = input;

return {
...restOfParameters,
...input,
awsAccessKeyId,
awsSecretAccessKey,
};
},

from(output: Partial<AwsProfileConfig>): Partial<AwsProfileConfig> {
if (output.csvCredentials) {
delete output.awsAccessKeyId;
delete output.awsSecretAccessKey;
}

return output;
}
};
1 change: 1 addition & 0 deletions src/resources/git/clone/git-clone-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "https://www.codifycli.com/git-clone.json",
"title": "Git-clone resource",
"description": "Git clone a repository. Choose either to specify the exact directory to clone into or the parent directory (it deduces the folder name using the repository name).",
"type": "object",
"properties": {
"repository": {
Expand Down
26 changes: 22 additions & 4 deletions src/resources/git/clone/git-clone.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { CreatePlan, DestroyPlan, getPty, Resource, ResourceSettings } from 'codify-plugin-lib';
import { CreatePlan, DestroyPlan, Resource, ResourceSettings, getPty } from 'codify-plugin-lib';
import { ResourceConfig } from 'codify-schemas';
import path from 'node:path';

import { codifySpawn } from '../../../utils/codify-spawn.js';
import { FileUtils } from '../../../utils/file-utils.js';
import { untildify } from '../../../utils/untildify.js';
import Schema from './git-clone-schema.json';


Expand All @@ -23,11 +22,29 @@ export class GitCloneResource extends Resource<GitCloneConfig> {
parameterSettings: {
parentDirectory: { type: 'directory' },
directory: { type: 'directory' },
autoVerifySSH: { type: 'setting', default: true },
autoVerifySSH: { type: 'boolean', default: true, setting: true },
},
import: {
importAndDestroy:{
requiredParameters: ['directory']
},
allowMultiple: {
matcher: (desired, current) => {
const desiredPath = desired.parentDirectory
? path.resolve(desired.parentDirectory, this.extractBasename(desired.repository!)!)
: path.resolve(desired.directory!);

const currentPath = current.parentDirectory
? path.resolve(current.parentDirectory, this.extractBasename(current.repository!)!)
: path.resolve(current.directory!);

const isNotCaseSensitive = process.platform === 'darwin';
if (isNotCaseSensitive) {
return desiredPath.toLowerCase() === currentPath.toLowerCase()
}

return desiredPath === currentPath;
}
},
dependencies: [
'ssh-key',
'ssh-add-key',
Expand Down Expand Up @@ -99,6 +116,7 @@ export class GitCloneResource extends Resource<GitCloneConfig> {

override async destroy(plan: DestroyPlan<GitCloneConfig>): Promise<void> {
// Do nothing here. We don't want to destroy a user's repository.
// TODO: change this to skip the destroy only if the user's repo has pending changes (check via git)
throw new Error(`The git-clone resource is not designed to delete folders.
Please delete ${plan.currentConfig.directory ?? (plan.currentConfig.parentDirectory! + this.extractBasename(plan.currentConfig.repository))} manually and re-apply`);
}
Expand Down
1 change: 0 additions & 1 deletion src/resources/git/git/git-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export class GitResource extends Resource<GitConfig> {
email: { type: 'stateful', definition: new GitEmailParameter(), },
username: { type: 'stateful', definition: new GitNameParameter() },
},

}
}

Expand Down
1 change: 1 addition & 0 deletions src/resources/git/git/git-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "https://www.codifycli.com/git.json",
"title": "Git resource",
"description": "Set and manage global git settings (email and username)",
"type": "object",
"properties": {
"email": {
Expand Down
1 change: 1 addition & 0 deletions src/resources/git/lfs/git-lfs-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "https://www.codifycli.com/git-lfs.json",
"title": "Git-LFS resource",
"description": "Installs git-lfs. This resource will automatically activate git-lfs as well.",
"type": "object",
"properties": {},
"additionalProperties": false
Expand Down
4 changes: 2 additions & 2 deletions src/resources/homebrew/formulae-parameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export class FormulaeParameter extends StatefulParameter<HomebrewConfig, string[
}
}

override async refresh(): Promise<null | string[]> {
override async refresh(desired: unknown, config: Partial<HomebrewConfig>): Promise<null | string[]> {
const $ = getPty();
const formulaeQuery = await $.spawnSafe('brew list --formula -1')
const formulaeQuery = await $.spawnSafe(`brew list --formula -1 ${config.onlyPlanUserInstalled ? '--installed-on-request' : ''}`)

if (formulaeQuery.status === SpawnStatus.SUCCESS && formulaeQuery.data !== null && formulaeQuery.data !== undefined) {
return formulaeQuery.data
Expand Down
5 changes: 5 additions & 0 deletions src/resources/homebrew/homebrew-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "https://www.codifycli.com/homebrew-main.json",
"title": "Homebrew plugin main resource",
"description": "Install homebrew and manages formulae, casks and taps.",
"type": "object",
"properties": {
"formulae": {
Expand All @@ -28,6 +29,10 @@
"skipAlreadyInstalledCasks": {
"type": "boolean",
"description": "Skips installing an casks which has already been installed externally. This prevents homebrew from conflicting with the existing install. Defaults to true."
},
"onlyPlanUserInstalled": {
"type": "boolean",
"description": "Only consider packages that the user has explicitly specified in the plan and ignore any dependent packages"
}
},
"additionalProperties": false
Expand Down
Loading
Loading