Running the yarn run build script fails on Windows.
1) Download the postgraphile repo, on Windows.
2) Open a terminal in the repo root.
3) Run yarn, to install the dependencies. (not actually necessary to demonstrate this issue, but might as well)
4) Run: yarn run build
I expect to see a success message in the terminal, and the outputted files in the build-turbo folder.
PS C:\Root\Apps\@V\@Modules\postgraphile\Fork> yarn run build
yarn run v1.22.10
$ ./scripts/build
'.\scripts\build' is not recognized as an internal or external command,
operable program or batch file.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Same thing for NPM:
PS C:\Root\Apps\@V\@Modules\postgraphile\Fork> npm run build
> [email protected] build C:\Root\Apps\@V\@Modules\postgraphile\Fork
> ./scripts/build
'.' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE [...]
I also tried renaming the scripts to end with .bat and running them in cmd/powershell, but that (as expected) fails as well. (many errors, due to linux commands like rm not being present)
OS: Windows 10
Node: v14.5.0
Switch from using bash scripts to NodeJS scripts, or some other cross-platform scripting solution (eg. based on shx or shelljs).
I鈥檓 afraid we don鈥檛 have the resources (and I don鈥檛 have the knowledge) to support contributing to PostGraphile on native Windows; please use a Linux VM or Docker or WSL or similar.
(For anyone reading out of context: you can run PostGraphile on Windows just fine, it鈥檚 the development scripts if you want to contribute to PostGraphile that are unix-specific.)
I figured that might be the case...
Anyway, this issue should help clarify that point at least, for others searching with the same question. 馃憤
I will add instructions to this thread if/when I figure out how to get the build process set up on Windows, using Windows Subsystem for Linux (WSS).
Thanks so much 鉂わ笍
I'll eventually look into using WSS for a "proper" build setup.
However, for people merely wanting a basic Typescript build command, I got it working on Windows.
Step 1: Create a build.js file in the scripts folder:
const {execSync} = require("child_process");
const fs = require("fs");
// create assets (some empty/fake) in the src/assets folder (to fix typescript errors)
fs.mkdirSync("./src/assets", {recursive: true});
//fs.copyFileSync("./assets/favicon.ico", "./src/assets/favicon.ico");
fs.writeFileSync("./src/assets/favicon.ico", "");
fs.writeFileSync("./src/assets/graphiql.html", "");
// this helper file tells Typescript to interpret the asset files as string-returning modules (else TS complains about their being imported)
//if (!fs.existsSync("./src/assets/assetsTSHelper.d.ts")) {
fs.writeFileSync("./src/assets/assetsTSHelper.d.ts", `
declare module '*.ico' {
const str: string;
export default str;
}
declare module '*.html' {
const str: string;
export default str;
}
`);
// the default is "build-turbo", but I use "build", to match with the npm-published postgraphile package (for npm-link)
//const buildFolder = "build-turbo";
const buildFolder = "build";
execSync(`.\\node_modules\\.bin\\tsc --target esnext --lib esnext --outDir ${buildFolder} --declarationDir ${buildFolder}`, {stdio: "inherit"});
// copy assets to build folder (else runtime-import error is hit)
fs.mkdirSync("./build/assets", {recursive: true});
const assetNames = ["favicon.ico", "graphiql.html"];
for (const assetName of assetNames) {
fs.copyFileSync(`./src/assets/${assetName}`, `./build/assets/${assetName}`);
}
Step 2: For easier running from VSCode, you can create a .vscode/launch.json file:
{
"version": "2.0.0",
"tasks": [
{
"label": "node: build (windows)",
"type": "shell",
"command": "node",
"args": [
".\\scripts\\build.js"
],
"group": "build",
"problemMatcher": []
}
]
}
Step 3: Run the build script, either with node .\scripts\build.js, or ctrl+shift+b in vscode.
Step 4 (optional): If you want to exclude these extra files from Git, add the following to your ./.git/info/exclude file:
/scripts/build.js
/src/assets
/build/assets
Like I said, this solution is not ideal (eg. it uses empty placeholder files for the assets), but for simply testing changes to the code locally, it works fine.