-
Notifications
You must be signed in to change notification settings - Fork 326
/
Copy pathinstall-site-in-isolation.mjs
50 lines (40 loc) · 1.62 KB
/
install-site-in-isolation.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env zx
import { cp, mkdir, mkdtemp } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import * as core from '@actions/core';
import { $, argv, cd, chalk } from 'zx';
try {
// Setup variables and environment variables
const SITE_PATH = argv._[0];
const ROOT_PATH = new URL('../', import.meta.url).pathname;
const FULL_SITE_PATH = join(ROOT_PATH, SITE_PATH);
const TMP_FOLDER = await mkdtemp(join(tmpdir(), 'clerk-site-'));
const FULL_TMP_FOLDER = join(TMP_FOLDER, SITE_PATH);
process.env.SECCO_SOURCE_PATH = ROOT_PATH;
process.env.FORCE_COLOR = '1';
core.debug(`Path variables:
SITE_PATH: ${SITE_PATH}
ROOT_PATH: ${ROOT_PATH}
FULL_SITE_PATH: ${FULL_SITE_PATH}
TMP_FOLDER: ${TMP_FOLDER}
FULL_TMP_FOLDER: ${FULL_TMP_FOLDER}`);
// Installing secco
await core.group('Installing secco (if not already installed)', async () => {
await $`command -v secco || (command -v sudo && sudo npm install -g secco@latest) || npm install -g secco@latest`;
});
// Create temporary folder setup
await mkdir(FULL_TMP_FOLDER, { recursive: true });
// Copy the site into the temporary location to isolate it
core.info(`Copying ${chalk.bold(SITE_PATH)} into ${chalk.bold(FULL_TMP_FOLDER)}`);
await cp(FULL_SITE_PATH, FULL_TMP_FOLDER, { recursive: true });
await core.group('Installing dependencies through secco', async () => {
cd(FULL_TMP_FOLDER);
await $`secco --force-verdaccio --scan-once`;
});
core.exportVariable('FULL_TMP_FOLDER', FULL_TMP_FOLDER);
} catch (e) {
// Bail on errors
core.setFailed(`Script failed with error: ${e}`);
process.exit();
}