Ver Fonte

chore:format scss compiler code

代强 há 4 anos atrás
pai
commit
3c87737fb7

+ 5 - 5
packages/semi-scss-compile/src/bin.ts

@@ -1,7 +1,7 @@
 #!/usr/bin/env node
 
 import arg from "arg";
-import {compile} from "./index";
+import { compile } from "./index";
 
 const main = () => {
     const userArgs = arg({
@@ -14,16 +14,16 @@ const main = () => {
         "-t": "--theme",
         "-o": "--output",
         "-m": "--min"
-    }, {permissive: true});
-    const {"--foundation": foundationPath, '--theme': themePath, '--output': outputPath, '--min': isMin} = userArgs;
+    }, { permissive: true });
+    const { "--foundation": foundationPath, '--theme': themePath, '--output': outputPath, '--min': isMin } = userArgs;
     console.log(`foundationPath: ${foundationPath},\nthemePath: ${themePath},\noutputPath: ${outputPath}\n`);
     if (foundationPath && themePath && outputPath) {
         compile(foundationPath, themePath, outputPath, {
             isMin
         });
     } else {
-        console.error('Error: lack of args.')
+        console.error('Error: lack of args.');
     }
-}
+};
 
 main();

+ 3 - 3
packages/semi-scss-compile/src/index.ts

@@ -9,12 +9,12 @@ export interface Options {
     isMin?: boolean,
 }
 
-const compile = (foundationPath: string, themePath: string, outputPath: string, {isMin = false}: Options = {}) => {
+const compile = (foundationPath: string, themePath: string, outputPath: string, { isMin = false }: Options = {}) => {
     const scssMap = generateScssMap(foundationPath, themePath);
-    const tempDir = writeFile(scssMap)
+    const tempDir = writeFile(scssMap);
     const result = compilerFromScssMap(path.join(tempDir, 'index.scss'), isMin);
     fs.outputFileSync(outputPath, result.css);
-}
+};
 
 
 export {

+ 4 - 3
packages/semi-scss-compile/src/utils/compiler.ts

@@ -2,8 +2,9 @@ import sass from 'sass';
 
 
 const compile = (entryScssPath: string, isMin: boolean = false) => {
-    const result = sass.renderSync({file: entryScssPath, outputStyle: isMin ? 'compressed' : 'expanded'});
-    return result
-}
+    const result = sass.renderSync({ file: entryScssPath, outputStyle: isMin ? 'compressed' : 'expanded' });
+    return result;
+};
 
 export default compile;
+

+ 9 - 9
packages/semi-scss-compile/src/utils/generateSCSSMap.ts

@@ -1,8 +1,8 @@
 import path from 'path';
 import fs from "fs-extra";
-import {set} from 'lodash';
+import { set } from 'lodash';
 
-const lodash = {set};
+const lodash = { set };
 
 const generateComponentsScssMap = (foundationPath: string) => {
     const foundationComponentList = fs.readdirSync(foundationPath);
@@ -14,23 +14,23 @@ const generateComponentsScssMap = (foundationPath: string) => {
             const componentPath = fileAbsolutePath;
             const scssFileList = fs.readdirSync(componentPath).filter((fileName) => fileName.endsWith('.scss'));
             scssFileList.forEach(scssFileName => {
-                const scssRaw = fs.readFileSync(path.join(componentPath, scssFileName), {encoding: 'utf-8'});
+                const scssRaw = fs.readFileSync(path.join(componentPath, scssFileName), { encoding: 'utf-8' });
                 lodash.set(componentScssMap, [fileName, scssFileName], scssRaw);
-            })
+            });
         }
     });
     return componentScssMap;
-}
+};
 
 
 const generateThemeScssMap = (themePath: string) => {
     const fileList = ['_font.scss', '_palette.scss', 'global.scss', 'index.scss', 'local.scss', 'mixin.scss', 'variables.scss'] as const;
-    const themeScssMap: { [key in typeof fileList[number]]?: string } = {}
+    const themeScssMap: { [key in typeof fileList[number]]?: string } = {};
     for (const fileName of fileList) {
         const scssAbsolutePath = path.join(themePath, 'scss', fileName);
         if (fs.existsSync(scssAbsolutePath)) {
             //in theme folder
-            themeScssMap[fileName] = fs.readFileSync(scssAbsolutePath, {encoding: "utf8"});
+            themeScssMap[fileName] = fs.readFileSync(scssAbsolutePath, { encoding: "utf8" });
         }
     }
     // console.log(themeScssMap)
@@ -41,7 +41,7 @@ const generateScssMap = (foundationPath: string, themePath: string) => {
     return {
         components: generateComponentsScssMap(foundationPath),
         theme: generateThemeScssMap(themePath)
-    }
-}
+    };
+};
 
 export default generateScssMap;

