From 250dbd5fb972d100c03efa6994a4e5390837df90 Mon Sep 17 00:00:00 2001 From: vandeurenglenn Date: Sat, 4 Nov 2023 08:19:52 +0100 Subject: [PATCH 1/7] Fix fonts build step on windows Use built-in node modules --- packages/lit-dev-content/package.json | 3 ++- packages/lit-dev-content/scripts/fonts.js | 27 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 packages/lit-dev-content/scripts/fonts.js diff --git a/packages/lit-dev-content/package.json b/packages/lit-dev-content/package.json index e5c581fad..17d3eb401 100644 --- a/packages/lit-dev-content/package.json +++ b/packages/lit-dev-content/package.json @@ -6,6 +6,7 @@ "author": "Google LLC", "license": "BSD-3-Clause", "main": "_site/index.html", + "type": "module", "scripts": { "fonts:manrope": "wireit", "build": "wireit", @@ -104,7 +105,7 @@ ] }, "fonts:manrope": { - "command": "rm -rf temp && mkdir -p site/fonts/manrope && git clone https://github.com/sharanda/manrope.git temp/manrope && cd temp/manrope && git checkout 9ffbc349f4659065b62f780fe6e9d5a93518bd95 && cp fonts/web/*.woff2 ../../site/fonts/manrope/ && cd ../.. && rm -rf temp", + "command": "node scripts/fonts.js", "files": [], "output": [ "site/fonts/manrope" diff --git a/packages/lit-dev-content/scripts/fonts.js b/packages/lit-dev-content/scripts/fonts.js new file mode 100644 index 000000000..9823ef668 --- /dev/null +++ b/packages/lit-dev-content/scripts/fonts.js @@ -0,0 +1,27 @@ +import rimraf from 'rimraf' +import {mkdir, copyFile} from 'fs/promises' +import {execSync} from 'child_process' +import glob from 'globby' +import {parse} from 'path' + +rimraf.sync('temp') + +try { + await mkdir('site/fonts/manrope') +} catch { + // already exists +} + +// clone the fonts repo +// TODO: check if the folder already exists +execSync('git clone https://github.com/sharanda/manrope.git temp/manrope') +execSync('cd temp/manrope && git checkout 9ffbc349f4659065b62f780fe6e9d5a93518bd95') +// get the desired font files to copy +const files = await glob('temp/manrope/fonts/web/*.woff2') +// copy the files to site/fonts/manrope +const promises = [] +for (const file of files) { + const parsed = parse(file) + promises.push(copyFile(file, `site/fonts/manrope/${parsed.name}${parsed.ext}`)) +} +await Promise.all(promises) \ No newline at end of file From 434ee15fb3785724e99b1baacb0fe9c2eff75496 Mon Sep 17 00:00:00 2001 From: vandeurenglenn Date: Sat, 4 Nov 2023 09:12:54 +0100 Subject: [PATCH 2/7] Fix spawn npm ENOENT (npm -> npm.cmd) When running execFile('npm') windows expects 'npm.cmd' --- packages/lit-dev-tools-cjs/src/api-docs/generate.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/lit-dev-tools-cjs/src/api-docs/generate.ts b/packages/lit-dev-tools-cjs/src/api-docs/generate.ts index 6405edd21..abc75dfc9 100644 --- a/packages/lit-dev-tools-cjs/src/api-docs/generate.ts +++ b/packages/lit-dev-tools-cjs/src/api-docs/generate.ts @@ -15,6 +15,8 @@ import {lit3Config} from './configs/lit-3.js'; import type {ApiDocsConfig} from './types.js'; +const isWindows = /^win/.test(process.platform) + const execFileAsync = promisify(execFile); // Only generate documentation for most recent Lit versions. @@ -61,9 +63,10 @@ const INSTALLED_FILE = 'INSTALLED'; */ const setup = async (config: ApiDocsConfig) => { console.log(`running npm ci in ${config.gitDir}`); - await execFileAsync('npm', ['ci'], {cwd: config.gitDir}); - for (const {cmd, args} of config.extraSetupCommands ?? []) { + await execFileAsync(isWindows ? 'npm.cmd' : 'npm', ['ci'], {cwd: config.gitDir}); + for (let {cmd, args} of config.extraSetupCommands ?? []) { console.log(`running ${cmd} ${args.join(' ')} in ${config.gitDir}`); + if (cmd === 'npm' && isWindows) cmd = 'npm.cmd' await execFileAsync(cmd, args, {cwd: config.gitDir}); } await fs.writeFile(pathlib.join(config.workDir, INSTALLED_FILE), '', 'utf8'); From 4bb3ba7ab8f3cfc0a32507053cb7785ece108ed4 Mon Sep 17 00:00:00 2001 From: vandeurenglenn Date: Sat, 4 Nov 2023 10:17:29 +0100 Subject: [PATCH 3/7] Fix rollup build failing (expected win sep got posix) Use platform specific separator --- packages/lit-dev-content/rollup.config.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/lit-dev-content/rollup.config.js b/packages/lit-dev-content/rollup.config.js index b6eb2ad84..d2a4f2136 100644 --- a/packages/lit-dev-content/rollup.config.js +++ b/packages/lit-dev-content/rollup.config.js @@ -8,6 +8,11 @@ import resolve from '@rollup/plugin-node-resolve'; import summary from 'rollup-plugin-summary'; import {terser} from 'rollup-plugin-terser'; import minifyHTML from 'rollup-plugin-minify-html-literals'; +import { dirname, sep} from 'path'; +import { fileURLToPath } from 'url'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); const terserOptions = { warnings: true, @@ -57,7 +62,7 @@ export default [ format: 'esm', // Preserve directory structure for entrypoints. entryFileNames: ({facadeModuleId}) => - facadeModuleId.replace(`${__dirname}/lib/`, ''), + facadeModuleId.replace(`${__dirname}${sep}lib${sep}`, ''), manualChunks: (id) => { // Create some more logical shared chunks. In particular, people will // probably be looking for lit.js in devtools! @@ -141,7 +146,7 @@ export default [ format: 'esm', // Preserve directory structure for entrypoints. entryFileNames: ({facadeModuleId}) => - facadeModuleId.replace(`${__dirname}/lib/`, ''), + facadeModuleId.replace(`${__dirname}${sep}lib${sep}`, ''), }, plugins: [ resolve(), From 950b07ae3425db3ec427df66d4e2a38f2627e45c Mon Sep 17 00:00:00 2001 From: vandeurenglenn Date: Sat, 4 Nov 2023 15:31:50 +0100 Subject: [PATCH 4/7] Fix samples not generating on windows --- packages/lit-dev-tools-esm/src/generate-js-samples.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/lit-dev-tools-esm/src/generate-js-samples.ts b/packages/lit-dev-tools-esm/src/generate-js-samples.ts index f1c61a137..bd05d0aaf 100644 --- a/packages/lit-dev-tools-esm/src/generate-js-samples.ts +++ b/packages/lit-dev-tools-esm/src/generate-js-samples.ts @@ -138,7 +138,7 @@ const tsCompileOpts: InvokeTypeScriptOpts = { const playgroundCommentRegexp = /\/\*\s*(playground-(fold|hide)(-end)?)\s\*\//g; const tsPath = jsPath - .replace(/^samples\/js\//, 'samples/') + .replace(/^samples\/js\/|^samples\\js\\/, `samples${pathlib.sep}`) .replace(/\.js$/, '.ts') .replace(/\.jsx$/, '.tsx'); const ts = fsSync.readFileSync(tsPath, 'utf8'); From 42cc97b865c9c78a5872ce85fa4f08372a73cdb3 Mon Sep 17 00:00:00 2001 From: vandeurenglenn Date: Sat, 4 Nov 2023 15:32:12 +0100 Subject: [PATCH 5/7] Create WINDOWS.md --- WINDOWS.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 WINDOWS.md diff --git a/WINDOWS.md b/WINDOWS.md new file mode 100644 index 000000000..8f19b774c --- /dev/null +++ b/WINDOWS.md @@ -0,0 +1,32 @@ + +# Lit.dev Windows Guide +## Setup + +### Patch +Windows comes without [patch][patch-manual] but is included in allot of tools and probably already on your system.
+If you already have patch available then make sure you have it added to your PATH (Environment Variables)
+ +#### Getting patch +The simpliest way to get patch on your system is to install one of the package-managers,terminals etc from below +- [cygwin][install-cygwin] +- [msys2][install-msys2] +- [cmder][install-cmder] +- [git][install-git] + +### Symlinks +Symlinks require admin access so will fail and return a EPERM error.
+There are two options +- [setting security policy](https://superuser.com/questions/104845/permission-to-make-symbolic-links-in-windows-7) +- [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development) +- [run your terminal as admin](https://www.thewindowsclub.com/how-to-run-command-prompt-as-an-administrator) + +***Notes***
+option two comes with security risks, read trough carefully and if you don't fully understand use option one!
+option three only applies when your an admin and option one can't be used unless you remove the account from the admin group. + + +[install-cygwin]: https://cygwin.com/install.html +[install-msys2]: https://www.msys2.org/ +[install-cmder]: https://cmder.app/ +[install-git]: https://git-scm.com/download/win +[patch-manual]: https://www.unix.com/man-page/minix/1/patch/ \ No newline at end of file From 4162837b4a6a36a9fc9d8a0216d1ea023cb18f37 Mon Sep 17 00:00:00 2001 From: vandeurenglenn Date: Sat, 4 Nov 2023 15:32:43 +0100 Subject: [PATCH 6/7] Update README & CONTRIBUTING to include WINDOWS --- CONTRIBUTING.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 15900c684..c6f378f6b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,7 +9,7 @@ There are many ways to contribute to the Lit project, and we have many different We have a [Code of Conduct](https://github.com/lit/lit/blob/main/CODE_OF_CONDUCT.md), please follow it in all interactions with project maintainers and fellow users. ## Set up - +Starting on mac or linux distros works out of the box, windows requires some extra [setup](WINDOWS.md) ```bash git clone https://github.com/lit/lit.dev.git cd lit.dev diff --git a/README.md b/README.md index eadc75762..07658abac 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ npm ci ``` ### Develop site content - +Starting on mac or linux distros works out of the box, windows requires some extra [setup](WINDOWS.md) ```sh npm run dev ``` From 48845d0f30d90cd9b1352912d9995de14af3ff4a Mon Sep 17 00:00:00 2001 From: vandeurenglenn Date: Sat, 4 Nov 2023 15:33:51 +0100 Subject: [PATCH 7/7] Eleventy doesn't like lit-dev-content as a module --- packages/lit-dev-content/package.json | 1 - packages/lit-dev-content/scripts/fonts.js | 24 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/lit-dev-content/package.json b/packages/lit-dev-content/package.json index 17d3eb401..f835be21c 100644 --- a/packages/lit-dev-content/package.json +++ b/packages/lit-dev-content/package.json @@ -6,7 +6,6 @@ "author": "Google LLC", "license": "BSD-3-Clause", "main": "_site/index.html", - "type": "module", "scripts": { "fonts:manrope": "wireit", "build": "wireit", diff --git a/packages/lit-dev-content/scripts/fonts.js b/packages/lit-dev-content/scripts/fonts.js index 9823ef668..b079aab55 100644 --- a/packages/lit-dev-content/scripts/fonts.js +++ b/packages/lit-dev-content/scripts/fonts.js @@ -1,27 +1,27 @@ -import rimraf from 'rimraf' -import {mkdir, copyFile} from 'fs/promises' -import {execSync} from 'child_process' -import glob from 'globby' -import {parse} from 'path' +const rimraf = require('rimraf') +const {mkdirSync, copyFileSync} = require('fs') +const {execFileSync, execSync} = require('child_process') +const glob = require('globby') +const {parse} = require('path') + + rimraf.sync('temp') try { - await mkdir('site/fonts/manrope') + mkdirSync('site/fonts/manrope') } catch { // already exists } // clone the fonts repo // TODO: check if the folder already exists -execSync('git clone https://github.com/sharanda/manrope.git temp/manrope') +execFileSync('git', ['clone', 'https://github.com/sharanda/manrope.git', 'temp/manrope']) execSync('cd temp/manrope && git checkout 9ffbc349f4659065b62f780fe6e9d5a93518bd95') // get the desired font files to copy -const files = await glob('temp/manrope/fonts/web/*.woff2') +const files = glob.sync('temp/manrope/fonts/web/*.woff2') // copy the files to site/fonts/manrope -const promises = [] for (const file of files) { const parsed = parse(file) - promises.push(copyFile(file, `site/fonts/manrope/${parsed.name}${parsed.ext}`)) -} -await Promise.all(promises) \ No newline at end of file + copyFileSync(file, `site/fonts/manrope/${parsed.name}${parsed.ext}`) +} \ No newline at end of file