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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Fynd Development Kit
>**Note:** Experimental support for Windows is available, it may not be fully stable.
<div>
<div className="fd_cli">

[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
Expand Down
30 changes: 16 additions & 14 deletions src/helper/serve.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import https from 'https';
const packageJSON = require('../../package.json');

const BUILD_FOLDER = './.fdk/dist';
const SERVE_BUILD_FOLDER = './.fdk/distServed';
let port = 5001;
let sockets = [];
let publicCache = {};
Expand Down Expand Up @@ -171,7 +172,7 @@ export async function startServer({ domain, host, isSSR, port }) {

applyProxy(app);

app.use(express.static(path.resolve(process.cwd(), BUILD_FOLDER)));
app.use(express.static(path.resolve(process.cwd(), SERVE_BUILD_FOLDER)));
app.get(['/__webpack_hmr', '/manifest.json'], async (req, res, next) => {
return res.end();
});
Expand All @@ -193,11 +194,11 @@ export async function startServer({ domain, host, isSSR, port }) {

const BUNDLE_PATH = path.join(
process.cwd(),
path.join('.fdk', 'dist', 'themeBundle.common.js'),
path.join('.fdk', 'distServed', 'themeBundle.common.js'),
);
if (!fs.existsSync(BUNDLE_PATH))
return res.sendFile(
path.join(__dirname, '../../', '/dist/helper', '/loader.html'),
path.join(__dirname, '../../', '/distServed/helper', '/loader.html'),
);
if (req.originalUrl == '/favicon.ico' || req.originalUrl == '/.webp') {
return res.status(404).send('Not found');
Expand All @@ -209,7 +210,7 @@ export async function startServer({ domain, host, isSSR, port }) {
if (isSSR) {
const BUNDLE_PATH = path.join(
process.cwd(),
'/.fdk/dist/themeBundle.common.js',
'/.fdk/distServed/themeBundle.common.js',
);
const User = Configstore.get(CONFIG_KEYS.AUTH_TOKEN);
themeUrl = (
Expand All @@ -218,7 +219,8 @@ export async function startServer({ domain, host, isSSR, port }) {
'fdk-cli-dev-files',
User.current_user._id,
)
).start.cdn.url;
).complete.cdn.url;

} else {
jetfireUrl.searchParams.set('__csr', 'true');
}
Expand Down Expand Up @@ -262,24 +264,24 @@ export async function startServer({ domain, host, isSSR, port }) {
)}"></script>`,
);
const umdJsAssests = glob
.sync(`${Theme.BUILD_FOLDER}/themeBundle.umd.**.js`)
.sync(`${Theme.SERVE_BUILD_FOLDER}/themeBundle.umd.**.js`)
.filter((x) => !x.includes('.min.'));
umdJsAssests.forEach((umdJsLink) => {
umdJsInitial.after(
`<script type="text/javascript" src="${urlJoin(
getFullLocalUrl(port),
umdJsLink.replace('./.fdk/dist/', ''),
umdJsLink.replace('./.fdk/distServed/', ''),
)}"></script>`,
);
});

const cssAssests = glob.sync(`${Theme.BUILD_FOLDER}/**.css`);
const cssAssests = glob.sync(`${Theme.SERVE_BUILD_FOLDER}/**.css`);
const cssInitial = $('link[data-css-cli-source="initial"]');
cssAssests.forEach((cssLink) => {
cssInitial.after(
`<link rel="stylesheet" href="${urlJoin(
getFullLocalUrl(port),
cssLink.replace('./.fdk/dist/', ''),
cssLink.replace('./.fdk/distServed/', ''),
)}"></link>`,
);
});
Expand All @@ -296,7 +298,7 @@ export async function startServer({ domain, host, isSSR, port }) {
errorString = `<h3><b>${errorString}</b></h3>`;
const mapContent = JSON.parse(
fs.readFileSync(
`${BUILD_FOLDER}/themeBundle.common.js.map`,
`${SERVE_BUILD_FOLDER}/themeBundle.common.js.map`,
{ encoding: 'utf8', flag: 'r' },
),
);
Expand Down Expand Up @@ -370,7 +372,7 @@ export async function startReactServer({ domain, host, isHMREnabled, port }) {
}

const ctx = {
buildPath: path.resolve(process.cwd(), Theme.BUILD_FOLDER),
buildPath: path.resolve(process.cwd(), Theme.SERVE_BUILD_FOLDER),
NODE_ENV: 'development',
localThemePort: port,
context: process.cwd(),
Expand All @@ -394,7 +396,7 @@ export async function startReactServer({ domain, host, isHMREnabled, port }) {

app.use(webpackHotMiddleware(compiler));
}
app.use(express.static(path.resolve(process.cwd(), BUILD_FOLDER)));
app.use(express.static(path.resolve(process.cwd(), SERVE_BUILD_FOLDER)));

app.use((request, response, next) => {
// Filtering so that HMR file requests are not routed to skyfire pods
Expand Down Expand Up @@ -429,14 +431,14 @@ export async function startReactServer({ domain, host, isHMREnabled, port }) {
currentContext.theme_id,
);
}
const BUNDLE_DIR = path.join(process.cwd(), path.join('.fdk', 'dist'));
const BUNDLE_DIR = path.join(process.cwd(), path.join('.fdk', 'distServed'));
if (req.originalUrl == '/favicon.ico' || req.originalUrl == '/.webp') {
return res.status(404).send('Not found');
}
// While build is not complete
if (!fs.existsSync(path.join(BUNDLE_DIR, 'themeBundle.umd.js'))) {
return res.sendFile(
path.join(__dirname, '../../', '/dist/helper', '/loader.html'),
path.join(__dirname, '../../', '/distServed/helper', '/loader.html'),
);
}
const skyfireUrl = new URL(urlJoin(domain, req.originalUrl));
Expand Down
21 changes: 12 additions & 9 deletions src/lib/Theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export default class Theme {
'react-template',
);
static BUILD_FOLDER = './.fdk/dist';
static SERVE_BUILD_FOLDER = './.fdk/distServed';
static SRC_FOLDER = path.join('.fdk', 'temp-theme');
static VUE_CLI_CONFIG_PATH = path.join('.fdk', 'vue.config.js');
static REACT_CLI_CONFIG_PATH = 'webpack.config.js';
Expand Down Expand Up @@ -1159,7 +1160,7 @@ export default class Theme {
Logger.info(`Locally building`);
Theme.createVueConfig();
await devBuild({
buildFolder: Theme.BUILD_FOLDER,
buildFolder: Theme.SERVE_BUILD_FOLDER,
imageCdnUrl: urlJoin(getFullLocalUrl(port), 'assets/images'),
isProd: isSSR,
});
Expand All @@ -1180,7 +1181,7 @@ export default class Theme {
watcher.on('change', async () => {
Logger.info(chalk.bold.green(`building`));
await devBuild({
buildFolder: Theme.BUILD_FOLDER,
buildFolder: Theme.SERVE_BUILD_FOLDER,
imageCdnUrl: urlJoin(
getFullLocalUrl(port),
'assets/images',
Expand Down Expand Up @@ -1210,7 +1211,7 @@ export default class Theme {
await Theme.createReactSectionsIndexFile();

await devReactBuild({
buildFolder: Theme.BUILD_FOLDER,
buildFolder: Theme.SERVE_BUILD_FOLDER,
runOnLocal: true,
localThemePort: port,
isHMREnabled,
Expand All @@ -1229,7 +1230,7 @@ export default class Theme {
Logger.info(chalk.bold.green(`Watching files for changes`));
devReactWatch(
{
buildFolder: Theme.BUILD_FOLDER,
buildFolder: Theme.SERVE_BUILD_FOLDER,
runOnLocal: true,
localThemePort: port,
isHMREnabled,
Expand Down Expand Up @@ -1605,6 +1606,7 @@ export default class Theme {
};
private static clearPreviousBuild = () => {
rimraf.sync(Theme.BUILD_FOLDER);
rimraf.sync(Theme.SERVE_BUILD_FOLDER);
rimraf.sync(Theme.SRC_ARCHIVE_FOLDER);
};

Expand Down Expand Up @@ -1872,7 +1874,8 @@ export default class Theme {
path.join(process.cwd(), Theme.BUILD_FOLDER, commonJS),
'application-theme-assets',
);
const commonJsUrl = commonJsUrlRes.start.cdn.url;
const commonJsUrl = commonJsUrlRes.complete.cdn.url;


Logger.info('Uploading umdJS');
const umdMinAssets = glob.sync(
Expand Down Expand Up @@ -1909,9 +1912,9 @@ export default class Theme {
});
const cssUrls = await Promise.all(cssPromisesArr);
return [
cssUrls.map((res) => res.start.cdn.url),
cssUrls.map((res) => res.complete.cdn.url),
commonJsUrl,
umdJsUrls.map((res) => res.start.cdn.url),
umdJsUrls.map((res) => res.complete.cdn.url),
];
} catch (err) {
throw new CommandError(
Expand Down Expand Up @@ -2515,8 +2518,8 @@ export default class Theme {
let res = await UploadService.uploadFile(
zipFilePath,
'application-theme-src',
);
return res.start.cdn.url;
);
return res.complete.cdn.url;
} catch (err) {
throw new CommandError(
err.message || `Failed to upload src folder`,
Expand Down