Skip to content

Commit

Permalink
migration commit #4
Browse files Browse the repository at this point in the history
  • Loading branch information
yesil committed Nov 22, 2024
1 parent 3223487 commit 783a282
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 115 deletions.
55 changes: 39 additions & 16 deletions libs/features/mas/scripts/build.mjs → libs/features/mas/build.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { writeFileSync } from 'node:fs';
import { build } from 'esbuild';

const outfolder = '../../../../libs/deps/mas';
const outfolder = '../../deps/mas';

const defaults = {
bundle: true,
Expand All @@ -11,22 +11,34 @@ const defaults = {
platform: 'browser',
};

async function buildLitComponent(name) {
const { metafile } = await build({
...defaults,
entryPoints: [`./src/${name}.js`],
external: ['lit'],
metafile: true,
outfile: `${outfolder}/${name}.js`,
plugins: [rewriteImports()],
});
// commerce.js
const { metafile } = await build({
...defaults,
alias: {
react: 'test/mocks/react.js',
},
entryPoints: ['./src/commerce.js'],
metafile: true,
outfile: `${outfolder}/commerce.js`,
platform: 'browser',
target: ['es2020'],
});
writeFileSync(`commerce.json`, JSON.stringify(metafile));

writeFileSync(
`../../../../libs/deps/mas/${name}.json`,
JSON.stringify(metafile),
);
}
// mas.js
await build({
...defaults,
entryPoints: ['./src/mas.js'],
outfile: './dist/mas.js',
});

await build({
...defaults,
entryPoints: ['./src/mas.js'],
outfile: `${outfolder}/mas.js`,
});

// web components
Promise.all([
build({
...defaults,
Expand Down Expand Up @@ -60,7 +72,6 @@ Promise.all([
buildLitComponent('merch-quantity-select'),
buildLitComponent('merch-secure-transaction'),
buildLitComponent('merch-stock'),
buildLitComponent('merch-subscription-panel'),
buildLitComponent('merch-twp-d2p'),
buildLitComponent('merch-whats-included'),
buildLitComponent('merch-mnemonic-list'),
Expand All @@ -80,6 +91,18 @@ function rewriteImports() {
};
}

async function buildLitComponent(name) {
const { metafile } = await build({
...defaults,
entryPoints: [`./src/${name}.js`],
external: ['lit'],
metafile: true,
outfile: `${outfolder}/${name}.js`,
plugins: [rewriteImports()],
});
writeFileSync(`${outfolder}/${name}.json`, JSON.stringify(metafile));
}

function rewriteImportsToLibsFolder() {
return {
name: 'rewrite-imports-to-libs-folder',
Expand Down
18 changes: 0 additions & 18 deletions libs/features/mas/scripts/commerce-build.mjs

This file was deleted.

30 changes: 0 additions & 30 deletions libs/features/mas/scripts/mas-build.mjs

This file was deleted.

50 changes: 30 additions & 20 deletions libs/features/mas/src/commerce.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
import { EVENT_TYPE_READY, TAG_NAME_SERVICE } from './constants.js';
import { CheckoutLink } from './checkout-link.js';
import { Landscape } from './constants.js';
import { Defaults } from './defaults.js';
import { TAG_NAME_SERVICE } from './mas-commerce-service.js';
import {
CheckoutWorkflow,
CheckoutWorkflowStep,
WcsCommitment,
WcsTerm,
WcsPlanType,
applyPlanType,
} from './external.js';
import { InlinePrice } from './inline-price.js';
import { Log } from './log.js';
import { getSettings } from './settings.js';

/**
* Waits for commerce service to be ready and returns.
*/
export async function getService() {
const { head } = document;
const current = head.querySelector(TAG_NAME_SERVICE);
if (current) return Promise.resolve(current);
return new Promise((resolve, reject) => {
head.addEventListener(
EVENT_TYPE_READY,
() => {
const service = head.querySelector(TAG_NAME_SERVICE);
if (service) resolve(service);
else reject(new Error('Commerce service not found'));
},
{ once: true },
);
});
}
export {
TAG_NAME_SERVICE,
CheckoutLink,
CheckoutWorkflow,
CheckoutWorkflowStep,
Defaults,
InlinePrice,
Log,
WcsCommitment,
Landscape,
WcsTerm,
WcsPlanType,
applyPlanType,
getSettings,
};
31 changes: 0 additions & 31 deletions libs/features/mas/src/index.js

This file was deleted.

0 comments on commit 783a282

Please sign in to comment.