forked from Viima/jquery-comments
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance build (compact CSS), add 'AttachmentModel' interface
- Loading branch information
Showing
14 changed files
with
117 additions
and
53 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
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
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import MagicString, {SourceMap} from 'magic-string'; | ||
import {readFileSync, writeFileSync} from 'node:fs'; | ||
|
||
let stylesheet: string = ''; | ||
let bundle: string = ''; | ||
|
||
try { | ||
stylesheet = readFileSync('./dist/css/stylesheet.js', 'utf8'); | ||
bundle = readFileSync('./dist/bundle/comments-element-esm.js', 'utf8'); | ||
} catch (e) { | ||
console.error(e); | ||
process.exit(1); | ||
} | ||
|
||
const stylesheetMagicString: MagicString = compactCss(stylesheet); | ||
const stylesheetCode: string = stylesheetMagicString.toString(); | ||
const stylesheetMap: SourceMap = stylesheetMagicString.generateMap({file: 'stylesheet.js', source: '../../src/css/stylesheet.ts'}); | ||
const bundleMagicString: MagicString = compactCss(bundle); | ||
const bundleCode: string = bundleMagicString.toString(); | ||
const bundleMap: SourceMap = bundleMagicString.generateMap({file: 'comments-element-esm.js'}); | ||
|
||
try { | ||
writeFileSync('./dist/css/stylesheet.js', stylesheetCode, 'utf8'); | ||
writeFileSync('./dist/css/stylesheet.js.map', stylesheetMap.toString(), 'utf8'); | ||
writeFileSync('./dist/bundle/comments-element-esm.js', bundleCode, 'utf8'); | ||
writeFileSync('./dist/bundle/comments-element-esm.js.map', bundleMap.toString(), 'utf8'); | ||
} catch (e) { | ||
console.error(e); | ||
process.exit(1); | ||
} | ||
|
||
function compactCss(source: string): MagicString { | ||
const magicString: MagicString = new MagicString(source); | ||
|
||
// Primitive regexp to select CSS strings to minify | ||
const multiLineCssString: RegExp = /tagNoop\s*`\s*[a-z*.#/][^`]+\{[^`]+\}\s*`/gm; | ||
return magicString.replaceAll(multiLineCssString, css => css | ||
.replace(/\s+/gm, ' ') | ||
.replace(/tagNoop\s*`/g, '`') | ||
.trim()); | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Noop tagger used just to tag own CSS literals. | ||
*/ | ||
export function tagNoop(...args: [TemplateStringsArray, ...(string | number)[]]): string { | ||
let s: string = args[0][0]; | ||
for (let i: number = 1, l = args.length; i < l; i++) | ||
s += arguments[i] + args[0][i]; | ||
return s; | ||
} |
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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {describe, expect, it} from '@jest/globals'; | ||
import {tagNoop} from '../../src/css/tag-noop.js'; | ||
|
||
describe('tagNoop', () => { | ||
it('Should return unchanged string', () => { | ||
const four: string = '4'; | ||
expect(tagNoop`${1}23${four}`).toEqual('1234'); | ||
}); | ||
}); |
Oops, something went wrong.