forked from pd4d10/hashmd
-
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.
- Loading branch information
Showing
39 changed files
with
430 additions
and
2,377 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -3,41 +3,46 @@ | |
"version": "1.15.0", | ||
"private": true, | ||
"scripts": { | ||
"build": "norm build bytemd '@bytemd/*'", | ||
"dev": "norm serve playground", | ||
"build": "tsc --build && pnpm --filter './packages/**' build", | ||
"dev": "pnpm --filter playground dev", | ||
"docs:build": "npx vitepress build docs", | ||
"docs:dev": "npx vitepress dev docs", | ||
"docs:serve": "npx vitepress serve docs", | ||
"format": "norm format", | ||
"format": "prettier --write '**/*.{ts,tsx,json,md,svelte}' && sort-package-json package.json 'packages/*/package.json'", | ||
"postinstall": "node scripts/postinstall.mjs && npm run format && sort-json packages/*/locales/*.json", | ||
"pub": "npm run build && norm version && pnpm --recursive --registry https://registry.npmjs.org/ publish --access public", | ||
"test": "norm test bytemd" | ||
}, | ||
"prettier": { | ||
"pluginSearchDirs": [ | ||
"." | ||
], | ||
"proseWrap": "never", | ||
"semi": false, | ||
"singleQuote": true | ||
}, | ||
"devDependencies": { | ||
"@norm/cli": "^0.4.43", | ||
"@sveltejs/vite-plugin-svelte": "1.0.0-next.47", | ||
"@testing-library/jest-dom": "^5.16.4", | ||
"@testing-library/svelte": "^3.1.2", | ||
"@types/fs-extra": "^9.0.13", | ||
"@types/lodash-es": "^4.17.6", | ||
"fast-glob": "^3.2.11", | ||
"fs-extra": "^10.1.0", | ||
"jsdom": "^19.0.0", | ||
"local-pkg": "^0.4.1", | ||
"lodash-es": "^4.17.21", | ||
"mustache": "^4.2.0", | ||
"prettier": "^2.6.2", | ||
"prettier-plugin-svelte": "^2.7.0", | ||
"sass": "^1.52.2", | ||
"sort-json": "^2.0.1", | ||
"sort-package-json": "^1.57.0", | ||
"svelte": "^3.48.0", | ||
"svelte-preprocess": "^4.10.6", | ||
"svelte2tsx": "^0.5.10", | ||
"typescript": "^4.7.3", | ||
"vite": "^2.9.9" | ||
"vite": "3.0.0-alpha.9" | ||
}, | ||
"packageManager": "[email protected]", | ||
"bundlewatch": { | ||
|
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,80 @@ | ||
// @ts-check | ||
import fs from 'fs-extra' | ||
import path from 'path' | ||
import { preprocess } from 'svelte/compiler' | ||
import glob from 'fast-glob' | ||
import { build } from 'vite' | ||
import { resolveModule } from 'local-pkg' | ||
import sveltePreprocess from 'svelte-preprocess' | ||
|
||
export const sveltePreprocessor = sveltePreprocess({ | ||
typescript: true, | ||
// https://github.com/sveltejs/svelte/issues/189#issuecomment-586142198 | ||
replace: [ | ||
[/(>)[\s]*([<{])/g, '$1$2'], | ||
[/({[/:][a-z]+})[\s]*([<{])/g, '$1$2'], | ||
[/({[#:][a-z]+ .+?})[\s]*([<{])/g, '$1$2'], | ||
[/([>}])[\s]+(<|{[/#:][a-z][^}]*})/g, '$1$2'], | ||
], | ||
}) | ||
|
||
const pkgName = 'decode-named-character-reference' | ||
const resolveOptions = { | ||
alias: { | ||
// do not resolve `browser` field to make it work at SSR | ||
// https://github.com/vitejs/vite/issues/4405 | ||
[pkgName]: resolveModule(pkgName), | ||
}, | ||
} | ||
|
||
async function buildFilesForSvelte() { | ||
console.log('building svelte entry and helpers...') | ||
for (const [src, dest] of Object.entries({ | ||
'src/helpers.ts': 'helpers.js', | ||
'src/index.ts': 'svelte-entry.js', | ||
})) { | ||
await build({ | ||
build: { | ||
emptyOutDir: false, | ||
lib: { | ||
entry: src, | ||
formats: ['es'], | ||
fileName(format) { | ||
if (format === 'es') return dest | ||
throw new Error('should not be here') | ||
}, | ||
}, | ||
rollupOptions: { | ||
external: ['./helpers', /\.svelte$/], | ||
}, | ||
}, | ||
resolve: resolveOptions, | ||
}) | ||
} | ||
|
||
console.log('processing svelte files...') | ||
const files = await glob('src/*.svelte') | ||
for (let file of files) { | ||
const dest = file.replace('src/', 'dist/') | ||
await fs.ensureDir(path.dirname(dest)) | ||
|
||
if (fs.statSync(file).isDirectory()) return | ||
|
||
if (file.endsWith('.svelte')) { | ||
const source = await fs.readFile(file, 'utf8') | ||
const item = await preprocess(source, sveltePreprocessor, { | ||
filename: file, | ||
}) | ||
await fs.writeFile( | ||
dest, | ||
item.code.replace('<script lang="ts">', '<script>') | ||
) | ||
} | ||
} | ||
|
||
console.log('processing style files (backward compatibility)...') | ||
await fs.move('dist/style.css', 'dist/index.css') | ||
await fs.copy('dist/index.css', 'dist/index.min.css') | ||
} | ||
|
||
buildFilesForSvelte() |
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,16 @@ | ||
// @ts-check | ||
import { defineConfig } from 'tsdv' | ||
import { svelte } from '@sveltejs/vite-plugin-svelte' | ||
import { sveltePreprocessor } from './build.mjs' | ||
|
||
// nullish coalescing in es2020 | ||
// TODO: 'decode-named-character-reference' | ||
export default defineConfig({ | ||
target: 'es2019', | ||
tsc: false, | ||
plugins: [ | ||
svelte({ | ||
preprocess: [sveltePreprocessor], | ||
}), | ||
], | ||
}) |
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,7 @@ | ||
// @ts-check | ||
import { defineConfig } from 'tsdv' | ||
|
||
export default defineConfig({ | ||
target: 'es2019', | ||
tsc: false, | ||
}) |
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,7 @@ | ||
// @ts-check | ||
import { defineConfig } from 'tsdv' | ||
|
||
export default defineConfig({ | ||
target: 'es2019', | ||
tsc: false, | ||
}) |
Oops, something went wrong.