postcss-font-grabber
Advanced tools
Comparing version 3.0.0-alpha.2 to 3.0.0-alpha.3
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -17,5 +8,4 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const fs_1 = __importDefault(require("fs")); | ||
const crypto_1 = require("crypto"); | ||
const path_1 = __importDefault(require("path")); | ||
const util_1 = require("util"); | ||
const crypto_1 = require("crypto"); | ||
function getOrDefault(object, key, defaultValue) { | ||
@@ -65,26 +55,10 @@ if (object[key] === undefined) { | ||
function makeDirectoryRecursively(directoryPath) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const fsStat = util_1.promisify(fs_1.default.stat); | ||
const fsMkdir = util_1.promisify(fs_1.default.mkdir); | ||
const pathParts = path_1.default.resolve(directoryPath).split(path_1.default.sep); | ||
const firstPart = pathParts.shift(); | ||
yield pathParts.reduce((result, current) => __awaiter(this, void 0, void 0, function* () { | ||
const resultString = yield result; | ||
const currentPath = `${resultString}${path_1.default.sep}${current}`; | ||
try { | ||
yield fsStat(currentPath); | ||
} | ||
catch (e) { | ||
if (e.code === 'ENOENT') { | ||
yield fsMkdir(currentPath); | ||
} | ||
else { | ||
throw e; | ||
} | ||
} | ||
return currentPath; | ||
}), Promise.resolve(firstPart)); | ||
}); | ||
return new Promise((resolve, reject) => fs_1.default.mkdir(path_1.default.normalize(directoryPath), { recursive: true }, error => { | ||
if (error) { | ||
return reject(error); | ||
} | ||
resolve(); | ||
})); | ||
} | ||
exports.makeDirectoryRecursively = makeDirectoryRecursively; | ||
//# sourceMappingURL=helpers.js.map |
{ | ||
"name": "postcss-font-grabber", | ||
"version": "3.0.0-alpha.2", | ||
"version": "3.0.0-alpha.3", | ||
"description": "It grabs remote font files and update your CSS, just like that.", | ||
@@ -41,5 +41,7 @@ "author": "AaronJan <aaronjan@qq.com>", | ||
"@types/jest": "^23.3.14", | ||
"@types/node": "^12.19.15", | ||
"@types/node": "^14.14.22", | ||
"@types/sinon": "^9.0.10", | ||
"coveralls": "^3.1.0", | ||
"css-loader": "^5.0.1", | ||
"file-loader": "^6.2.0", | ||
"gulp": "^4.0.2", | ||
@@ -49,7 +51,10 @@ "gulp-postcss": "^9.0.0", | ||
"postcss": "^8.0.0", | ||
"postcss-loader": "^5.0.0", | ||
"prettier": "^2.2.1", | ||
"rimraf": "^3.0.2", | ||
"sinon": "^9.2.4", | ||
"style-loader": "^2.0.0", | ||
"ts-jest": "^26.5.0", | ||
"typescript": "^4.1.3" | ||
"typescript": "^4.1.3", | ||
"webpack": "^5.20.1" | ||
}, | ||
@@ -56,0 +61,0 @@ "peerDependencies": { |
@@ -34,6 +34,7 @@ <h1 align=center> | ||
- Download font files concurrently | ||
- Infer font file extension from HTTP response header (Thanks to [@FTWinston](https://github.com/FTWinston)) | ||
## Installation | ||
> Requires: `Node >= 8.0`, `postcss 8.*` | ||
> Requires: `Node >= 10.0`, `postcss 8.*` | ||
@@ -44,33 +45,31 @@ ``` | ||
## Usages | ||
## Options | ||
### Options | ||
Function `postcssFontGrabber` takes an object of options as parameter, like: | ||
```typescript | ||
import { postcssFontGrabber, FontSpec } from 'postcss-font-grabber'; | ||
import { Readable } from 'stream'; | ||
```javascript | ||
import { postcssFontGrabber } from 'postcss-font-grabber'; | ||
postcssFontGrabber({ | ||
// The path of the source CSS directory. | ||
// Normally you don't have to set this. | ||
cssSrc: 'src/css/', | ||
cssDest: 'dist/', | ||
fontDest: 'dist/fonts/', | ||
}); | ||
``` | ||
// The path of the CSS output directory. | ||
// You have to specify this manually, PFG needs this to calculate relative | ||
// path. | ||
cssDest: 'src/css/', | ||
| Name | Type | Default | Description | | ||
| :------: | :----------------------------------------------------------------------: | :----------------------------------- | :-------------------------------------------------- | | ||
| cssSrc | `string` | `opts.from` from `PostCSS`'s setting | The root directory path of all CSS files | | ||
| cssDest | `string` | `opts.to` from `PostCSS`'s setting | The directory where the transpiled CSS files are in | | ||
| fontDest | `string` | the same as `cssDest` | The directory where the downloaded fonts stored | | ||
| download | `(fontSpec: FontSpec) => Promise<{ data: Readable, mimeType?: string }>` | - | Custom function to download font files | | ||
// The directory to store the downloaded font files. | ||
// It's the same as `cssDest` by default. | ||
fontDest: 'tmp/css/fonts/', | ||
You can import types as shown above: | ||
// Custom function to download font files. | ||
// Optional. | ||
download: async (fontSpec: FontSpec) => ({ | ||
data: Readable.from(['font file content']), | ||
mimeType: 'application/font-woff2', | ||
}), | ||
}), | ||
```typescript | ||
import { FontSpec, Downloader, DownloadResult } from 'postcss-font-grabber'; | ||
``` | ||
## Usages | ||
### With Gulp | ||
@@ -101,3 +100,3 @@ | ||
> This example is using `Webpack 4` with these packages: | ||
> This example is using `Webpack 5` with these packages: | ||
> | ||
@@ -122,21 +121,7 @@ > - [postcss-loader](https://github.com/postcss/postcss-loader) | ||
{ | ||
test: /\.css$/, | ||
exclude: /node_modules/, | ||
use: [ | ||
{ | ||
loader: 'style-loader', | ||
}, | ||
{ | ||
loader: 'css-loader', | ||
options: { | ||
importLoaders: 1, | ||
}, | ||
}, | ||
{ | ||
loader: 'postcss-loader', | ||
}, | ||
], | ||
test: /\.css$/i, | ||
use: ['style-loader', 'css-loader', 'postcss-loader'], | ||
}, | ||
{ | ||
test: /\.(woff|woff2|eot|ttf|otf)$/, | ||
test: /\.(woff|woff2|eot|ttf|otf)$/i, | ||
use: ['file-loader'], | ||
@@ -152,3 +137,3 @@ }, | ||
```javascript | ||
import postcssFontGrabber from 'postcss-font-grabber'; | ||
import { postcssFontGrabber } from 'postcss-font-grabber'; | ||
@@ -159,6 +144,7 @@ module.exports = { | ||
cssSrc: 'src/css/', | ||
// When using with `Webpack` you must set `cssDest` as the same as `cssSrc` | ||
// since `Webpack` doesn't output CSS files directly, when done with | ||
// `PostCSS`, `Webpack` use `file-loader` to transpile local file | ||
// references in the CSS. | ||
// When using with `Webpack` you must set `cssDest` as the same as `cssSrc`, | ||
// since `Webpack` kept updated CSS files in memory, your source files will | ||
// be fine. | ||
// When `PostCSS` is done its job, `Webpack` then use `file-loader` to | ||
// embedding font file references into the dist file. | ||
cssDest: 'src/css/', | ||
@@ -175,21 +161,2 @@ fontDest: 'tmp/css/fonts/', | ||
## Options | ||
Function `postcssFontGrabber` takes an object of options as parameter: | ||
```javascript | ||
postcssFontGrabber({ | ||
cssSrc: 'src/css/', | ||
cssDest: 'dist/', | ||
fontDest: 'dist/fonts/', | ||
}); | ||
``` | ||
| Name | Type | Default | Description | | ||
| :------: | :-------: | :----------------------------------- | :-------------------------------------------------------------- | | ||
| cssSrc | {string} | `opts.from` from `PostCSS`'s setting | The root directory path of all CSS files | | ||
| cssDest | {string} | `opts.to` from `PostCSS`'s setting | The directory where the transpiled CSS files are in | | ||
| fontDest | {string} | the same as `cssDest` | The directory where the downloaded fonts stored | | ||
| mkdir | {boolean} | `true` | whether to create non-existing directories automatically or not | | ||
## Advanced Usages | ||
@@ -196,0 +163,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56093
19
554
170