Skip to content

Commit

Permalink
issue-#1 - Added util method.
Browse files Browse the repository at this point in the history
- Added 'position' css generator.
  • Loading branch information
elycruz committed Sep 22, 2022
1 parent fea8f52 commit 36f3451
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
2 changes: 2 additions & 0 deletions scripts/gen-css/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const
{genJustifyContentCss} = require('./justify-content'),
{genAlignItemsCss} = require('./align-items'),
{genGridCss} = require('./grid'),
{genPositionCss} = require('./position'),
{genSpacingCss} = require('./spacing');

(async () => Promise.all([
Expand All @@ -18,6 +19,7 @@ const
genDisplayCss(),
genGridCss(),
genJustifyContentCss(),
genPositionCss(),
genSpacingCss(),
]).catch(console.error)
)();
35 changes: 35 additions & 0 deletions scripts/gen-css/position.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* position.js
*
* Generates `position` property classes (`.x-position-absolute` etc.).
*/
const fs = require('fs'),
path = require('path'),
{log, error} = console,

genPositionCss = () => {
const fileName = 'position.css',
outputFilePath = path.join(__dirname, `../../src/css/modules/${fileName}`);
const out = [
'static',
'relative',
'absolute',
'sticky',
'fixed',
].map(k => `.x-position-${k} {
position: ${k};
}`);

const content =
`/**
* ${fileName}
*/
${out.join('\n\n')}\n`;
return fs.promises.writeFile(outputFilePath, content)
.then(
() => log(`file ${fileName} written successfully`),
error
);
};

module.exports = {genPositionCss};
34 changes: 34 additions & 0 deletions scripts/utils/genCssPropClasses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* justify-content.js
*
* Generates `justify-content` property classes (`.x-justify-space-between, .x-jc-space-between` etc.).
*/
const fs = require('fs'),
path = require('path'),
{log, error} = console;

/**
* Writes property values as css classes, for given `propName` -
* Resulting content is written to given filePath
*/
const genCssPropClasses = (propName, values, outputFilePath) => {
const out = values.reduce((agg, k) => agg + `.x-${propName}-${k} {
${propName}: ${k};
}\n`, '');
const content =
`/**
* ${outputFilePath}
*/
${out.join('\n\n')}\n`
;
return fs.promises.writeFile(outputFilePath, content)
.then(
() => log(`file ${outputFilePath} written successfully`),
error
);
};

module.exports = {
genCssPropClasses
}

0 comments on commit 36f3451

Please sign in to comment.