Skip to content

Commit

Permalink
Revert "feat: use template engine for styles (#240)"
Browse files Browse the repository at this point in the history
This reverts commit 668989e.
  • Loading branch information
jaywcjlove authored Aug 30, 2024
1 parent 668989e commit fe666d3
Show file tree
Hide file tree
Showing 18 changed files with 218 additions and 133 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ examples/templates/dist
examples/example#211/font
lib
package-lock.json
yarn.lock
__snapshots__

### Node ###
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -655,14 +655,14 @@ Define preview web content. Example:
#### website.template
> Type: `String`
> Default value: [index.html](src/website/index.html)
> Default value: [index.ejs](src/website/index.ejs)
Custom template can customize parameters. You can define your own template based on the [default template](src/website/index.html).
Custom template can customize parameters. You can define your own template based on the [default template](src/website/index.ejs).
```js
{
website: {
template: path.join(process.cwd(), "my-template.html")
template: path.join(process.cwd(), "my-template.ejs")
}
}
```
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,15 @@
}
},
"dependencies": {
"@tsbb/copy-template-dir": "^1.4.0",
"auto-config-loader": "^1.7.4",
"cheerio": "~1.0.0-rc.12",
"colors-cli": "~1.0.28",
"del": "~7.1.0",
"ejs": "~3.1.6",
"fs-extra": "~11.2.0",
"image2uri": "^2.1.2",
"nunjucks": "^3.2.4",
"move-file": "~3.1.0",
"svg2ttf": "~6.0.3",
"svgicons2svgfont": "~14.0.0",
"svgo": "~3.3.0",
Expand All @@ -96,8 +99,8 @@
"yargs": "^17.7.2"
},
"devDependencies": {
"@types/ejs": "~3.1.0",
"@types/fs-extra": "^11.0.1",
"@types/nunjucks": "^3.2.6",
"@types/svg2ttf": "~5.0.1",
"@types/ttf2eot": "~2.0.0",
"@types/ttf2woff": "~2.0.2",
Expand Down
13 changes: 5 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference types="../src/types" />

import path from 'path';
import { fileURLToPath } from 'url';
import fs from 'fs-extra';
Expand Down Expand Up @@ -258,7 +260,6 @@ export default async (options: SvgToFontOptions = {}) => {
await fs.ensureDir(options.dist);
const unicodeObject = await createSVG(options);

/** @deprecated */
let cssToVars: string[] = [];
let cssString: string[] = [];
let cssRootVars: string[] = [];
Expand Down Expand Up @@ -321,17 +322,14 @@ export default async (options: SvgToFontOptions = {}) => {
await createSvgSymbol(options);

if (options.css) {
const styleTemplatePath = options.styleTemplates || path.resolve(__dirname, 'styles')
const outDir = typeof options.css === 'object' ? options.css.output || options.dist : options.dist;
await copyTemplate(styleTemplatePath, outDir, {
const styleTemplatePath = options.styleTemplates || (!options.useNameAsUnicode ? path.resolve(__dirname, 'styles') : path.resolve(__dirname, 'ligature-styles'));
await copyTemplate(styleTemplatePath, options.dist, {
fontname: options.fontName,
cssString: cssString.join(''),
cssToVars: cssToVars.join(''),
infoData,
fontSize: fontSize,
timestamp: new Date().getTime(),
prefix,
nameAsUnicode: options.useNameAsUnicode,
_opts: typeof options.css === 'boolean' ? {} : { ...options.css }
});
}
Expand All @@ -354,7 +352,7 @@ export default async (options: SvgToFontOptions = {}) => {
if (name === 'symbol') symbolPath = _path;
});
// default template
options.website.template = options.website.template || path.join(__dirname, 'website', 'index.html');
options.website.template = options.website.template || path.join(__dirname, 'website', 'index.ejs');
// template data
const tempData: SvgToFontOptions['website'] & {
fontname: string;
Expand Down Expand Up @@ -417,7 +415,6 @@ export default async (options: SvgToFontOptions = {}) => {
log.log(`${color.green('SUCCESS')} Created React Native Components. `);
}

return infoData;
} catch (error) {
log.log('SvgToFont:CLI:ERR:', error);
}
Expand Down
19 changes: 19 additions & 0 deletions src/ligature-styles/_{{filename}}.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@font-face {
font-family: "{{fontname}}";
src: url('{{cssPath}}{{fontname}}.eot?t={{timestamp}}'); /* IE9*/
src: url('{{cssPath}}{{fontname}}.eot?t={{timestamp}}#iefix') format('embedded-opentype'), /* IE6-IE8 */
url("{{cssPath}}{{fontname}}.woff2?t={{timestamp}}") format("woff2"),
url("{{cssPath}}{{fontname}}.woff?t={{timestamp}}") format("woff"),
url('{{cssPath}}{{fontname}}.ttf?t={{timestamp}}') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/
url('{{cssPath}}{{fontname}}.svg?t={{timestamp}}#{{fontname}}') format('svg'); /* iOS 4.1- */
}

.{{prefix}} {
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

{{cssString}}

15 changes: 15 additions & 0 deletions src/ligature-styles/_{{filename}}.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@font-face {font-family: "{{fontname}}";
src: url('{{cssPath}}{{fontname}}.eot?t={{timestamp}}'); /* IE9*/
src: url('{{cssPath}}{{fontname}}.eot?t={{timestamp}}#iefix') format('embedded-opentype'), /* IE6-IE8 */
url("{{cssPath}}{{fontname}}.woff2?t={{timestamp}}") format("woff2"),
url("{{cssPath}}{{fontname}}.woff?t={{timestamp}}") format("woff"),
url('{{cssPath}}{{fontname}}.ttf?t={{timestamp}}') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/
url('{{cssPath}}{{fontname}}.svg?t={{timestamp}}#{{fontname}}') format('svg'); /* iOS 4.1- */
}

.{{prefix}} {
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
15 changes: 15 additions & 0 deletions src/ligature-styles/_{{filename}}.module.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@font-face {font-family: "{{fontname}}";
src: url('{{cssPath}}{{fontname}}.eot?t={{timestamp}}'); /* IE9*/
src: url('{{cssPath}}{{fontname}}.eot?t={{timestamp}}#iefix') format('embedded-opentype'), /* IE6-IE8 */
url("{{cssPath}}{{fontname}}.woff2?t={{timestamp}}") format("woff2"),
url("{{cssPath}}{{fontname}}.woff?t={{timestamp}}") format("woff"),
url('{{cssPath}}{{fontname}}.ttf?t={{timestamp}}') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/
url('{{cssPath}}{{fontname}}.svg?t={{timestamp}}#{{fontname}}') format('svg'); /* iOS 4.1- */
}

.{{prefix}} {
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
15 changes: 15 additions & 0 deletions src/ligature-styles/_{{filename}}.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@font-face {font-family: "{{fontname}}";
src: url('{{cssPath}}{{fontname}}.eot?t={{timestamp}}'); /* IE9*/
src: url('{{cssPath}}{{fontname}}.eot?t={{timestamp}}#iefix') format('embedded-opentype'), /* IE6-IE8 */
url("{{cssPath}}{{fontname}}.woff2?t={{timestamp}}") format("woff2"),
url("{{cssPath}}{{fontname}}.woff?t={{timestamp}}") format("woff"),
url('{{cssPath}}{{fontname}}.ttf?t={{timestamp}}') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/
url('{{cssPath}}{{fontname}}.svg?t={{timestamp}}#{{fontname}}') format('svg'); /* iOS 4.1- */
}

.{{prefix}} {
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
15 changes: 15 additions & 0 deletions src/ligature-styles/_{{filename}}.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@font-face {font-family: "{{fontname}}";
src: url('{{cssPath}}{{fontname}}.eot?t={{timestamp}}'); /* IE9*/
src: url('{{cssPath}}{{fontname}}.eot?t={{timestamp}}#iefix') format('embedded-opentype'), /* IE6-IE8 */
url("{{cssPath}}{{fontname}}.woff2?t={{timestamp}}") format("woff2"),
url("{{cssPath}}{{fontname}}.woff?t={{timestamp}}") format("woff"),
url('{{cssPath}}{{fontname}}.ttf?t={{timestamp}}') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/
url('{{cssPath}}{{fontname}}.svg?t={{timestamp}}#{{fontname}}') format('svg'); /* iOS 4.1- */
}

.{{prefix}} {
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
5 changes: 2 additions & 3 deletions src/styles/_{{filename}}.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
url('{{cssPath}}{{fontname}}.svg?t={{timestamp}}#{{fontname}}') format('svg'); /* iOS 4.1- */
}

{% if nameAsUnicode %}.{{prefix}}{% else %}[class^="{{prefix}}-"], [class*=" {{prefix}}-"]{% endif %} {
[class^="{{prefix}}-"], [class*=" {{prefix}}-"] {
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

{% if not nameAsUnicode %}

{{cssString}}
{% endif %}
6 changes: 2 additions & 4 deletions src/styles/_{{filename}}.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
url('{{cssPath}}{{fontname}}.svg?t={{timestamp}}#{{fontname}}') format('svg'); /* iOS 4.1- */
}

{% if nameAsUnicode %}.{{prefix}}{% else %}[class^="{{prefix}}-"], [class*=" {{prefix}}-"]{% endif %} {
[class^="{{prefix}}-"], [class*=" {{prefix}}-"] {
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

{% if not nameAsUnicode %}
{{cssString}}
{% endif %}
{{cssString}}
6 changes: 2 additions & 4 deletions src/styles/_{{filename}}.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
url('{{cssPath}}{{fontname}}.svg?t={{timestamp}}#{{fontname}}') format('svg'); /* iOS 4.1- */
}

{% if nameAsUnicode %}.{{prefix}}{% else %}[class^="{{prefix}}-"], [class*=" {{prefix}}-"]{% endif %} {
[class^="{{prefix}}-"], [class*=" {{prefix}}-"] {
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

{% if not nameAsUnicode %}
:global {
{{cssString}}
}
{% endif %}
}
10 changes: 3 additions & 7 deletions src/styles/_{{filename}}.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@
url('{{cssPath}}{{fontname}}.svg?t={{timestamp}}#{{fontname}}') format('svg'); /* iOS 4.1- */
}

{% if nameAsUnicode %}.{{prefix}}{% else %}[class^="{{prefix}}-"], [class*=" {{prefix}}-"]{% endif %} {
[class^="{{prefix}}-"], [class*=" {{prefix}}-"] {
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

{% if not nameAsUnicode %}
{{ cssString }}
{% for name, value in infoData %}
${{ name }}: {{ value.encodedCode }}
{% endfor %}
{% endif %}
{{cssString}}
{{cssToVars}}
9 changes: 2 additions & 7 deletions src/styles/_{{filename}}.styl
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@
url('{{cssPath}}{{fontname}}.svg?t={{timestamp}}#{{fontname}}') format('svg'); /* iOS 4.1- */
}

{% if nameAsUnicode %}.{{prefix}}{% else %}[class^="{{prefix}}-"], [class*=" {{prefix}}-"]{% endif %} {
[class^="{{prefix}}-"], [class*=" {{prefix}}-"] {
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

{% if not nameAsUnicode %}
{{ cssString }}
{% for name, value in infoData %}
${{ name }} = {{ value.encodedCode }}
{% endfor %}
{% endif %}
{{cssString}}
5 changes: 5 additions & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="node" />

declare module '@tsbb/copy-template-dir' {
export default function(templateDir: string, targetDir: string, options: Record<string, any>, callback: (err: Error, createdFiles: string[]) => void): void;
}
Loading

0 comments on commit fe666d3

Please sign in to comment.