Skip to content

Commit

Permalink
Refactor and additional comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Duda committed Feb 16, 2021
1 parent 07fb870 commit e056ee6
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions apps/test-bundles/webpackUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const resources = require('@fluentui/scripts/webpack/webpack-resources');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const TerserPlugin = require('terser-webpack-plugin');

const FIXTURE_PATH = 'temp/fixtures/';

function createWebpackConfig(entries) {
return Object.keys(entries).map(entryName => {
let anaylizerPluginOptions = {
Expand Down Expand Up @@ -87,7 +89,7 @@ function createFluentNorthstarFixtures() {
const importStatement = `import { ${itemName} } from '${packageName}'; console.log(${itemName})`;
try {
const folderName = getFolderName(packageName);
const entryPath = path.join('temp/fixtures/', folderName, `${itemName}.js`);
const entryPath = path.join(FIXTURE_PATH, folderName, `${itemName}.js`);
fs.outputFileSync(entryPath, importStatement, 'utf-8');
} catch (err) {
console.log(err);
Expand All @@ -109,10 +111,11 @@ function createFluentReactFixtures() {

if (isAllowedFile && !isFolder) {
const item = isFolder ? itemName : itemName.replace(/.js$/, '');
// import everything from package/item path
const importStatement = `import * as p from '${packageName}/lib/${item}'; console.log(p)`;
try {
const folderName = getFolderName(packageName);
const entryPath = path.join('temp/fixtures/', folderName, `${item}.js`);
const entryPath = path.join(FIXTURE_PATH, folderName, `${item}.js`);
fs.outputFileSync(entryPath, importStatement, 'utf-8');
} catch (err) {
console.log(err);
Expand All @@ -126,7 +129,7 @@ function createEntry(packageName) {
// import everything from a single package
const importStatement = `import * as p from '${packageName}'; console.log(p)`;
const folderName = getFolderName(packageName);
const entryPath = path.join('temp/fixtures/', folderName, 'index.js');
const entryPath = path.join(FIXTURE_PATH, folderName, 'index.js');
fs.outputFileSync(entryPath, importStatement, 'utf-8');
} catch (err) {
console.log(err);
Expand All @@ -144,7 +147,7 @@ function createEntry(packageName) {
*/
function buildEntries(packageName, entries = {}, includeStats = true) {
const folderName = getFolderName(packageName);
const packagePath = path.join('temp/fixtures/', folderName);
const packagePath = path.join(FIXTURE_PATH, folderName);

fs.readdirSync(packagePath).forEach(itemName => {
const entryName = itemName.replace(/.js$/, '');
Expand All @@ -163,7 +166,7 @@ function buildEntries(packageName, entries = {}, includeStats = true) {
*/
function buildEntry(packageName, includeStats = true) {
const folderName = getFolderName(packageName);
const entryPath = path.resolve(path.join('temp/fixtures/', folderName));
const entryPath = path.resolve(path.join(FIXTURE_PATH, folderName));
return {
entryPath: `${entryPath}/index.js`,
includeStats,
Expand Down

0 comments on commit e056ee6

Please sign in to comment.