Skip to content

Commit e4af572

Browse files
authored
Merge pull request #17 from codeforwings/12-cygwin
12 cygwin - works but build broke
2 parents f019f33 + b7d6090 commit e4af572

File tree

10 files changed

+187
-67
lines changed

10 files changed

+187
-67
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ Build the application for production:
7676

7777
```bash
7878
npm run build
79+
80+
81+
# "build-bins": "pnpm run /build-bins:.*/",
82+
# "pwsh:ghGenerateAndDeploy": "c:/progra~1/PowerShell/7/pwsh.exe -File lib/deploy/ghPagesDeploy.ps1",
83+
# didnt work...
84+
# https://github.com/codeforwings/nuxt3-win32-posix-path/deployments/activity_log?environment=github-pages
85+
7986
```
8087

8188
Locally preview production build:

app.vue

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
:value="sOutputWin32ToPosix"
1414
/>
1515
<br/>
16-
<!-- sOutputPosixToWin32 />-->
16+
</div>
17+
<!-- sOutputPosixToWin32 , todo auto fix sep etx.../>-->
1718
<h1>Posix to Win32</h1>
1819
<textarea class="area"
1920
v-model="sInputPosix"
@@ -22,7 +23,6 @@
2223
<textarea class="area"
2324
:value="sOutputPosixToWin32"
2425
/>
25-
</div>
2626
<!-- Win32 Normalized / JS />-->
2727
<h1>Win32 to Win32JS</h1>
2828
<textarea class="area"
@@ -31,7 +31,7 @@
3131
<textarea class="area"
3232
:value="sOutputWin32Normal"
3333
/>
34-
<!-- Win32 wsl - todo make this append / cydrive?
34+
<!-- Win32 wsl - make this append / cydrive?
3535
https://github.com/codeforwings/nuxt3-win32-posix-path/issues/3
3636
/>-->
3737
<h1>Win32 to Win32 WSL mnt</h1>
@@ -41,6 +41,15 @@
4141
<textarea class="area"
4242
:value="sOutputWin32ToWsl"
4343
/>
44+
<h1>Win32 to Cygwin</h1>
45+
<!-- todo cygwin path base. i.e. /usr/local/bin? or no -->
46+
<textarea class="area"
47+
v-model="sWin32ToCygwin"
48+
/>
49+
<textarea class="area"
50+
:value="sOutputWin32ToCygwin"
51+
/>
52+
<!-- fixme make loop or something / component -->
4453
<!-- Win32 slash todo make this toggle space with quotes
4554
https://github.com/codeforwings/nuxt3-win32-posix-path/issues/3
4655
/>-->
@@ -51,7 +60,6 @@
5160
<textarea class="area"
5261
:value="sOutputWin32ToSlash"
5362
/>
54-
<!-- todo cygwin "/cygdrive/c/" to c:/ -->
5563

