Skip to content

Commit

Permalink
Add build decofile and decofile priority
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia committed Nov 25, 2024
1 parent 400e1f7 commit b17aecf
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 10 deletions.
4 changes: 2 additions & 2 deletions dev/deno.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@deco/dev",
"version": "1.107.0",
"version": "1.107.2-beta.1",
"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
24 changes: 19 additions & 5 deletions dev/mod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import { build } from "./tailwind.ts";
await build();
import { newFsFolderProvider } from "@deco/deco/engine";
import { exists } from "@std/fs/exists";
import { join } from "@std/path";
import { build as tailwindBuild } from "./tailwind.ts";

if (Deno.args.includes("build")) {
Deno.exit(0);
}
const DECO_FOLDER = ".deco";
export const build = async () => {
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
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/blocks/decofile.json")) {
return txt;
}
return {
content: `${txt.content}\n.deco/blocks/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

0 comments on commit b17aecf

Please sign in to comment.