Skip to content

Commit

Permalink
Fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
etienne-dldc committed Dec 13, 2024
1 parent e43032a commit fd698ff
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/cleanupFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { walk } from "@std/fs";

export async function cleanupFiles(localPath: string, files: string[]) {
const allFiles = await Array.fromAsync(
walk(localPath, { includeDirs: false })
walk(localPath, { includeDirs: false }),
);
const diff = allFiles.filter((f) => !files.includes(f.path));
console.log(`TODO: Cleanup ${diff.length} files`);
Expand Down
5 changes: 3 additions & 2 deletions src/cloneRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ export interface TRepo {
export async function cloneRepo(
logger: TLogger,
repo: string,
branch: string
branch: string,
): Promise<TRepo> {
const path = await Deno.makeTempDir();
logger.log(`Cloning ${repo} on branch ${branch}`);

const lines =
await $`git clone --branch ${branch} --single-branch --depth 1 ${repo} ${path}`.lines();
await $`git clone --branch ${branch} --single-branch --depth 1 ${repo} ${path}`
.lines();

lines.forEach((line) => logger.log(line));
return { path };
Expand Down
2 changes: 1 addition & 1 deletion src/copyFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export async function copyFiles(
repoPath: string,
remotePath: string,
localPath: string,
files: string[]
files: string[],
): Promise<void> {
const baseFolder = resolve(repoPath, remotePath);
for (const file of files) {
Expand Down
16 changes: 8 additions & 8 deletions src/getInstalledVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ const ListSchema = v.array(
v.string(),
v.object({
version: v.string(),
})
)
}),
),
),
devDependencies: v.optional(
v.record(
v.string(),
v.object({
version: v.string(),
})
)
}),
),
),
})
}),
);

export async function getInstalledVersion(
name: string
name: string,
): Promise<string | null> {
const currentVersion = await $`pnpm list --depth 0 --json ${name}`.json();
const result = v.parse(ListSchema, currentVersion);
if (result.length === 0) {
return null;
}
const deps =
result[0].dependencies?.[name] ?? result[0].devDependencies?.[name];
const deps = result[0].dependencies?.[name] ??
result[0].devDependencies?.[name];
if (!deps) {
return null;
}
Expand Down
6 changes: 3 additions & 3 deletions src/installDeps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import $ from "@david/dax";
import { parseRange, parse as parseVersion, satisfies } from "@std/semver";
import { parse as parseVersion, parseRange, satisfies } from "@std/semver";
import { getInstalledVersion } from "./getInstalledVersion.ts";
import { readPackageJson } from "./readPackageJson.ts";

Expand All @@ -8,7 +8,7 @@ export async function installDeps(deps: Record<string, string>): Promise<void> {
const packagesToInstall: string[] = [];
for (const [name, requiredRange] of Object.entries(deps)) {
const isInstalled = Boolean(
currentPkg.dependencies?.[name] || currentPkg.devDependencies?.[name]
currentPkg.dependencies?.[name] || currentPkg.devDependencies?.[name],
);
if (!isInstalled) {
// Install the dependency
Expand All @@ -24,7 +24,7 @@ export async function installDeps(deps: Record<string, string>): Promise<void> {
}
if (!satisfies(parseVersion(currentVersion), parseRange(requiredRange))) {
console.error(
`Version mismatch for ${name}: required ${requiredRange}, found ${currentVersion}`
`Version mismatch for ${name}: required ${requiredRange}, found ${currentVersion}`,
);
continue;
}
Expand Down
8 changes: 4 additions & 4 deletions src/resolveDeps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function resolveDeps(
repoPath: string,
remotePath: string,
baseFiles: string[],
remotePkg: TPackageJson
remotePkg: TPackageJson,
): Promise<TResolvedDeps> {
const baseFolder = resolve(repoPath, remotePath);
const project = new Project();
Expand Down Expand Up @@ -77,7 +77,7 @@ export async function resolveDeps(
return;
}
throw new Error(
`Could not resolve module ${moduleSpecifier} in ${directory}`
`Could not resolve module ${moduleSpecifier} in ${directory}`,
);
}
}
Expand All @@ -88,7 +88,7 @@ export async function resolveDeps(
*/
async function resolveNodeFile(
path: string,
allowDirectory = true
allowDirectory = true,
): Promise<string | null> {
if (await exists(path, { isFile: true })) {
return path;
Expand All @@ -111,7 +111,7 @@ async function resolveNodeFile(

function findDependency(
deps: Record<string, string>,
moduleSpecifier: string
moduleSpecifier: string,
): { name: string; version: string } | null {
for (const [mode, version] of Object.entries(deps)) {
if (mode === moduleSpecifier) {
Expand Down
4 changes: 2 additions & 2 deletions src/resolveFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { resolve } from "@std/path";
export async function resolveFiles(
repoPath: string,
remotePath: string,
patterns: string[]
patterns: string[],
): Promise<string[]> {
const baseFolder = resolve(repoPath, remotePath);
const files = new Set<string>();

for (const pattern of patterns) {
const patFiles = await Array.fromAsync(
expandGlob(pattern, { root: baseFolder, includeDirs: false })
expandGlob(pattern, { root: baseFolder, includeDirs: false }),
);
for await (const file of patFiles) {
files.add(file.path);
Expand Down
2 changes: 1 addition & 1 deletion src/runJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function runJob(job: TConfigJob): Promise<void> {
cloned.path,
remotePath,
baseFiles,
remotePkg
remotePkg,
);
await copyFiles(cloned.path, remotePath, localPath, allDeps.files);
await installDeps(allDeps.dependencies);
Expand Down

0 comments on commit fd698ff

Please sign in to comment.