Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
fpbrault committed Sep 19, 2024
1 parent 0f41617 commit fcdf54c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 121 deletions.
61 changes: 2 additions & 59 deletions packages/atomic/.storybook/main.mts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {nxViteTsPaths} from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
import type {StorybookConfig} from '@storybook/web-components-vite';
import path from 'node:path';
import {mergeConfig} from 'vite';
import headlessJson from '../../../packages/headless/package.json';
import {packageMappings} from '../scripts/packageMappings';

const isCDN = process.env.DEPLOYMENT_ENVIRONMENT === 'CDN';

Expand Down Expand Up @@ -34,7 +33,7 @@ function externalizeDependencies() {
name: 'externalize-dependencies',
enforce: 'pre',
resolveId: (id: string) => {
if (id.startsWith('/headless')) {
if (/^\/(headless|bueno)/.test(id)) {
return false;
}
if (packageMappings[id]) {
Expand All @@ -51,60 +50,4 @@ function externalizeDependencies() {
};
}

let headlessVersion: string;
if (isCDN) {
console.log('Building for CDN');
headlessVersion = 'v' + headlessJson.version;
}

const packageMappings: {[key: string]: {devWatch: string; cdn: string}} = {
'@coveo/headless/commerce': {
devWatch: path.resolve(
__dirname,
'../src/external-builds/commerce/headless.esm.js'
),
cdn: `/headless/${headlessVersion}/commerce/headless.esm.js`,
},
'@coveo/headless/insight': {
devWatch: path.resolve(
__dirname,
'../src/external-builds/insight/headless.esm.js'
),
cdn: `/headless/${headlessVersion}/insight/headless.esm.js`,
},
'@coveo/headless/product-recommendation': {
devWatch: path.resolve(
__dirname,
'../src/external-builds/product-recommendation/headless.esm.js'
),
cdn: `/headless/${headlessVersion}/product-recommendation/headless.esm.js`,
},
'@coveo/headless/recommendation': {
devWatch: path.resolve(
__dirname,
'../src/external-builds/recommendation/headless.esm.js'
),
cdn: `/headless/${headlessVersion}/recommendation/headless.esm.js`,
},
'@coveo/headless/case-assist': {
devWatch: path.resolve(
__dirname,
'../src/external-builds/case-assist/headless.esm.js'
),
cdn: `/headless/${headlessVersion}/case-assist/headless.esm.js`,
},
'@coveo/headless': {
devWatch: path.resolve(__dirname, '../src/external-builds/headless.esm.js'),
cdn: `/headless/${headlessVersion}/headless.esm.js`,
},
/* '@coveo/bueno': {
devWatch: path.resolve(__dirname, './src/external-builds/bueno.esm.js'),
cdn: `/bueno/${headlessVersion}/bueno.esm.js`,
}, */
};

export default config;

// To customize your Vite configuration you can use the viteFinal field.
// Check https://storybook.js.org/docs/react/builders/vite#configuration
// and https://nx.dev/recipes/storybook/custom-builder-configs
59 changes: 59 additions & 0 deletions packages/atomic/scripts/packageMappings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import path from 'node:path';
import headlessJson from '../../../packages/headless/package.json';
import buenoJson from '../../../packages/headless/package.json';

let headlessVersion: string = '';
let buenoVersion: string = '';

headlessVersion = 'v' + headlessJson.version;
buenoVersion = 'v' + buenoJson.version;

export const packageMappings: {[key: string]: {devWatch: string; cdn: string}} =
{
'@coveo/headless/commerce': {
devWatch: path.resolve(
__dirname,
'../src/external-builds/commerce/headless.esm.js'
),
cdn: `/headless/${headlessVersion}/commerce/headless.esm.js`,
},
'@coveo/headless/insight': {
devWatch: path.resolve(
__dirname,
'../src/external-builds/insight/headless.esm.js'
),
cdn: `/headless/${headlessVersion}/insight/headless.esm.js`,
},
'@coveo/headless/product-recommendation': {
devWatch: path.resolve(
__dirname,
'../src/external-builds/product-recommendation/headless.esm.js'
),
cdn: `/headless/${headlessVersion}/product-recommendation/headless.esm.js`,
},
'@coveo/headless/recommendation': {
devWatch: path.resolve(
__dirname,
'../src/external-builds/recommendation/headless.esm.js'
),
cdn: `/headless/${headlessVersion}/recommendation/headless.esm.js`,
},
'@coveo/headless/case-assist': {
devWatch: path.resolve(
__dirname,
'../src/external-builds/case-assist/headless.esm.js'
),
cdn: `/headless/${headlessVersion}/case-assist/headless.esm.js`,
},
'@coveo/headless': {
devWatch: path.resolve(
__dirname,
'../src/external-builds/headless.esm.js'
),
cdn: `/headless/${headlessVersion}/headless.esm.js`,
},
'@coveo/bueno': {
devWatch: path.resolve(__dirname, './src/external-builds/bueno.esm.js'),
cdn: `/bueno/${buenoVersion}/bueno.esm.js`,
},
};
65 changes: 4 additions & 61 deletions packages/atomic/stencil.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {Config} from '@stencil/core';
import {reactOutputTarget as react} from '@stencil/react-output-target';
import autoprefixer from 'autoprefixer';
import {readFileSync, readdirSync} from 'fs';
import path from 'path';
import focusVisible from 'postcss-focus-visible';
import atImport from 'postcss-import';
import postcssMap from 'postcss-map';
Expand All @@ -16,68 +15,12 @@ import html from 'rollup-plugin-html';
import {inlineSvg} from 'stencil-inline-svg';
import tailwind from 'tailwindcss';
import tailwindNesting from 'tailwindcss/nesting';
import headlessJson from '../../packages/headless/package.json';
import buenoJson from '../../packages/headless/package.json';
import {packageMappings} from './scripts/packageMappings';
import {generateAngularModuleDefinition as angularModule} from './stencil-plugin/atomic-angular-module';

const isProduction = process.env.BUILD === 'production';
const isCDN = process.env.DEPLOYMENT_ENVIRONMENT === 'CDN';

let headlessVersion: string = '';
let buenoVersion: string = '';

if (isCDN) {
console.log('Building for CDN');
headlessVersion = 'v' + headlessJson.version;
buenoVersion = 'v' + buenoJson.version;
}

const packageMappings: {[key: string]: {devWatch: string; cdn: string}} = {
'@coveo/headless/commerce': {
devWatch: path.resolve(
__dirname,
'./src/external-builds/commerce/headless.esm.js'
),
cdn: `/headless/${headlessVersion}/commerce/headless.esm.js`,
},
'@coveo/headless/insight': {
devWatch: path.resolve(
__dirname,
'./src/external-builds/insight/headless.esm.js'
),
cdn: `/headless/${headlessVersion}/insight/headless.esm.js`,
},
'@coveo/headless/product-recommendation': {
devWatch: path.resolve(
__dirname,
'./src/external-builds/product-recommendation/headless.esm.js'
),
cdn: `/headless/${headlessVersion}/product-recommendation/headless.esm.js`,
},
'@coveo/headless/recommendation': {
devWatch: path.resolve(
__dirname,
'./src/external-builds/recommendation/headless.esm.js'
),
cdn: `/headless/${headlessVersion}/recommendation/headless.esm.js`,
},
'@coveo/headless/case-assist': {
devWatch: path.resolve(
__dirname,
'./src/external-builds/case-assist/headless.esm.js'
),
cdn: `/headless/${headlessVersion}/case-assist/headless.esm.js`,
},
'@coveo/headless': {
devWatch: path.resolve(__dirname, './src/external-builds/headless.esm.js'),
cdn: `/headless/${headlessVersion}/headless.esm.js`,
},
'@coveo/bueno': {
devWatch: path.resolve(__dirname, './src/external-builds/bueno.esm.js'),
cdn: `/bueno/${buenoVersion}/bueno.esm.js`,
},
};

function generateAliasEntries() {
return Object.entries(packageMappings).map(([find, paths]) => ({
find,
Expand Down Expand Up @@ -268,14 +211,14 @@ export const config: Config = {
function externalizeDependenciesPlugin() {
return {
name: 'externalize-dependencies',
resolveId(source: string) {
if (packageMappings[source]) {
resolveId: (id: string) => {
if (packageMappings[id]) {
if (!isCDN) {
return false;
}

return {
id: packageMappings[source].cdn,
id: packageMappings[id].cdn,
external: 'absolute',
};
}
Expand Down
3 changes: 2 additions & 1 deletion packages/atomic/tsconfig.storybook.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
".storybook/*.tsx",
".storybook/*.jsx",
".storybook/register.tsx",
".storybook/main.mts"
".storybook/main.mts",
"scripts/packageMappings.ts"
]
}

0 comments on commit fcdf54c

Please sign in to comment.