Skip to content

Commit ec0f066

Browse files
committed
Improved naming in plugin resolver + misc things
1 parent 7403de5 commit ec0f066

File tree

6 files changed

+28
-24
lines changed

6 files changed

+28
-24
lines changed

.eslintrc.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@
99
"warn",
1010
"always"
1111
],
12-
"perfectionist/sort-classes": [
13-
"off"
14-
],
12+
"perfectionist/sort-classes": "off",
13+
"perfectionist/sort-interfaces": "off",
14+
"perfectionist/sort-enums": "off",
15+
"perfectionist/sort-objects": "off",
16+
"perfectionist/sort-object-types": "off",
17+
"unicorn/no-array-reduce": "off",
18+
"unicorn/no-array-for-each": "off",
19+
"unicorn/prefer-object-from-entries": "off",
20+
"unicorn/prefer-type-error": "off",
1521
"quotes": [
1622
"error",
1723
"single"

codify.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
"20.15"
1313
]
1414
},
15-
{
16-
"type": "android-studio",
17-
"version": "2023.3.1"
18-
},
1915
{
2016
"type": "homebrew",
2117
"formulae": [

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@
110110
},
111111
"update": {
112112
"s3": {
113-
"host": "https://releases-dev.codifycli.com",
114-
"bucket": "cli-releases-dev"
113+
"host": "https://releases.codifycli.com",
114+
"bucket": "cli-releases"
115115
}
116116
},
117117
"warn-if-update-available": {

src/plugins/plugin-manager.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { ResourceOperation, ValidateResponseData } from 'codify-schemas';
22

3+
import { InternalError } from '../common/errors.js';
34
import { Plan, ResourcePlan } from '../entities/plan.js';
5+
import { PlanRequest } from '../entities/plan-request.js';
46
import { Project } from '../entities/project.js';
5-
import { ResourceConfig } from '../entities/resource-config.js';
67
import { SubProcessName, ctx } from '../events/context.js';
78
import { prettyFormatResourcePlan } from '../ui/plan-pretty-printer.js';
89
import { groupBy } from '../utils/index.js';
910
import { Plugin } from './plugin.js';
1011
import { PluginResolver } from './resolver.js';
11-
import { InternalError } from '../common/errors.js';
12-
import { PlanRequest } from '../entities/plan-request.js';
1312

1413
type PluginName = string;
1514
type ResourceTypeId = string;
@@ -96,10 +95,10 @@ export class PluginManager {
9695
};
9796

9897
const configPlugins = await Promise.all(Object.entries(pluginDefinitions).map(([name, version]) =>
99-
PluginResolver.resolve(name, version)
98+
PluginResolver.getOrDownload(name, version)
10099
));
101100

102-
const existingPlugins = await PluginResolver.resolveExisting(Object.keys(pluginDefinitions));
101+
const existingPlugins = await PluginResolver.getAllExisting(Object.keys(pluginDefinitions));
103102

104103
return [...existingPlugins, ...configPlugins];
105104
}

src/plugins/resolver.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,31 @@ const PLUGIN_CACHE_DIR = '/Library/Caches/codify/plugins'
1212

1313
export class PluginResolver {
1414

15-
static async resolve(name: string, version: string): Promise<Plugin> {
16-
await PluginResolver.checkAndCreateCacheDirIfNotExists()
15+
static async getOrDownload(name: string, versionOrPath?: string): Promise<Plugin> {
16+
await PluginResolver.createPluginDirIfNotExists()
17+
18+
// Default versions to latest
19+
versionOrPath = versionOrPath ?? 'latest';
1720

1821
let directoryStat;
1922
try {
20-
directoryStat = await fs.stat(version);
23+
directoryStat = await fs.stat(versionOrPath);
2124
} catch {
2225
}
2326

2427
// For easier development. A direct js file can be specified for the plugin.
2528
if (directoryStat && directoryStat.isFile()) {
26-
return PluginResolver.resolvePluginFs(name, version)
29+
return PluginResolver.getFromFileSystem(name, versionOrPath)
2730
}
2831

2932
if (name === 'default') {
30-
return PluginResolver.resolvePluginDefault(name, version)
33+
return PluginResolver.downloadDefaultPlugin(name, versionOrPath)
3134
}
3235

3336
throw new Error('Non-default plugins are not currently supported');
3437
}
3538

36-
static async resolveExisting(exclude: string[]): Promise<Plugin[]> {
39+
static async getAllExisting(exclude: string[]): Promise<Plugin[]> {
3740
let files;
3841
try {
3942
files = await fs.readdir(PLUGIN_CACHE_DIR);
@@ -57,7 +60,7 @@ export class PluginResolver {
5760
}
5861
}
5962

60-
private static async resolvePluginFs(name: string, filePath: string): Promise<Plugin> {
63+
private static async getFromFileSystem(name: string, filePath: string): Promise<Plugin> {
6164
const fileExtension = filePath.slice(filePath.lastIndexOf('.'))
6265
if (fileExtension !== '.js' && fileExtension !== '.ts') {
6366
throw new Error(`Only .js and .ts plugins are support currently. Can't resolve ${filePath}`);
@@ -70,7 +73,7 @@ export class PluginResolver {
7073
)
7174
}
7275

73-
private static async resolvePluginDefault(name: string, version: string): Promise<Plugin> {
76+
private static async downloadDefaultPlugin(name: string, version: string): Promise<Plugin> {
7477
const { body } = await fetch(DEFAULT_PLUGIN_URL)
7578
if (!body) {
7679
throw new Error('Un-able to fetch the default plugin (body not found). Exiting');
@@ -89,7 +92,7 @@ export class PluginResolver {
8992
)
9093
}
9194

92-
private static async checkAndCreateCacheDirIfNotExists() {
95+
private static async createPluginDirIfNotExists() {
9396
let pluginDirStat = null;
9497
try {
9598
pluginDirStat = await fs.stat(PluginResolver.getCacheDir())

test/integration/resolver.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('Plugin resolver integration test', () => {
1313
})
1414

1515
it('resolves the default plugin', async () => {
16-
const plugin = await PluginResolver.resolve('default')
16+
const plugin = await PluginResolver.getOrDownload('default')
1717

1818
expect(fs.existsSync('/Library/Caches/codify/plugins/default.js')).to.be.true;
1919
})

0 commit comments

Comments
 (0)