Skip to content

Commit cc376f7

Browse files
yurynixvaleriihorsharik-wix
authored andcommitted
Move to client dir if artifact is static only (#10)
* Move to client dir if artifact is static only * Bump version
1 parent 85b9341 commit cc376f7

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

packages/@wix-astro/src/integration.ts

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,49 @@ export function createIntegration(): AstroIntegration {
231231
},
232232
"astro:build:done": async (buildResult) => {
233233
const hasPages = buildResult.pages.length > 0;
234-
const buildOutputType = _buildOutput === "static" ?
235-
"static"
236-
: hasPages ? "hybrid" : "server-only";
234+
const buildOutputType = _buildOutput === "static"
235+
? "static"
236+
: hasPages
237+
? "hybrid"
238+
: "server-only";
237239

238-
await fs.writeFile(path.join(_config.outDir.pathname, '.wix-build-metadata.json'), JSON.stringify({ envName: process.env["ENV_NAME"], buildOutputType, }, null, '\t'));
240+
241+
const moveToClientDir = async () => {
242+
const clientDir = path.join(_config.outDir.pathname, "client");
243+
await fs.mkdir(clientDir, { recursive: true });
244+
245+
// Move all files except "client" directory
246+
const files = await fs.readdir(_config.outDir.pathname);
247+
await Promise.all(
248+
files
249+
.filter(file => file !== "client")
250+
.map(file =>
251+
fs.rename(
252+
path.join(_config.outDir.pathname, file),
253+
path.join(clientDir, file)
254+
)
255+
)
256+
);
257+
}
258+
259+
if (_buildOutput === "static") {
260+
try {
261+
await moveToClientDir();
262+
} catch(ex) {
263+
console.error(`@wix/astro failed to move files to client directory: ${(ex as Error).message}`);
264+
throw ex;
265+
}
266+
}
267+
268+
const metadata = {
269+
envName: process.env["ENV_NAME"],
270+
buildOutputType,
271+
};
272+
273+
await fs.writeFile(
274+
path.join(_config.outDir.pathname, ".wix-build-metadata.json"),
275+
JSON.stringify(metadata, null, 2) // More conventional JSON formatting
276+
);
239277
},
240278
},
241279
};

0 commit comments

Comments
 (0)