Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build decofile.json #870

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion daemon/workers/denoRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const buildPermissionsArgs = (
for (const [key, value] of Object.entries(perm)) {
if (value === "inherit") {
permCache[key] ??= Deno.permissions.querySync({
name: key as keyof Deno.PermissionOptionsObject,
name: key as Deno.PermissionDescriptor["name"],
}).state;
const access = permCache[key];
access === "granted" && args.push(`--allow-${key}`);
Expand Down
3 changes: 2 additions & 1 deletion dev/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"name": "@deco/dev",
"version": "1.107.2",
"exports": {
".": "./mod.ts",
"./tailwind": "./tailwind.ts"
},
"imports": {
"@deco/deco": "jsr:@deco/deco@^1.101.22-alpha.1",
"@deco/deco": "jsr:@deco/deco@^1.107.2-beta.1",
"@std/fmt": "jsr:@std/fmt@^1.0.0",
"@std/fs": "jsr:@std/fs@^1.0.4",
"@std/path": "jsr:@std/path@^1.0.2"
Expand Down
20 changes: 20 additions & 0 deletions dev/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { newFsFolderProvider } from "@deco/deco/engine";
import { exists } from "@std/fs/exists";
import { join } from "@std/path";
import { build as tailwindBuild } from "./tailwind.ts";

const DECO_FOLDER = ".deco";
export const build = async (): Promise<void> => {
await tailwindBuild();
const decoFolder = join(Deno.cwd(), DECO_FOLDER);
if (
Deno.args.includes("build") && await exists(decoFolder)
) {
const provider = newFsFolderProvider(join(DECO_FOLDER, "blocks"));
const decofile = await provider.state();
await Deno.writeTextFile(
join(decoFolder, "decofile.json"),
JSON.stringify(decofile, null, 2),
);
}
};
15 changes: 12 additions & 3 deletions engine/decofile/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,15 @@ const DECOFILE_RELEASE_ENV_VAR = "DECO_RELEASE";

// if decofile does not exists but blocks exists so it should be lazy
const BLOCKS_FOLDER = join(Deno.cwd(), ".deco", "blocks");
const BUILT_DECOFILE_PATH = join(Deno.cwd(), ".deco", "decofile.json");
const blocksFolderExistsPromise = exists(BLOCKS_FOLDER, {
isDirectory: true,
isReadable: true,
});
const builtDecofileExistsPromise = exists(BUILT_DECOFILE_PATH, {
isFile: true,
isReadable: true,
});
const DECOFILE_PATH_FROM_ENV = Deno.env.get(DECOFILE_RELEASE_ENV_VAR);

/**
Expand All @@ -110,9 +115,13 @@ export const getProvider = async (
return newFsProvider();
}

const endpoint = await blocksFolderExistsPromise
? `folder://${BLOCKS_FOLDER}`
: DECOFILE_PATH_FROM_ENV;
let endpoint = DECOFILE_PATH_FROM_ENV;
if (await builtDecofileExistsPromise) {
endpoint = `file://${BUILT_DECOFILE_PATH}`;
} else if (await blocksFolderExistsPromise) {
endpoint = `folder://${BLOCKS_FOLDER}`;
}

if (endpoint) {
console.info(
colors.brightCyan(
Expand Down
2 changes: 2 additions & 0 deletions engine/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export { newFsFolderProvider } from "./decofile/fsFolder.ts";
export { ImportMapBuilder } from "./importmap/builder.ts";
export type { ImportMapResolver } from "./importmap/builder.ts";
export type { ParsedSource } from "./schema/deps.ts";
export { initLoader, parsePath } from "./schema/parser.ts";

18 changes: 18 additions & 0 deletions scripts/codemod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,12 +712,30 @@ export const runCodeMod = async (context?: CodeModContext): Promise<void> => {
return pinDecoVersion.apply(txt, ctx);
},
},
{
options: {
match: [/.gitignore$/],
},
apply: (txt) => {
if (txt.content.includes(".deco/decofile.json")) {
return txt;
}
return {
content: `${txt.content}\n.deco/decofile.json\n`,
};
},
},
{
options: {
match: [/dev.ts$/],
},
apply: (txt) => {
if (txt.content.includes("@deco/dev/tailwind")) {
return {
content: txt.content.replace("@deco/dev/tailwind", "@deco/dev"),
};
}
if (txt.content.includes("@deco/dev")) {
return txt;
}
return {
Expand Down
Loading