Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix building on windows #1255

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
32 changes: 32 additions & 0 deletions WINDOWS.md
Original file line number Diff line number Diff line change
@@ -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.<br>
If you already have patch available then make sure you have it added to your PATH (Environment Variables)<br>

#### 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.<br>
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***<br>
option two comes with security risks, read trough carefully and if you don't fully understand use option one!<br>
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/
2 changes: 1 addition & 1 deletion packages/lit-dev-content/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,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"
Expand Down
9 changes: 7 additions & 2 deletions packages/lit-dev-content/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -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(),
Expand Down
27 changes: 27 additions & 0 deletions packages/lit-dev-content/scripts/fonts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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 {
mkdirSync('site/fonts/manrope')
} catch {
// already exists
}

// clone the fonts repo
// TODO: check if the folder already exists
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 = glob.sync('temp/manrope/fonts/web/*.woff2')
// copy the files to site/fonts/manrope
for (const file of files) {
const parsed = parse(file)
copyFileSync(file, `site/fonts/manrope/${parsed.name}${parsed.ext}`)
}
7 changes: 5 additions & 2 deletions packages/lit-dev-tools-cjs/src/api-docs/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion packages/lit-dev-tools-esm/src/generate-js-samples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down