Skip to content

Commit

Permalink
feat(styles): add js exports from package.json [ci visual]
Browse files Browse the repository at this point in the history
  • Loading branch information
N1XUS committed Feb 13, 2023
1 parent 8f01019 commit 83b4847
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 12 deletions.
3 changes: 2 additions & 1 deletion packages/styles/src/horizontal-navigation.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import './new-settings';
@import './mixins';

$block: fd-horizontal-navigation;
$block: #{$fd-namespace}-horizontal-navigation;

.#{$block} {
@include fd-reset();
Expand Down
3 changes: 2 additions & 1 deletion packages/styles/src/icon-tab-bar.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import './new-settings';
@import './mixins';

$block: fd-icon-tab-bar;
$block: #{$fd-namespace}-icon-tab-bar;
$fd-icon-tab-bar-icon-spacing: 0.188rem !default;
$fd-icon-tab-bar-list-padding-right: 1rem !default;
$fd-icon-tab-bar-icon-circle-size: 2.75rem !default;
Expand Down
3 changes: 2 additions & 1 deletion packages/styles/src/illustrated-message.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import './new-settings';
@import 'mixins/mixins';

$block: fd-illustrated-message;
$block: #{$fd-namespace}-illustrated-message;

.#{$block} {
--illustrationW: 20rem;
Expand Down
3 changes: 2 additions & 1 deletion packages/styles/src/scrollbar.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import './new-settings';
@import "mixins/mixins";

$block: fd-scrollbar;
$block: #{$fd-namespace}-scrollbar;

.#{$block} {
@include fd-reset();
Expand Down
3 changes: 2 additions & 1 deletion packages/styles/src/splitter.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import './new-settings';
@import "mixins/mixins";

$block: fd-splitter;
$block: #{$fd-namespace}-splitter;

@mixin fd-splitter-gradient($deg) {
background: linear-gradient($deg, transparent, var(--fdSplitter_Resizer_Decoration_Background));
Expand Down
31 changes: 24 additions & 7 deletions packages/workspace-plugins/src/executors/build/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ export default async function runExecutor(options: BuildExecutorSchema, context:
if (!assetsCopyResult.success) {
return assetsCopyResult;
}
let projectPackageJsonContent = readFileSync(`${projectJson.root}/package.json`, 'utf-8');
Object.entries(versions).forEach(([key, value]) => {
projectPackageJsonContent = projectPackageJsonContent.replace(new RegExp(key, 'g'), value);
});
writeFileSync(`${options.outputPath}/package.json`, projectPackageJsonContent);
const projectPackageJson = JSON.parse(projectPackageJsonContent);
copyFileSync(`./LICENSES/${projectPackageJson.license}.txt`, `${options.outputPath}/LICENSE`);

const outputFiles = glob.sync(`${compilationOutputPath}/**/*.css`, { nodir: true });

Expand All @@ -50,17 +43,41 @@ export default async function runExecutor(options: BuildExecutorSchema, context:
});
commit();
}

let projectPackageJsonContent = readFileSync(`${projectJson.root}/package.json`, 'utf-8');
const projectPackageJson = JSON.parse(projectPackageJsonContent);

projectPackageJson['exports'] = projectPackageJson['exports'] || {};

const files = glob.sync(`${compilationOutputPath}/**/*.css`);

for (const file of files) {
const content = readFileSync(file, 'utf-8');
const filePath = file.replace(new RegExp(`^${compilationOutputPath}(.*).css$`), `${compilationOutputPath}/js$1.mjs`);
const typesPath = file.replace(new RegExp(`^${compilationOutputPath}(.*).css$`), `${compilationOutputPath}/js$1.d.ts`);
const exportsPath = file.replace(new RegExp(`^${compilationOutputPath}(.*).css$`), `./dist/js$1`);
const defaultExport = file.replace(new RegExp(`^${compilationOutputPath}(.*).css$`), `./dist/js$1.mjs`);
projectPackageJson['exports'][exportsPath] = {
types: file.replace(new RegExp(`^${compilationOutputPath}(.*).css$`), `./dist/js$1.d.ts`),
esm2020: defaultExport,
default: defaultExport
}
mkdirpSync(parse(filePath).dir);
writeFileSync(filePath, `export default { cssSource: \`${content}\` };`);
writeFileSync(typesPath, `declare const _default: { cssSource: string }; export default _default;`);
}

projectPackageJsonContent = JSON.stringify(projectPackageJson, null, 4);

console.log(projectPackageJsonContent);

Object.entries(versions).forEach(([key, value]) => {
projectPackageJsonContent = projectPackageJsonContent.replace(new RegExp(key, 'g'), value);
});
writeFileSync(`${options.outputPath}/package.json`, projectPackageJsonContent);

copyFileSync(`./LICENSES/${projectPackageJson.license}.txt`, `${options.outputPath}/LICENSE`);

return {
success: true
};
Expand Down

0 comments on commit 83b4847

Please sign in to comment.