Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added js to publish #4237

Merged
merged 3 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
50 changes: 40 additions & 10 deletions packages/workspace-plugins/src/executors/build/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { ExecutorContext } from '@nrwl/devkit';
import { copyFileSync, existsSync, readFileSync, rmSync, writeFileSync } from 'fs';
import glob from 'glob';
import { processWithPostCss } from '../shared/postcss';
import { mkdirpSync } from 'fs-extra';
import { parse } from 'path';

const packageJson = JSON.parse(readFileSync('package.json', 'utf-8'));
const versions = {
Expand All @@ -15,11 +17,12 @@ const versions = {
export default async function runExecutor(options: BuildExecutorSchema, context: ExecutorContext) {
const projectName = <string>context.projectName;
if (existsSync(options.outputPath)) {
rmSync(options.outputPath, {recursive: true});
rmSync(options.outputPath, { recursive: true });
}
const compilationOutputPath = `${options.outputPath}/dist`;

const projectJson = context.projectGraph?.nodes[projectName].data;
execSync(`npx sass -q --no-source-map --style expanded ${options.source}:${compilationOutputPath}`, {stdio: 'inherit'});
execSync(`npx sass -q --no-source-map --style expanded ${options.source}:${compilationOutputPath}`, { stdio: 'inherit' });
const assetsCopyResult = await copyAssets({
assets: options.assets || [],
outputPath: options.outputPath,
Expand All @@ -28,15 +31,8 @@ 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});
const outputFiles = glob.sync(`${compilationOutputPath}/**/*.css`, { nodir: true });

for (const file of outputFiles) {
const commit = await processWithPostCss({
Expand All @@ -48,6 +44,40 @@ 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