Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension asset upload #361

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8080c23
ID:FPCO-34269;DONE:100;HOURS:10;dev-prod saparate build
meetdhananifynd Jun 20, 2024
1de114c
Merge branch 'master' of github.com:gofynd/fdk-cli
meetdhananifynd Jul 11, 2024
9af8ca9
Merge branch 'master' of github.com:gofynd/fdk-cli
meetdhananifynd Jul 29, 2024
923f218
Merge branch 'master' of github.com:gofynd/fdk-cli
meetdhananifynd Aug 7, 2024
99b3cc3
Merge branch 'master' of github.com:gofynd/fdk-cli
meetdhananifynd Aug 27, 2024
3c3097c
Merge branch 'master' of github.com:gofynd/fdk-cli
meetdhananifynd Sep 3, 2024
c2aa142
ID:FPCO-39516;DONE:100;HOURS:10;migratios
meetdhananifynd Sep 3, 2024
70dce3c
ID:FPCO-39516;DONE:100;HOURS:10;migrations
meetdhananifynd Sep 5, 2024
8b4fc68
ID:FPCO-39516;DONE:100;HOURS:10;migrations
meetdhananifynd Sep 5, 2024
3593d7f
ID:FPCO-39516;DONE:100;HOURS:10;migrations
meetdhananifynd Sep 5, 2024
f8a065d
ID:FPCO-40052;DONE:100;HOURS:10;migrations
meetdhananifynd Sep 9, 2024
75703be
Merge branch 'master' of github.com:gofynd/fdk-cli into extension-ass…
meetdhananifynd Sep 10, 2024
2990732
ID:FPCO-43148;DONE:100;HOURS:10;migrations
meetdhananifynd Sep 10, 2024
3aee736
ID:FPCO-43995;DONE:100;HOURS:10;Brunt Test socket
meetdhananifynd Sep 20, 2024
446abb0
ID:FPCO-44106;DONE:100;HOURS:10;Bug fix header footer
meetdhananifynd Sep 24, 2024
52d38f5
ID:FPCO-44106;DONE:100;HOURS:10;Bug fix header footer
meetdhananifynd Sep 24, 2024
595eb68
ID:FPCO-44106;DONE:100;HOURS:10;Bug fix header footer
meetdhananifynd Sep 24, 2024
47047f9
ID:FPCO-44106;DONE:100;HOURS:10;Bug fix header footer
meetdhananifynd Sep 24, 2024
46ed898
ID:FPCO-44106;DONE:100;HOURS:10;Bug fix header footer
meetdhananifynd Sep 24, 2024
ff23469
Merge branch 'master' of github.com:gofynd/fdk-cli into extension-ass…
meetdhananifynd Sep 24, 2024
27f551b
vue support
meetdhananifynd Sep 26, 2024
bcf7203
vue support
meetdhananifynd Sep 26, 2024
229dc44
ID:FPCO-44106;DONE:100;HOURS:10;Bug fix header footer
meetdhananifynd Sep 26, 2024
bff79c0
ID:FPCO-44106;DONE:100;HOURS:10;Bug fix header footer
meetdhananifynd Sep 26, 2024
dc37383
ID:FPCO-44884;DONE:100;HOURS:10;Doc Update
meetdhananifynd Sep 27, 2024
40ebd6a
ID:FPCO-44884;DONE:100;HOURS:10;Doc Update
meetdhananifynd Sep 27, 2024
91a8407
ID:FPCO-44884;DONE:100;HOURS:10;Doc Update
meetdhananifynd Sep 30, 2024
c02abf9
ID:FPCO-44884;DONE:100;HOURS:10;Doc Update
meetdhananifynd Sep 30, 2024
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
10 changes: 10 additions & 0 deletions extension-section/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,17 @@ module.exports = (env) => {
"less-loader",
],
exclude: /\.global\.less$/,
},
{
test: /\.(png|jpg|jpeg|ttf|otf|woff|woff2)$/i,
type: "asset/resource",
generator: {
publicPath: isLocalBuild
? env.localAssetBasePath
: env.assetCdnUrl,
outputPath: "assets/",
},
},
],
},
plugins: [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gofynd/fdk-cli",
"version": "6.2.1",
"version": "6.2.2",
"main": "index.js",
"license": "MIT",
"bin": {
Expand Down
3 changes: 3 additions & 0 deletions src/helper/extension.react.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type ExtensionBuildContext = {
bundleName: string;
port: number
context: string;
assetCdnUrl?: string;
localAssetBasePath?: string,
}

const snippet = (port) => `
Expand Down Expand Up @@ -65,6 +67,7 @@ export function extensionWebpackConfig(env: ExtensionBuildContext, webpackConfig

const extendedWebpackResolved = webpackConfigFromBinding(env);


const baseConfig: Configuration = {
externals: {
react: 'React',
Expand Down
78 changes: 72 additions & 6 deletions src/lib/ExtensionSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { tunnel as startCloudflareTunnel, bin, install } from 'cloudflared';

import Logger from './Logger';
import Spinner from '../helper/spinner';
import { installNpmPackages } from '../helper/utils';
import { asyncForEach, installNpmPackages } from '../helper/utils';
import { readFile } from '../helper/file.utils';
import { extensionWebpackConfig } from '../helper/extension.react.config';
import { webpack } from 'webpack';
Expand Down Expand Up @@ -37,6 +37,7 @@ const readDirectories = promisify(fs.readdir);
type BindingInterface = 'Web Theme' | 'Platform';

export type SupportedFrameworks = 'react' | 'vue2';
import glob from 'glob';

type AppliedThemeData = {
applicationId: string;
Expand Down Expand Up @@ -291,6 +292,59 @@ export default class ExtensionSection {
}
}

private static assetsUploader = async (destinationPath) => {
try {
const cwd = path.resolve(
destinationPath,
'dist',
'assets',
);
const images = glob.sync(path.join('**', '**.**'), { cwd });
await asyncForEach(images, async (img) => {
const assetPath = path.join(
cwd,
img,
);
await uploadService.uploadFile(
assetPath,
'application-theme-images',
);
});
} catch (err) {
throw new CommandError(
err.message || `Failed to upload assets/images`,
err.code,
);
}
};

private static getAssetCdnUrl = async () => {
try {
const dummyFile = path.join(
__dirname,
'..',
'..',
'sample-upload.jpeg'
);

const response = await uploadService.uploadFile(
dummyFile,
'application-theme-assets',
null,
'application/javascript'
);


return path.dirname(response.complete.cdn.url);
} catch (err) {
Logger.error(err);
throw new CommandError(
`Failed in getting image CDN base url`,
err.code,
);
}
}

public static clearContext() {
Configstore.set('extensionSections', {});
}
Expand Down Expand Up @@ -441,14 +495,18 @@ export default class ExtensionSection {
options,
'publish',
);

const { interface: bindingInterface, framework, name } = context;

if (bindingInterface === 'Web Theme') {
if (framework === 'react' || framework === 'vue2') {
Logger.info(`Publishing Extension Bindings`);

const assetCdnUrl = await ExtensionSection.getAssetCdnUrl();

const sectionData = await ExtensionSection.buildAndExtractSections(
context,
assetCdnUrl
);
sectionData.status = 'published';

Expand Down Expand Up @@ -537,6 +595,7 @@ export default class ExtensionSection {

static async buildAndExtractSections(
context: SyncExtensionBindingsOptions,
assetCdnUrl:string
): Promise<any> {
const { name: bundleName, framework } = context;
const isReact = framework === 'react';
Expand All @@ -547,11 +606,12 @@ export default class ExtensionSection {
isReact ? ExtensionSection.BINDINGS_DIR_REACT : ExtensionSection.BINDINGS_DIR_VUE,
bundleName,
)

Logger.info('Uploading extension assets');
await ExtensionSection.assetsUploader(destinationPath);
process.chdir(destinationPath);

if (isReact) {
await ExtensionSection.buildExtensionCode({ bundleName }).catch(
await ExtensionSection.buildExtensionCode({ bundleName,assetCdnUrl }).catch(
ZaidRehmanQureshi marked this conversation as resolved.
Show resolved Hide resolved
console.error,
);
} else {
Expand Down Expand Up @@ -611,6 +671,7 @@ export default class ExtensionSection {

static async buildExtensionCode({
bundleName,
assetCdnUrl='',
ZaidRehmanQureshi marked this conversation as resolved.
Show resolved Hide resolved
isLocal = false,
port = 5502,
}): Promise<{ jsFile: string; cssFile: string }> {
Expand All @@ -623,7 +684,7 @@ export default class ExtensionSection {
context,
'webpack.config.js'
);

if (fs.existsSync(webpackExtendedPath)) {
({ default: webpackConfigFromBinding } = await import(
webpackExtendedPath
Expand All @@ -634,6 +695,7 @@ export default class ExtensionSection {
isLocal,
bundleName,
port,
assetCdnUrl: assetCdnUrl + '/',
context,
}, webpackConfigFromBinding);

Expand Down Expand Up @@ -667,9 +729,10 @@ export default class ExtensionSection {
if (bindingInterface === 'Web Theme') {
if (framework === 'react' || framework === 'vue2') {
Logger.info(`Creating drafts for Extension Bindings`);

const assetCdnUrl = await ExtensionSection.getAssetCdnUrl();
const sectionData = await ExtensionSection.buildAndExtractSections(
context,
assetCdnUrl
);
sectionData.status = 'draft';

Expand Down Expand Up @@ -715,10 +778,13 @@ export default class ExtensionSection {
));
}

const localAssetBasePath = `http://127.0.0.1:${port}/assets/`;

const webpackConfig = extensionWebpackConfig({
isLocal: true,
bundleName,
port,
localAssetBasePath,
context,
}, webpackConfigFromBinding);

Expand Down
12 changes: 6 additions & 6 deletions src/lib/Theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,9 @@ export default class Theme {
throw new CommandError(error.message, error.code);
}
});
config['application_id'] = selectedApplication;
config['company_id'] = selectedCompany;
config['application_id'] = selectedApplication;
config['company_id'] = selectedCompany;

return config;
}

Expand Down Expand Up @@ -1217,7 +1218,6 @@ export default class Theme {

// start dev server
Logger.info(chalk.bold.blueBright(`Starting server`));

await startReactServer({
domain,
host,
Expand Down Expand Up @@ -1645,7 +1645,7 @@ export default class Theme {
);
}

private static assetsImageUploader = async () => {
private static assetsImageUploader = async () => {
try {
const cwd = path.resolve(
process.cwd(),
Expand Down Expand Up @@ -1675,7 +1675,7 @@ export default class Theme {
}
};

private static getImageCdnBaseUrl = async () => {
public static getImageCdnBaseUrl = async () => {
try {
const dummyFile = path.join(
__dirname,
Expand All @@ -1701,7 +1701,7 @@ export default class Theme {
}
};

private static getAssetCdnBaseUrl = async () => {
public static getAssetCdnBaseUrl = async () => {
try {
const dummyFile = path.join(
__dirname,
Expand Down
Loading