-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing yarn and stop use artifacts
- Loading branch information
1 parent
53d2d4e
commit e27b7c6
Showing
5 changed files
with
212 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,55 @@ | ||
import fse from 'fs-extra'; | ||
import path from 'path'; | ||
import jsZip from 'jszip'; | ||
import nodeFetch from 'node-fetch'; | ||
import util from 'util'; | ||
import { exec } from 'child_process'; | ||
import dotenv from 'dotenv'; | ||
const execPromise = util.promisify(exec); | ||
|
||
dotenv.config(); | ||
|
||
// Pull latest git, dont use artifacts at all, see run-mock server | ||
const BUILD_MODE = process.env.BUILD_PATH === 'internal' ? 'internal' : 'www'; | ||
const dashboardDist = path.join(BUILD_MODE, 'light-app'); | ||
|
||
const ENV_BRANCH = (process.env.BRANCH !== 'main' && !process.env.BUILD_PROD) ? 'develop' : 'main'; | ||
|
||
console.log(`[fetch-light-app] Fetching light-app for branch "${process.env.BRANCH}" from server "${ENV_BRANCH}" branch...`); | ||
|
||
async function downloadAndUnpackDashboard(dashboardArtifact, distDir) { | ||
const latestArtifact = await nodeFetch(dashboardArtifact); | ||
const artifactBuffer = await latestArtifact.buffer(); | ||
|
||
const artifactZip = await jsZip.loadAsync(artifactBuffer); | ||
|
||
for (const [filename, file] of Object.entries(artifactZip.files)) { | ||
if (file.dir) { | ||
continue; | ||
} | ||
function copyDirectorySync(source, destination) { | ||
// Create the destination directory if it doesn't exist | ||
if (!fse.existsSync(destination)) { | ||
fse.mkdirSync(destination); | ||
} | ||
|
||
const fileBuffer = await file.async('nodebuffer'); | ||
// Read the contents of the source directory | ||
const files = fse.readdirSync(source); | ||
|
||
for (const file of files) { | ||
const sourceFilePath = path.join(source, file); | ||
const destinationFilePath = path.join(destination, file); | ||
|
||
const fileDist = path.join(distDir, filename); | ||
await fse.promises.mkdir(path.dirname(fileDist), { recursive: true }); | ||
fse.outputFileSync(fileDist, fileBuffer); | ||
// Check if the current item is a directory | ||
if (fse.statSync(sourceFilePath).isDirectory()) { | ||
// If it's a directory, recursively copy its contents | ||
copyDirectorySync(sourceFilePath, destinationFilePath); | ||
} else { | ||
// If it's a file, copy it to the destination directory | ||
fse.copyFileSync(sourceFilePath, destinationFilePath); | ||
} | ||
} | ||
} | ||
|
||
(async () => { | ||
// Download the dashboard app | ||
await downloadAndUnpackDashboard(`https://nightly.link/casanet/lightweight-dashboard/workflows/build/${ENV_BRANCH}/${BUILD_MODE}.zip`, dashboardDist); | ||
|
||
try { await execPromise(`mkdir ${path.join('temp-mock')}`); } catch {} | ||
try { await execPromise(`cd ${path.join('temp-mock')} && git clone https://github.com/casanet/lightweight-dashboard.git && git checkout ${ENV_BRANCH}`); } catch {} | ||
await execPromise(`cd ${path.join('temp-mock', 'lightweight-dashboard')} && git checkout ${ENV_BRANCH} && git pull`); | ||
try { | ||
const setEnvRes = await execPromise(`cd ${path.join('temp-mock', 'lightweight-dashboard')} && node scripts/set-environment.js`, { env: { API_URL: process.env.REACT_APP_API_URL } }); | ||
console.log(setEnvRes.stdout); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
|
||
copyDirectorySync(path.join('temp-mock', 'lightweight-dashboard', 'src'), dashboardDist); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.