diff --git a/README.md b/README.md index d0554f54..1250ad75 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # Fynd Development Kit >**Note:** Experimental support for Windows is available, it may not be fully stable. -
+
[![NPM Version][npm-image]][npm-url] [![NPM Downloads][downloads-image]][downloads-url] diff --git a/src/helper/serve.utils.ts b/src/helper/serve.utils.ts index 94c80541..d149385c 100644 --- a/src/helper/serve.utils.ts +++ b/src/helper/serve.utils.ts @@ -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 = {}; @@ -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(); }); @@ -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'); @@ -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 = ( @@ -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'); } @@ -262,24 +264,24 @@ export async function startServer({ domain, host, isSSR, port }) { )}">`, ); 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( ``, ); }); - 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( ``, ); }); @@ -296,7 +298,7 @@ export async function startServer({ domain, host, isSSR, port }) { errorString = `

${errorString}

`; const mapContent = JSON.parse( fs.readFileSync( - `${BUILD_FOLDER}/themeBundle.common.js.map`, + `${SERVE_BUILD_FOLDER}/themeBundle.common.js.map`, { encoding: 'utf8', flag: 'r' }, ), ); @@ -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(), @@ -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 @@ -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)); diff --git a/src/lib/Theme.ts b/src/lib/Theme.ts index 3a0278df..2774b0a4 100644 --- a/src/lib/Theme.ts +++ b/src/lib/Theme.ts @@ -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'; @@ -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, }); @@ -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', @@ -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, @@ -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, @@ -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); }; @@ -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( @@ -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( @@ -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`,