Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/cli-methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1863,13 +1863,17 @@ export const buildFrontend = async () => {
});
}).then(async () => {
// make sure environment is not development for storage config
// and if we want to upload to storage, we need set S3_BUCKET_ENDPOINT
// and ensure remote storage config exists for publish
const hasRemoteStorageEndpoint =
process.env.STATIC_S3_BUCKET_ENDPOINT ||
process.env.UPLOADS_S3_BUCKET_ENDPOINT ||
process.env.S3_BUCKET_ENDPOINT;
if (
process.env.NODE_ENV === 'development' ||
!process.env.S3_BUCKET_ENDPOINT
!hasRemoteStorageEndpoint
) {
console.warn(
'Upload build to storage skip in development environment or S3_BUCKET_ENDPOINT is not set',
'Upload build to storage skipped in development environment or no S3 endpoint is configured',
);
return;
// process.exit();
Expand All @@ -1886,9 +1890,12 @@ export const buildFrontend = async () => {
path.join(process.cwd(), 'scripts', 'storage-config.js')
);

// check if LincdFileStorage has a default FileStore
// if yes: copy all the files in the build folder over with LincdFileStorage
if (LinkedFileStorage.getDefaultStore()) {
const publishStore =
storageConfig.staticFileStore || LinkedFileStorage.getDefaultStore();

// check if we have a publish store
// if yes: copy all the files in the build folder over with that store
if (publishStore) {
// get public directory
const rootDirectory = 'public';
const pathDir = path.join(process.cwd(), rootDirectory);
Expand Down Expand Up @@ -1921,7 +1928,8 @@ export const buildFrontend = async () => {
const pathname = filePath.replace(pathDir, `/${rootDirectory}`);

// upload file to storage
await LinkedFileStorage.saveFile(pathname, fileContent)
await publishStore
.saveFile(pathname, fileContent)
.then(() => {
clearSpinner.text = `${counter++}/${files.length}: - Published ${pathname} `;
})
Expand Down
12 changes: 9 additions & 3 deletions src/config-webpack-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ export const getWebpackAppConfig = async () => {
// set up the storage config for the app
await import(path.join(process.cwd(), 'scripts', 'storage-config.js'));
const accessURL = LinkedFileStorage.accessURL;
const staticAccessURL = (
process.env.STATIC_ACCESS_URL ||
accessURL ||
''
).replace(/\/$/, '');

// set up the public path for the app
// for Capacitor apps (APP_ENV is set), use /bundles/ since Capacitor's webDir strips /public (see: capacitor.config.ts)
Expand All @@ -171,8 +176,9 @@ export const getWebpackAppConfig = async () => {
// ASSET_PATH is used load the assets from the correct path
// if ASSET_PATH is set in environment (app builds), use it directly
// otherwise, use CDN URL + bundlesPath for production, or bundlesPath for development
const ASSET_PATH = process.env.ASSET_PATH ||
(accessURL ? accessURL + bundlesPath : bundlesPath);
const ASSET_PATH =
process.env.ASSET_PATH ||
(staticAccessURL ? staticAccessURL + bundlesPath : bundlesPath);

let config = await getLincdConfig();

Expand Down Expand Up @@ -241,7 +247,7 @@ export const getWebpackAppConfig = async () => {
return cleanedUrl;
}

const baseUrl = (accessURL || '').replace(/\/$/, '');
const baseUrl = staticAccessURL;
return `${baseUrl}${publicPath}${cleanedUrl}`;
},
}),
Expand Down