5664
<h1 Links></h1>
5765
<div>
@@ -67,8 +75,13 @@
6775
// import {win32ToWin32JS} from "~/src/win32ToWin32JS.mjs";
6876
// import {win32ToWin32Slash, win32ToWin32WSL2} from "~/src/win32ToWin32WSL2.mjs";
6977
78+
//1. ~/lib
7079
import {posixTests, win32Tests} from "~/lib/nodePathTestExamples.mjs";
71-
import {pathPosixToWin32, pathWin32ToPosix,win32ToWin32JS,win32ToWin32Slash,win32ToWin32WSL2} from "~/lib/dist/index.mjs";
80+
/* from src - dont use until fixed... arg*/
81+
import {pathPosixToWin32, pathWin32ToPosix,win32ToWin32JS,win32ToWin32Slash,win32ToWin32WSL2,win32ToCygwin} from "~/src/index.mjs";
82+
/* 2.2 from dist... */
83+
// import {pathPosixToWin32, pathWin32ToPosix,win32ToWin32JS,win32ToWin32Slash,win32ToWin32WSL2} from "~/lib/dist/index.mjs";
84+
7285
7386
//## not working for some reason
7487
// import {posixTests, win32Tests} from "##/lib/nodePathTestExamples.mjs";
@@ -95,6 +108,12 @@ export default {
95108
"C:\\Users\\Public\\Documents",
96109
"C:\\\\Users\\\\Public\\\\Documents",
97110
].join('\n'),
111+
sWin32ToCygwin:[
112+
`"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"`,
113+
`C:\\progra~1\\PowerShell\\7\\pwsh.exe`,
114+
`C:\\cygwin64\\bin\\bash.exe`,
115+
//try appdata / localappdata
116+
].join('\n'),
98117
sWin32ToSlash:
99118
[
100119
"C:\\Users\\Public\\Documents",
@@ -131,6 +150,11 @@ export default {
131150
return win32ToWin32WSL2(val);
132151
}).join('\n')
133152
},
153+
sOutputWin32ToCygwin() {
154+
return this.sWin32ToCygwin.split('\n').map( val =>{
155+
return win32ToCygwin(val);
156+
}).join('\n')
157+
},
134158
sOutputWin32ToSlash(){
135159
return this.sWin32ToSlash.split('\n').map( val =>{
136160
return win32ToWin32Slash(val);

lib/deploy/ghPagesDeploy.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ if($pwd -notmatch "nuxt3-win32-posix-path"){
2727
$pwd
2828
exit
2929
}
30-
# 2. verify node / maybe pnpm
30+
# 2. verify node / maybe pnpm - if needed
31+
# fixme. that doesnt sound right for this project... only nuxt3
3132
$isNod316=node -v | Select-String -Pattern "v16" -Quiet
3233
if(!$isNod316){
3334
Write-Host "node version 16 required"

lib/test-utils/ConstPathTests.mjs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,29 @@ for (let i = 0; i < ogLength; i++) {
1414
WSLPassTests.push([`'${row[0]}'`,row[1],`${i}1`]);//append with single quotes
1515
WSLPassTests.push([`"${row[0]}"`,row[1],`${i}2`]);//append with double quotes
1616

17+
}
18+
19+
//todo add the ones inside of cygwin64...
20+
// but should be ok? add issue to github
21+
export const CygwinPassTests = [
22+
["C:\\cygwin64\\bin\\bash.exe","/cygdrive/c/cygwin64/bin/bash.exe"],
23+
["C:\\Users\\Public\\Documents","/cygdrive/c/Users/Public/Documents"],//maybe append with quotes instead?
24+
["C:\\Users\\Public\\Documents","/cygdrive/c/Users/Public/Documents"],//maybe append with quotes instead?
25+
["C:\\Users\\Public\\temp spaces\\a\\b c\\d","/cygdrive/c/Users/Public/temp\\ spaces/a/b\\ c/d"],
26+
["C:\\Users\\Public\\temp spaces\\a\\b c\\d","/cygdrive/c/Users/Public/temp\\ spaces/a/b\\ c/d"],
27+
["C:\\\\Users\\\\Public\\\\Documents","/cygdrive/c/Users/Public/Documents"],
28+
//todo look into thje backtick
29+
// ["C:\\Users\\Public\\temp` spaces\\a\\b` c\\d","/mnt/c/Users/Public/temp\\ spaces/a/b\\ c/d"],
30+
]
31+
//should work with changing the length of the array
32+
//clean up this. maybe convert it to yaml
33+
{
34+
const ogLength = CygwinPassTests.length
35+
for (let i = 0; i < ogLength; i++) {
36+
const row = CygwinPassTests[i];
37+
row[2] = i;
38+
CygwinPassTests.push([`'${row[0]}'`, row[1], `${i}1`]);//append with single quotes
39+
CygwinPassTests.push([`"${row[0]}"`, row[1], `${i}2`]);//append with double quotes
40+
41+
}
1742
}

nuxt.config.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
// https://nuxt.com/docs/api/configuration/nuxt-config
2+
// const baseURL = process.env.NUXT_APP_BASE_URL || '/'
3+
process.env.NUXT_APP_BASE_URL = '/nuxt3-win32-posix-path/'
4+
//this works easiest way fixme
5+
const baseURL = process.env.NUXT_APP_BASE_URL || '/nuxt3-win32-posix-path/'
26
export default defineNuxtConfig({
37
ssr:false,
8+
// baseURL,//this breaks it? wth
9+
// env: {
10+
// NUXT_APP_BASE_URL: process.env.NUXT_APP_BASE_URL || 'http://localhost:3000',
11+
// }
12+
413
})

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55
"scripts": {
66
"build": "nuxt build",
77
"dev": "nuxt dev",
8-
"generate": "nuxt generate",
9-
"pwsh:generate:gh": "set NUXT_APP_BASE_URL=\"/nuxt3-win32-posix-path/\" && nuxt generate",
8+
"generate": "nuxt generate --config nuxt.config.mjs",
9+
"pwsh:generate:gh": "set NUXT_APP_BASE_URL=\"/nuxt3-win32-posix-path/\" && nuxt generate --config nuxt.config.mjs --no",
10+
"gh-pages-deploy": "gh-pages --dotfiles --dist dist",
1011
"preview": "nuxt preview",
1112
"postinstall": "nuxt prepare",
12-
"test:unit": "mocha --recursive --timeout 10000 --exit tests/unit",
13+
"test:unit": "mocha --recursive --timeout 10000 --exit --ui bdd tests/unit/",
1314
"testPathSep:os": "node tests/concepts/printSep.dev.mjs",
14-
"gh-pages-deploy": "gh-pages --dotfiles --dist dist",
1515
"ghGenerateAndDeploy": "node lib/deploy/ghPagesDeploy.mjs",
16-
"pwsh:ghGenerateAndDeploy": "c:/progra~1/PowerShell/7/pwsh.exe -File lib/deploy/ghPagesDeploy.ps1",
1716
"docs:dev": "vitepress dev docs",
1817
"docs:build": "vitepress build docs",
1918
"docs:preview": "vitepress preview docs",
2019
"build-rollup:vite": "vite build --mode production",
2120
"build-rollup:pkg": "pkg lib/dist/index.js --out-path lib/dist/bins",
2221
"build-bins": "pnpm run /build-bins:.*/",
2322
"build-bins:rollup": "vite build --mode production --config lib/bin_build/bin-vite.config.mjs",
24-
"build-bins:pkg": "pkg lib/bin_build/.output/index.js --out-path lib/bin_build/dist/"
23+
"build-bins:pkg": "pkg lib/bin_build/.output/index.js --out-path lib/bin_build/dist/",
24+
"pwsh:ghGenerateAndDeploy": "c:/progra~1/PowerShell/7/pwsh.exe -File lib/deploy/ghPagesDeploy.ps1"
2525
},
2626
"devDependencies": {
2727
"gh-pages": "^4.0.0",

src/index.mjs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
* that's one ay of oding it
44
*/
55

6-
import {pathWin32ToPosix,pathPosixToWin32} from "#src/pathReplacement.mjs";
6+
// import {pathWin32ToPosix,pathPosixToWin32} from "#src/pathReplacement.mjs";
7+
import {pathWin32ToPosix,pathPosixToWin32} from "~/src/pathReplacement.mjs";
78
export {pathWin32ToPosix,pathPosixToWin32}
89

9-
import {win32ToWin32WSL2,win32ToWin32Slash} from "#src/win32ToWin32WSL/win32ToWin32WSL2.mjs";
10-
export {win32ToWin32WSL2,win32ToWin32Slash}
10+
// import {win32ToWin32WSL2,win32ToWin32Slash} from "#src/win32ToWin32WSL/win32ToWin32WSL2.mjs";
11+
import {win32ToWin32WSL2,win32ToWin32Slash,win32ToCygwin} from "~/src/win32ToWin32WSL/win32ToWin32WSL2.mjs";
12+
export {win32ToWin32WSL2,win32ToWin32Slash,win32ToCygwin}
1113

12-
import {win32ToWin32JS} from "#src/win32ToWin32JS.mjs";
14+
// import {win32ToWin32JS} from "#src/win32ToWin32JS.mjs";
15+
import {win32ToWin32JS} from "~/src/win32ToWin32JS.mjs";
1316
export {win32ToWin32JS}
1417

1518
// <!-- todo cygwin "/cygdrive/c/" to c:/ -->

src/win32ToWin32WSL/win32ToWin32WSL2.mjs

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
/**
2+
* Should be renamed i feel to better reflect
3+
* wsl / mnt.
4+
1. js c:/
5+
2. wsl
6+
3. cygwin
27
* Quick and dirty script to convert a Windows path to a WSL2 path
38
* been doing this manually for too much today.
49
*
@@ -11,6 +16,28 @@
1116
// import {pathWin32ToPosix} from "./pathReplacement.mjs";
1217
import {pathWin32ToPosix} from "#src/pathReplacement.mjs";
1318

19+
/**
20+
* Generic Function
21+
* @param win32Path {string} - Path
22+
* @param mntPrefix {string} /mnt/ - to validate
23+
* @param options {object} fixme
24+
* @param mntPrefix
25+
*/
26+
export function win32ToMntPath(win32Path,mntPrefix='/mnt/',options){
27+
let slashPath;
28+
const {spaceEscape} = options || {spaceEscape:undefined};
29+
/* replace \ with / */
30+
slashPath = pathWin32ToPosix(win32Path,spaceEscape)
31+
/* convert Drive letter to /mnt/<lowercase>/ */
32+
slashPath = slashPath.replace(/^([a-zA-Z]):/,(match,p1)=>{
33+
// console.log(match);//match is C:
34+
return mntPrefix + p1.toLowerCase();// /mnt/c/... might want to add quote etc.
35+
// return '/mnt/' + p1.toLowerCase();// /mnt/c/... might want to add quote etc.
36+
})
37+
//trim check for quotes / validation later
38+
39+
return slashPath;
40+
}
1441
/**
1542
*
1643
* @param win32Path {string} - Windows Path - Example: C:\Users\Public\Documents
@@ -20,14 +47,22 @@ import {pathWin32ToPosix} from "#src/pathReplacement.mjs";
2047
*/
2148
export function win32ToWin32WSL2(win32Path){
2249
let wsl2Path;
23-
/* replace \ with / */
24-
wsl2Path = pathWin32ToPosix(win32Path);
25-
/* convert Drive letter to /mnt/<lowercase>/ */
26-
wsl2Path = wsl2Path.replace(/^([a-zA-Z]):/,(match,p1)=>{
27-
// console.log(match);//match is C:
28-
return '/mnt/' + p1.toLowerCase();
29-
})
30-
//trim check for quotes / validation later
50+
wsl2Path = win32ToMntPath(win32Path,'/mnt/')
51+
// win32ToMntPath(win32Path,'/mnt/',{spaceEscape:'` '})
52+
53+
return wsl2Path;
54+
}
55+
56+
/**
57+
* Returns cywin path
58+
* @param win32Path {string}
59+
* @return {string} - /cygdrive/c/Users/Public/Documents
60+
* todo add /usr/bin, pass in options
61+
*/
62+
export function win32ToCygwin(win32Path){
63+
let wsl2Path;
64+
wsl2Path = win32ToMntPath(win32Path,'/cygdrive/')
65+
// win32ToMntPath(win32Path,'/mnt/',{spaceEscape:'` '})
3166

3267
return wsl2Path;
3368
}

tests/unit/win32ToWin32WSL2.test.mjs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
2424
2525
*/
26-
import {WSLPassTests} from "##/lib/test-utils/ConstPathTests.mjs";
26+
import {CygwinPassTests, WSLPassTests} from "##/lib/test-utils/ConstPathTests.mjs";
2727
// import { createRequire } from 'module';
2828
// const require = createRequire(import.meta.url);
2929
// const assert = require('assert');
@@ -66,7 +66,7 @@ this.timeout(500);//500ms
6666
*/
6767
import fs from 'node:fs';
6868
// import {win32ToWin32WSL2} from "##/dev/win-to-wsl/win32ToWin32WSL2.mjs";
69-
import {win32ToWin32Slash, win32ToWin32WSL2} from "##/src/win32ToWin32WSL/win32ToWin32WSL2.mjs";//fixme check the import subpath in package.json in other branch
69+
import {win32ToCygwin, win32ToWin32Slash, win32ToWin32WSL2} from "##/src/win32ToWin32WSL/win32ToWin32WSL2.mjs";//fixme check the import subpath in package.json in other branch
7070
function writeToFile(fileName,data,space=2){
7171
const sFileName = /\./.test(fileName) ? fileName : fileName + '.json';
7272
const filePath = `temp/${sFileName}`
@@ -78,7 +78,7 @@ function writeToFile(fileName,data,space=2){
7878
/**
7979
* To integrate and move with other tests
8080
*/
81-
81+
//todo win32ToMntPath
8282
describe('win32ToWin32WSL2.test.mjs', function(){
8383
it('wsl', function(){
8484
//assert.strictEqual(1,1);//require assert
@@ -173,3 +173,18 @@ describe('WSLPassTests', function(){
173173
}
174174
});
175175

176+
describe('CygwinPassTests', function(){
177+
/* if windows */
178+
// if(process.platform !== 'win32'){
179+
// return;
180+
// }
181+
/**/
182+
for (let i = 0; i < CygwinPassTests.length; i++) {
183+
const [inputWinPath, expectedMntPath, wslPassTestIndex] = CygwinPassTests[i];
184+
it(`CygwinPassTests MJS ${wslPassTestIndex}`, function () {
185+
// console.log(wslPassTestIndex,inputWinPath);
186+
const actual = win32ToCygwin(inputWinPath);
187+
assert.strictEqual(actual,expectedMntPath);
188+
});
189+
}
190+
});

0 commit comments

Comments
 (0)