Skip to content

Commit

Permalink
Merge branch 'develop' into feat/handle-contentful-preview-content
Browse files Browse the repository at this point in the history
  • Loading branch information
matteoscurati authored Oct 12, 2024
2 parents fc48ef5 + f2f180b commit 4777aa4
Showing 1 changed file with 48 additions and 9 deletions.
57 changes: 48 additions & 9 deletions development/sentry-publish.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env node

const fs = require('node:fs/promises');
const path = require('node:path');
const yargs = require('yargs/yargs');
const { hideBin } = require('yargs/helpers');

Expand Down Expand Up @@ -80,17 +82,19 @@ async function start() {
]);
}

const additionalUploadArgs = [];
if (dist) {
additionalUploadArgs.push('--dist', dist);
}
let distDirectory = 'dist';
if (buildType !== loadBuildTypesConfig().default) {
additionalUploadArgs.push(
'--dist-directory',
dist ? `dist-${buildType}-${dist}` : `dist-${buildType}`,
);
distDirectory = dist ? `dist-${buildType}-${dist}` : `dist-${buildType}`;
} else if (dist) {
additionalUploadArgs.push('--dist-directory', `dist-${dist}`);
distDirectory = `dist-${dist}`;
}

const absoluteDistDirectory = path.resolve(__dirname, '../', distDirectory);
await assertIsNonEmptyDirectory(absoluteDistDirectory);

const additionalUploadArgs = ['--dist-directory', distDirectory];
if (dist) {
additionalUploadArgs.push('--dist', dist);
}
// upload sentry source and sourcemaps
await runInShell('./development/sentry-upload-artifacts.sh', [
Expand Down Expand Up @@ -123,3 +127,38 @@ async function doesNotFail(asyncFn) {
throw error;
}
}

/**
* Assert that the given path exists, and is a non-empty directory.
*
* @param {string} directoryPath - The path to check.
*/
async function assertIsNonEmptyDirectory(directoryPath) {
await assertIsDirectory(directoryPath);

const files = await fs.readdir(directoryPath);
if (!files.length) {
throw new Error(`Directory empty: '${directoryPath}'`);
}
}

/**
* Assert that the given path exists, and is a directory.
*
* @param {string} directoryPath - The path to check.
*/
async function assertIsDirectory(directoryPath) {
try {
const directoryStats = await fs.stat(directoryPath);
if (!directoryStats.isDirectory()) {
throw new Error(`Invalid path '${directoryPath}'; must be a directory`);
}
} catch (error) {
if (error.code === 'ENOENT') {
throw new Error(`Directory '${directoryPath}' not found`, {
cause: error,
});
}
throw error;
}
}

0 comments on commit 4777aa4

Please sign in to comment.