Skip to content

Commit

Permalink
Move to cache/modules & also create files in createNewProject
Browse files Browse the repository at this point in the history
  • Loading branch information
LorisSigrist committed Jun 18, 2024
1 parent 7a47ab0 commit 4ec9097
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
9 changes: 6 additions & 3 deletions inlang/source-code/sdk/src/createNewProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ export async function createNewProject(args: {
if (await pathExists(args.projectPath, nodeishFs)) {
throw new Error(`projectPath already exists, received "${args.projectPath}"`)
}
await nodeishFs.mkdir(args.projectPath, { recursive: true })

const settingsText = JSON.stringify(args.projectSettings ?? defaultProjectSettings, undefined, 2)

await nodeishFs.writeFile(`${args.projectPath}/settings.json`, settingsText)
await nodeishFs.mkdir(args.projectPath, { recursive: true })
await Promise.all([
nodeishFs.writeFile(`${args.projectPath}/settings.json`, settingsText),
nodeishFs.writeFile(`${args.projectPath}/.gitignore`, "cache"),
nodeishFs.mkdir(`${args.projectPath}/cache/modules`, { recursive: true }),
])
}
8 changes: 4 additions & 4 deletions inlang/source-code/sdk/src/migrations/maybeAddModuleCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export async function maybeAddModuleCache(args: {
// This is how paths are handled in the other migrations.
// Is this reliable on windows?
const gitignorePath = args.projectPath + "/.gitignore"
const cachePath = args.projectPath + "/cache"
const moduleCache = args.projectPath + "/cache/modules/"

const gitignoreExists = await fileExists(gitignorePath, args.repo.nodeishFs)
const cacheExists = await directoryExists(cachePath, args.repo.nodeishFs)
const moduleCacheExists = await directoryExists(moduleCache, args.repo.nodeishFs)

if (gitignoreExists) {
// non-destructively add any missing ignores
Expand All @@ -31,8 +31,8 @@ export async function maybeAddModuleCache(args: {
await args.repo.nodeishFs.writeFile(gitignorePath, EXPECTED_IGNORES.join("\n"))
}

if (!cacheExists) {
await args.repo.nodeishFs.mkdir(cachePath, { recursive: true })
if (!moduleCacheExists) {
await args.repo.nodeishFs.mkdir(moduleCache, { recursive: true })
}
}

Expand Down
4 changes: 2 additions & 2 deletions inlang/source-code/sdk/src/resolve-modules/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async function readModuleFromCache(
readFile: NodeishFilesystemSubset["readFile"]
): Promise<Result<string, Error>> {
const moduleHash = escape(moduleURI)
const filePath = projectPath + `/cache/${moduleHash}.js`
const filePath = projectPath + `/cache/modules/${moduleHash}.js`

return await tryCatch(async () => await readFile(filePath, { encoding: "utf-8" }))
}
Expand All @@ -26,7 +26,7 @@ async function writeModuleToCache(
writeFile: NodeishFilesystemSubset["writeFile"]
): Promise<void> {
const moduleHash = escape(moduleURI)
const filePath = projectPath + `/cache/${moduleHash}.js`
const filePath = projectPath + `/cache/modules/${moduleHash}.js`
await writeFile(filePath, moduleContent)
}

Expand Down

0 comments on commit 4ec9097

Please sign in to comment.