+ 13 - 13
packages/semi-scss-compile/src/utils/writeFile.ts

@@ -2,16 +2,16 @@ import fs from 'fs-extra';
 import path from 'path';
 import os from 'os';
 import generateScssMap from "./generateSCSSMap";
-import {cloneDeep, omit} from "lodash";
+import { cloneDeep, omit } from "lodash";
 
-const lodash = {cloneDeep, omit};
+const lodash = { cloneDeep, omit };
 
 const writeComponentScss = (scssMap: { [p: string]: { [p: string]: string } }, tempDir: string) => {
     for (const componentName of Object.keys(scssMap)) {
         const componentDirPath = path.join(tempDir, 'components', componentName);
         fs.emptyDirSync(componentDirPath);
         for (const scssFileName of Object.keys(scssMap[componentName])) {
-            fs.writeFileSync(path.join(componentDirPath, scssFileName), scssMap[componentName][scssFileName], {encoding: 'utf-8'});
+            fs.writeFileSync(path.join(componentDirPath, scssFileName), scssMap[componentName][scssFileName], { encoding: 'utf-8' });
         }
     }
     return;
@@ -22,32 +22,32 @@ const writeThemeScss = (scssMap: (ReturnType<typeof generateScssMap>)['theme'],
     fs.emptyDirSync(themeDirPath);
 
     for (const scssFileName of Object.keys(scssMap)) {
-        fs.writeFileSync(path.join(themeDirPath, scssFileName), scssMap[scssFileName as keyof typeof scssMap] as string, {encoding: "utf8"});
+        fs.writeFileSync(path.join(themeDirPath, scssFileName), scssMap[scssFileName as keyof typeof scssMap] as string, { encoding: "utf8" });
     }
     return;
-}
+};
 
 const preProcessScssMap = (scssMapOrigin: ReturnType<typeof generateScssMap>) => {
     const scssMap = lodash.cloneDeep(scssMapOrigin);
 
     //----- generate entry -----
     let compilerEntryContent = '';
-    compilerEntryContent += `@import "./theme/index.scss";\n`
+    compilerEntryContent += `@import "./theme/index.scss";\n`;
     compilerEntryContent += `@import "./theme/global.scss";\n`;
 
     for (const componentName of Object.keys(scssMap['components'])) {
         let scssFileName = `${componentName}.scss`;
         //edge case portal keyframes, cause their folderName and scssFilename not match.
         if (componentName === '_portal') {
-            scssFileName = 'portal.scss'
+            scssFileName = 'portal.scss';
         } else if (componentName === 'keyframes') {
-            scssFileName = 'rotate.scss'
+            scssFileName = 'rotate.scss';
         }
         compilerEntryContent += `@import "./components/${componentName}/${scssFileName}";\n`;
     }
     //edge case for iconButton and textarea
-    compilerEntryContent += `@import "./components/button/iconButton.scss";\n`
-    compilerEntryContent += `@import "./components/input/textarea.scss";\n`
+    compilerEntryContent += `@import "./components/button/iconButton.scss";\n`;
+    compilerEntryContent += `@import "./components/input/textarea.scss";\n`;
     //----- generate entry end -----
 
 
@@ -69,7 +69,7 @@ const preProcessScssMap = (scssMapOrigin: ReturnType<typeof generateScssMap>) =>
         },
         index: compilerEntryContent
     };
-}
+};
 
 
 const writeFile = (scssMap: ReturnType<typeof generateScssMap>, tempDir: string = path.join(os.tmpdir(), `semi_scss_compile_${Date.now()}`)) => {
@@ -79,8 +79,8 @@ const writeFile = (scssMap: ReturnType<typeof generateScssMap>, tempDir: string
     writeComponentScss(finalScssMapWaitForCompiling["components"], tempDir);
     writeThemeScss(finalScssMapWaitForCompiling['theme'], tempDir);
     //write compile entry
-    fs.writeFileSync(path.join(tempDir, 'index.scss'), finalScssMapWaitForCompiling['index'], {encoding: "utf8"});
+    fs.writeFileSync(path.join(tempDir, 'index.scss'), finalScssMapWaitForCompiling['index'], { encoding: "utf8" });
     return tempDir;
-}
+};
 
 export default writeFile;