-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Carlos Viteri
committed
Sep 12, 2024
1 parent
35638fa
commit 0674c47
Showing
6 changed files
with
191 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,59 @@ | ||
import fs from 'fs-extra' | ||
import concat from 'concat' | ||
import path from 'path' | ||
import { getDirname } from '../utils.mjs' | ||
import fs from 'fs-extra'; | ||
import concat from 'concat'; | ||
import path from 'path'; | ||
import { getDirname } from '../utils.mjs'; | ||
|
||
const __dirname = getDirname(import.meta.url) | ||
const __dirname = getDirname(import.meta.url); | ||
|
||
export const concatFiles = (StyleDictionary) => { | ||
// concat all files in buildPath to a given filename | ||
StyleDictionary.registerAction({ | ||
name: 'concat-files', | ||
do: (dictionary, config) => { | ||
fs.readdir(config.buildPath, async (error, files) => { | ||
if (error) { | ||
throw error | ||
try { | ||
// Read files from the specified build path | ||
const buildPath = path.join(__dirname, '../../', config.buildPath); | ||
const files = fs.readdirSync(buildPath); | ||
|
||
if (files.length === 0) { | ||
console.warn('No files found in the build path.'); | ||
return; | ||
} | ||
|
||
const extension = path.extname(files[0]) | ||
const allPaths = files.map(f => path.join(__dirname, '../../', config.buildPath, f)) | ||
const concatPaths = allPaths.filter(p => !p.includes('no_concat')) | ||
const noConcatPaths = allPaths.filter(p => p.includes('no_concat')) | ||
const outFile = path.join(__dirname, '../../', config.buildPath, `cdr-tokens${extension}`) | ||
// Determine the file extension from the first file | ||
const extension = path.extname(files[0]); | ||
const allPaths = files.map(f => path.join(buildPath, f)); | ||
const concatPaths = allPaths.filter(p => !path.basename(p).includes('no_concat')); | ||
const noConcatPaths = allPaths.filter(p => path.basename(p).includes('no_concat')); | ||
const outFile = path.join(buildPath, `cdr-tokens${extension}`); | ||
|
||
noConcatPaths.forEach(async (p) => { | ||
const newPath = p.replace('.no_concat', '') | ||
fs.renameSync(p, newPath) | ||
}) | ||
// Rename files with 'no_concat' in their name | ||
noConcatPaths.forEach(p => { | ||
const newPath = p.replace('.no_concat', ''); | ||
fs.renameSync(p, newPath); | ||
}); | ||
|
||
// output concat paths | ||
concat(concatPaths) | ||
.then(async (r) => | ||
fs.outputFileSync(outFile, r) | ||
).catch((err) => { | ||
console.error('Error concatenating files', err) | ||
}) | ||
// Concatenate files | ||
const result = concat.sync(concatPaths); | ||
fs.outputFileSync(outFile, result); | ||
console.log(`Successfully concatenated files into ${outFile}`); | ||
|
||
// remove concatenated files | ||
concatPaths.forEach(async (p) => { | ||
fs.removeSync(p) | ||
}) | ||
}) | ||
// Remove concatenated files | ||
concatPaths.forEach(p => { | ||
fs.removeSync(p); | ||
}); | ||
console.log('Successfully removed concatenated files'); | ||
} catch (error) { | ||
console.error('Error during file concatenation process:', error); | ||
} | ||
}, | ||
undo: async (dictionary, config) => { | ||
fs.removeSync(path.join(__dirname, '../../', config.buildPath)) | ||
undo: (dictionary, config) => { | ||
try { | ||
const buildPath = path.join(__dirname, '../../', config.buildPath); | ||
fs.removeSync(buildPath); | ||
console.log(`Successfully removed ${buildPath}`); | ||
} catch (error) { | ||
console.error('Error removing build path:', error); | ||
} | ||
} | ||
}) | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,39 @@ | ||
import fs from 'fs-extra' | ||
import path from 'path' | ||
import { getDirname } from '../utils.mjs' | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
import { getDirname } from '../utils.mjs'; | ||
|
||
const __dirname = getDirname(import.meta.url) | ||
const __dirname = getDirname(import.meta.url); | ||
|
||
export const includeDeprecateScss = (StyleDictionary) => { | ||
// concat all files in buildPath to a given filename | ||
// Register custom action for Style Dictionary | ||
StyleDictionary.registerAction({ | ||
name: 'include-deprecate-scss', | ||
do: (dictionary, config) => { | ||
const deprecateScss = path.join(__dirname, '../utilities/deprecate.scss') | ||
const outputDir = path.join(__dirname, '../../', config.buildPath, 'deprecate.scss') | ||
fs.copyFileSync(deprecateScss, outputDir) | ||
try { | ||
const deprecateScss = path.join(__dirname, '../utilities/deprecate.scss'); | ||
const outputDir = path.join(__dirname, '../../', config.buildPath); | ||
const outputFile = path.join(outputDir, 'deprecate.scss'); | ||
|
||
// Ensure the output directory exists | ||
fs.ensureDirSync(outputDir); | ||
|
||
// Copy the SCSS file | ||
fs.copyFileSync(deprecateScss, outputFile); | ||
console.log(`Successfully copied to ${outputFile}`); | ||
} catch (error) { | ||
console.error('Error including deprecate SCSS:', error); | ||
} | ||
}, | ||
undo: (dictionary, config) => { | ||
fs.removeSync(path.join(__dirname, '../../', config.buildPath)) | ||
try { | ||
const outputDir = path.join(__dirname, '../../', config.buildPath); | ||
|
||
// Remove the output directory and its contents | ||
fs.removeSync(outputDir); | ||
console.log(`Successfully removed ${outputDir}`); | ||
} catch (error) { | ||
console.error('Error removing deprecate SCSS directory:', error); | ||
} | ||
} | ||
}) | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,38 @@ | ||
import fs from 'fs-extra' | ||
import path from 'path' | ||
import { getDirname } from '../utils.mjs' | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
import { getDirname } from '../utils.mjs'; | ||
|
||
const __dirname = getDirname(import.meta.url) | ||
const __dirname = getDirname(import.meta.url); | ||
|
||
export const includeDisplayLess = (StyleDictionary) => { | ||
// concat all files in buildPath to a given filename | ||
StyleDictionary.registerAction({ | ||
name: 'include-display-less', | ||
do: (dictionary, config) => { | ||
const less = path.join(__dirname, '../utilities/display.less') | ||
const outputDir = path.join(__dirname, '../../', config.buildPath, 'display.less') | ||
fs.copyFileSync(less, outputDir) | ||
try { | ||
const lessFile = path.join(__dirname, '../utilities/display.less'); | ||
const outputDir = path.join(__dirname, '../../', config.buildPath); | ||
const outputFile = path.join(outputDir, 'display.less'); | ||
|
||
// Ensure the output directory exists | ||
fs.ensureDirSync(outputDir); | ||
|
||
// Copy the LESS file to the output directory | ||
fs.copyFileSync(lessFile, outputFile); | ||
console.log(`Successfully copied ${lessFile} to ${outputFile}`); | ||
} catch (error) { | ||
console.error('Error including display LESS file:', error); | ||
} | ||
}, | ||
undo: (dictionary, config) => { | ||
fs.removeSync(path.join(__dirname, '../../', config.buildPath)) | ||
try { | ||
const outputDir = path.join(__dirname, '../../', config.buildPath); | ||
|
||
// Remove the output directory and its contents | ||
fs.removeSync(outputDir); | ||
console.log(`Successfully removed ${outputDir}`); | ||
} catch (error) { | ||
console.error('Error removing display LESS file directory:', error); | ||
} | ||
} | ||
}) | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,38 @@ | ||
import fs from 'fs-extra' | ||
import path from 'path' | ||
import { getDirname } from '../utils.mjs' | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
import { getDirname } from '../utils.mjs'; | ||
|
||
const __dirname = getDirname(import.meta.url) | ||
const __dirname = getDirname(import.meta.url); | ||
|
||
export const includeDisplayScss = (StyleDictionary) => { | ||
StyleDictionary.registerAction({ | ||
name: 'include-display-scss', | ||
do: (dictionary, config) => { | ||
const scss = path.join(__dirname, '../utilities/display.scss') | ||
const outputDir = path.join(__dirname, '../../', config.buildPath, 'display.scss') | ||
fs.copyFileSync(scss, outputDir) | ||
try { | ||
const scssFile = path.join(__dirname, '../utilities/display.scss'); | ||
const outputDir = path.join(__dirname, '../../', config.buildPath); | ||
const outputFile = path.join(outputDir, 'display.scss'); | ||
|
||
// Ensure the output directory exists | ||
fs.ensureDirSync(outputDir); | ||
|
||
// Copy the SCSS file to the output directory | ||
fs.copyFileSync(scssFile, outputFile); | ||
console.log(`Successfully copied ${scssFile} to ${outputFile}`); | ||
} catch (error) { | ||
console.error('Error including display SCSS file:', error); | ||
} | ||
}, | ||
undo: (dictionary, config) => { | ||
fs.removeSync(path.join(__dirname, '../../', config.buildPath)) | ||
try { | ||
const outputDir = path.join(__dirname, '../../', config.buildPath); | ||
|
||
// Remove the output directory and its contents | ||
fs.removeSync(outputDir); | ||
console.log(`Successfully removed ${outputDir}`); | ||
} catch (error) { | ||
console.error('Error removing display SCSS file directory:', error); | ||
} | ||
} | ||
}) | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,38 @@ | ||
import fs from 'fs-extra' | ||
import path from 'path' | ||
import { getDirname } from '../utils.mjs' | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
import { getDirname } from '../utils.mjs'; | ||
|
||
const __dirname = getDirname(import.meta.url) | ||
const __dirname = getDirname(import.meta.url); | ||
|
||
export const includeMediaQueriesLess = (StyleDictionary) => { | ||
// concat all files in buildPath to a given filename | ||
StyleDictionary.registerAction({ | ||
name: 'include-media-queries-less', | ||
do: (dictionary, config) => { | ||
const less = path.join(__dirname, '../utilities/media-queries.less') | ||
const outputDir = path.join(__dirname, '../../', config.buildPath, 'media-queries.less') | ||
fs.copyFileSync(less, outputDir) | ||
try { | ||
const lessFile = path.join(__dirname, '../utilities/media-queries.less'); | ||
const outputDir = path.join(__dirname, '../../', config.buildPath); | ||
const outputFile = path.join(outputDir, 'media-queries.less'); | ||
|
||
// Ensure the output directory exists | ||
fs.ensureDirSync(outputDir); | ||
|
||
// Copy the LESS file to the output directory | ||
fs.copyFileSync(lessFile, outputFile); | ||
console.log(`Successfully copied ${lessFile} to ${outputFile}`); | ||
} catch (error) { | ||
console.error('Error including media queries LESS file:', error); | ||
} | ||
}, | ||
undo: (dictionary, config) => { | ||
fs.removeSync(path.join(__dirname, '../../', config.buildPath)) | ||
try { | ||
const outputDir = path.join(__dirname, '../../', config.buildPath); | ||
|
||
// Remove the output directory and its contents | ||
fs.removeSync(outputDir); | ||
console.log(`Successfully removed ${outputDir}`); | ||
} catch (error) { | ||
console.error('Error removing media queries LESS file directory:', error); | ||
} | ||
} | ||
}) | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,38 @@ | ||
import fs from 'fs-extra' | ||
import path from 'path' | ||
import { getDirname } from '../utils.mjs' | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
import { getDirname } from '../utils.mjs'; | ||
|
||
const __dirname = getDirname(import.meta.url) | ||
const __dirname = getDirname(import.meta.url); | ||
|
||
export const includeMediaQueriesScss = (StyleDictionary) => { | ||
// concat all files in buildPath to a given filename | ||
StyleDictionary.registerAction({ | ||
name: 'include-media-queries-scss', | ||
do: (dictionary, config) => { | ||
const scss = path.join(__dirname, '../utilities/media-queries.scss') | ||
const outputDir = path.join(__dirname, '../../', config.buildPath, 'media-queries.scss') | ||
fs.copyFileSync(scss, outputDir) | ||
try { | ||
const scssFile = path.join(__dirname, '../utilities/media-queries.scss'); | ||
const outputDir = path.join(__dirname, '../../', config.buildPath); | ||
const outputFile = path.join(outputDir, 'media-queries.scss'); | ||
|
||
// Ensure the output directory exists | ||
fs.ensureDirSync(outputDir); | ||
|
||
// Copy the SCSS file to the output directory | ||
fs.copyFileSync(scssFile, outputFile); | ||
console.log(`Successfully copied ${scssFile} to ${outputFile}`); | ||
} catch (error) { | ||
console.error('Error including media queries SCSS file:', error); | ||
} | ||
}, | ||
undo: (dictionary, config) => { | ||
fs.removeSync(path.join(__dirname, '../../', config.buildPath)) | ||
try { | ||
const outputDir = path.join(__dirname, '../../', config.buildPath); | ||
|
||
// Remove the output directory and its contents | ||
fs.removeSync(outputDir); | ||
console.log(`Successfully removed ${outputDir}`); | ||
} catch (error) { | ||
console.error('Error removing media queries SCSS file directory:', error); | ||
} | ||
} | ||
}) | ||
} | ||
}); | ||
}; |