Skip to content

Commit

Permalink
fix globals on non minified
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardo-devis-agullo committed Sep 8, 2024
1 parent f2632c7 commit e44b1ff
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions tasks/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,40 @@ function parseConf(conf) {
};
}

function getFiles({ sync = false }) {
function getFiles({ sync = false, conf }) {
const srcPath = '../src/';
const vendorPath = '../vendor/';

const lPath = path.join(__dirname, vendorPath, 'l.js');
const ocClientPath = path.join(__dirname, srcPath, 'oc-client.js');
const replaceGlobals = x =>
x
.replaceAll(
'__REGISTERED_TEMPLATES_PLACEHOLDER__',
JSON.stringify(conf.templates)
)
.replaceAll('__EXTERNALS__', JSON.stringify(conf.externals))
.replaceAll('__DEFAULT_RETRY_LIMIT__', conf.retryLimit)
.replaceAll('__DEFAULT_RETRY_INTERVAL__', conf.retryInterval)
.replaceAll('__DEFAULT_DISABLE_LOADER__', conf.disableLoader)
.replaceAll('__DISABLE_LEGACY_TEMPLATES__', conf.disableLegacyTemplates);

if (sync) {
const l = fs.readFileSync(lPath, 'utf-8');
const ocClient = fs.readFileSync(ocClientPath, 'utf-8');
const ocClient = replaceGlobals(fs.readFileSync(ocClientPath, 'utf-8'));

return [l, ocClient];
} else {
const lPromise = readFile(lPath, 'utf-8');
const ocClientPromise = readFile(ocClientPath, 'utf-8');
const ocClientPromise = readFile(ocClientPath, 'utf-8').then(
replaceGlobals
);

return Promise.all([lPromise, ocClientPromise]);
}
}

function compileFiles(l, ocClient, conf) {
function compileFiles(l, ocClient) {
const version = packageJson.version;
const licenseLink =
'https://github.com/opencomponents/oc-client-browser/tree/master/LICENSES';
Expand All @@ -103,16 +116,6 @@ function compileFiles(l, ocClient, conf) {
sourceMap: {
filename: 'oc-client.min.js',
url: 'oc-client.min.map'
},
compress: {
global_defs: {
__DISABLE_LEGACY_TEMPLATES__: conf.disableLegacyTemplates,
__DEFAULT_DISABLE_LOADER__: conf.disableLoader,
__DEFAULT_RETRY_INTERVAL__: conf.retryInterval,
__DEFAULT_RETRY_LIMIT__: conf.retryLimit,
__EXTERNALS__: conf.externals,
__REGISTERED_TEMPLATES_PLACEHOLDER__: conf.templates
}
}
});

Expand All @@ -123,14 +126,14 @@ function compileFiles(l, ocClient, conf) {

async function compile(conf = {}) {
const parsedConf = parseConf(conf);
const [l, ocClient] = await getFiles({ sync: false });
return compileFiles(l, ocClient, parsedConf);
const [l, ocClient] = await getFiles({ sync: false, conf: parsedConf });
return compileFiles(l, ocClient);
}

function compileSync(conf = {}) {
const parsedConf = parseConf(conf);
const [l, ocClient] = getFiles({ sync: true });
return compileFiles(l, ocClient, parsedConf);
const [l, ocClient] = getFiles({ sync: true, conf: parsedConf });
return compileFiles(l, ocClient);
}

module.exports = {
Expand Down

0 comments on commit e44b1ff

Please sign in to comment.