mirror of
https://github.com/gromlab-ru/svg-sprites.git
synced 2026-07-22 04:40:17 +03:00
feat: добавить серверную генерацию спрайтов
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
const sourceOrigin = process.env.SVG_SPRITE_SOURCE_ORIGIN
|
||||
const sourceSha256 = process.env.SVG_SPRITE_SOURCE_SHA256
|
||||
|
||||
if (!sourceOrigin || !sourceSha256) throw new Error('HTTP source origin and SHA-256 are required.')
|
||||
|
||||
export default {
|
||||
mode: 'standalone@server',
|
||||
name: 'remote-http',
|
||||
input: [
|
||||
{
|
||||
name: 'folder open',
|
||||
url: `${sourceOrigin}/sources/check.svg`,
|
||||
sha256: sourceSha256,
|
||||
},
|
||||
],
|
||||
generatedNotice: false,
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
const sourceOrigin = process.env.SVG_SPRITE_SOURCE_ORIGIN
|
||||
|
||||
if (!sourceOrigin) throw new Error('SVG_SPRITE_SOURCE_ORIGIN is required.')
|
||||
|
||||
export default {
|
||||
mode: 'standalone@server',
|
||||
name: 'remote-app',
|
||||
input: [
|
||||
'../../../../fixtures/icons/duotone.svg',
|
||||
{ name: 'check', url: `${sourceOrigin}/sources/check.svg` },
|
||||
],
|
||||
generatedNotice: false,
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
export default {
|
||||
mode: 'standalone@server',
|
||||
name: 'remote-plain',
|
||||
input: '../../../../fixtures/icons/duotone.svg',
|
||||
transform: {
|
||||
removeSize: false,
|
||||
replaceColors: false,
|
||||
addTransition: false,
|
||||
},
|
||||
generatedNotice: false,
|
||||
}
|
||||
15
integration/apps/standalone-server/package.json
Normal file
15
integration/apps/standalone-server/package.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "@svg-sprites-fixtures/standalone-server",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"sprites": "npm run sprites:mixed && npm run sprites:http && npm run sprites:plain && node verify-release.mjs",
|
||||
"sprites:mixed": "svg-sprites cases/mixed-input/svg-sprite.config.js",
|
||||
"sprites:http": "svg-sprites cases/http-only/svg-sprite.config.js",
|
||||
"sprites:plain": "svg-sprites cases/transforms-disabled/svg-sprite.config.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gromlab/svg-sprites": "file:../../.."
|
||||
}
|
||||
}
|
||||
59
integration/apps/standalone-server/verify-release.mjs
Normal file
59
integration/apps/standalone-server/verify-release.mjs
Normal file
@@ -0,0 +1,59 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { createHash } from 'node:crypto'
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
||||
const casesRoot = path.join(import.meta.dirname, 'cases')
|
||||
|
||||
function sha256(bytes) {
|
||||
return createHash('sha256').update(bytes).digest('hex')
|
||||
}
|
||||
|
||||
function verifyCase(caseName, expected) {
|
||||
const outputDir = path.join(casesRoot, caseName, '.svg-sprite')
|
||||
const manifestPath = path.join(outputDir, 'svg-sprite.manifest.json')
|
||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'))
|
||||
|
||||
assert.equal(manifest.kind, '@gromlab/svg-sprites/server')
|
||||
assert.equal(manifest.mode, 'standalone@server')
|
||||
assert.equal(manifest.target, 'server')
|
||||
assert.equal(manifest.name, expected.name)
|
||||
assert.equal(manifest.iconCount, expected.icons.length)
|
||||
assert.deepEqual(manifest.icons.map(({ name }) => name), expected.icons)
|
||||
assert.deepEqual(manifest.transform, expected.transform)
|
||||
|
||||
for (const profile of ['stack', 'stack-root-viewbox']) {
|
||||
const asset = manifest.sprites[profile]
|
||||
const filePath = path.resolve(outputDir, asset.href)
|
||||
const bytes = fs.readFileSync(filePath)
|
||||
assert.equal(bytes.byteLength, asset.byteLength)
|
||||
assert.equal(sha256(bytes), asset.sha256)
|
||||
assert.match(path.basename(filePath), new RegExp(`^sprite${profile === 'stack' ? '' : '-root-viewbox'}\\.[a-f0-9]{16}\\.svg$`))
|
||||
}
|
||||
|
||||
assert.deepEqual(fs.readdirSync(outputDir).sort().length, 3)
|
||||
assert.equal(fs.existsSync(path.join(outputDir, 'index.js')), false)
|
||||
assert.equal(fs.existsSync(path.join(path.dirname(outputDir), '.gitignore')), false)
|
||||
return manifest
|
||||
}
|
||||
|
||||
const defaults = { removeSize: true, replaceColors: true, addTransition: true }
|
||||
verifyCase('mixed-input', {
|
||||
name: 'remote-app',
|
||||
icons: ['check', 'duotone'],
|
||||
transform: defaults,
|
||||
})
|
||||
const httpManifest = verifyCase('http-only', {
|
||||
name: 'remote-http',
|
||||
icons: ['folder open'],
|
||||
transform: defaults,
|
||||
})
|
||||
assert.match(httpManifest.icons[0].id, /^icon-[a-f0-9]{16}$/)
|
||||
const plainManifest = verifyCase('transforms-disabled', {
|
||||
name: 'remote-plain',
|
||||
icons: ['duotone'],
|
||||
transform: { removeSize: false, replaceColors: false, addTransition: false },
|
||||
})
|
||||
assert.equal(plainManifest.icons[0].colors.length, 0)
|
||||
|
||||
console.log('Verified standalone@server integration cases.')
|
||||
Reference in New Issue
Block a user