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

refactored to support fomantic ui packages. #25

Merged
merged 1 commit into from
Aug 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 55 additions & 37 deletions packages/css-patch/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,71 @@ const path = require("path");

const nodeModulesPath = path.resolve(process.cwd(), "node_modules");

const hasPackage = packageName => {
return fs.existsSync(path.resolve(nodeModulesPath, packageName));
const hasPackages = packageNames => {
for (const packageName of packageNames) {
if (fs.existsSync(path.resolve(nodeModulesPath, packageName))) {
return packageName;
}
}

return undefined;
};

const replaceDoubleSemiColon = input =>
input.replace("utf-8;;base64", "utf-8;base64");

const run = async () => {
if (hasPackage("semantic-ui-less")) {
console.log(logSymbols.info, `Detected "semantic-ui-less" package...`);

const fileToPatchPath = path.resolve(
nodeModulesPath,
"semantic-ui-less",
"themes",
"default",
"elements",
"step.overrides"
);

if (fs.existsSync(fileToPatchPath)) {
fs.writeFileSync(
fileToPatchPath,
replaceDoubleSemiColon(
fs.readFileSync(fileToPatchPath, { encoding: "utf8" })
)
);
console.log(logSymbols.info, `Patch was successfully applied`);
} else {
const fixFiles = (filesToPatch, packageName) => {
filesToPatch.forEach(fileToPatchPath => {
if (!fs.existsSync(fileToPatchPath)) {
console.log(
logSymbols.error,
chalk.bgRed.bold(
`Failed to find "${path.resolve(
process.cwd(),
fileToPatchPath
)}", please check your installation of "semantic-ui-less"`
)}", please check your installation of "${packageName}"`
)
);

return;
}
} else if (hasPackage("semantic-ui-css")) {

fs.writeFileSync(
fileToPatchPath,
replaceDoubleSemiColon(
fs.readFileSync(fileToPatchPath, { encoding: "utf8" })
)
);
});

console.log(logSymbols.info, `Patch was successfully applied`);
}

const run = () => {
const lessPackage = hasPackages(["semantic-ui-less", "fomantic-ui-less"]);
if (lessPackage !== undefined) {
console.log(logSymbols.info, `Detected "${lessPackage}" package...`);

const filesToPatchPath = [
path.resolve(
nodeModulesPath,
lessPackage,
"themes",
"default",
"elements",
"step.overrides"
),
];

fixFiles(filesToPatchPath, lessPackage);

return;
}

const cssPackage = hasPackages(["semantic-ui-css", "fomantic-ui-css"]);
if (cssPackage !== undefined) {
console.log(logSymbols.info, `Detected "${cssPackage}" package...`);

const filesToPatchPath = [
path.resolve(nodeModulesPath, "semantic-ui-css", "semantic.css"),
path.resolve(nodeModulesPath, "semantic-ui-css", "semantic.min.css"),
Expand All @@ -62,19 +87,12 @@ const run = async () => {
)
];

filesToPatchPath.forEach(fileToPatchPath => {
fs.writeFileSync(
fileToPatchPath,
replaceDoubleSemiColon(
fs.readFileSync(fileToPatchPath, { encoding: "utf8" })
)
);
});
fixFiles(filesToPatchPath, cssPackage);

console.log(logSymbols.info, `Patch was successfully applied`);
} else {
console.log(logSymbols.info, `No supported packages found`);
return;
}

console.log(logSymbols.info, `No supported packages found`);
};

module.exports = {
Expand Down