Skip to content
Merged
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ Build the application for production:

```bash
npm run build


# "build-bins": "pnpm run /build-bins:.*/",
# "pwsh:ghGenerateAndDeploy": "c:/progra~1/PowerShell/7/pwsh.exe -File lib/deploy/ghPagesDeploy.ps1",
# didnt work...
# https://github.com/codeforwings/nuxt3-win32-posix-path/deployments/activity_log?environment=github-pages

```

Locally preview production build:
Expand Down
34 changes: 29 additions & 5 deletions app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
:value="sOutputWin32ToPosix"
/>
<br/>
<!-- sOutputPosixToWin32 />-->
</div>
<!-- sOutputPosixToWin32 , todo auto fix sep etx.../>-->
<h1>Posix to Win32</h1>
<textarea class="area"
v-model="sInputPosix"
Expand All @@ -22,7 +23,6 @@
<textarea class="area"
:value="sOutputPosixToWin32"
/>
</div>
<!-- Win32 Normalized / JS />-->
<h1>Win32 to Win32JS</h1>
<textarea class="area"
Expand All @@ -31,7 +31,7 @@
<textarea class="area"
:value="sOutputWin32Normal"
/>
<!-- Win32 wsl - todo make this append / cydrive?
<!-- Win32 wsl - make this append / cydrive?
https://github.com/codeforwings/nuxt3-win32-posix-path/issues/3
/>-->
<h1>Win32 to Win32 WSL mnt</h1>
Expand All @@ -41,6 +41,15 @@
<textarea class="area"
:value="sOutputWin32ToWsl"
/>
<h1>Win32 to Cygwin</h1>
<!-- todo cygwin path base. i.e. /usr/local/bin? or no -->
<textarea class="area"
v-model="sWin32ToCygwin"
/>
<textarea class="area"
:value="sOutputWin32ToCygwin"
/>
<!-- fixme make loop or something / component -->
<!-- Win32 slash todo make this toggle space with quotes
https://github.com/codeforwings/nuxt3-win32-posix-path/issues/3
/>-->
Expand All @@ -51,7 +60,6 @@
<textarea class="area"
:value="sOutputWin32ToSlash"
/>
<!-- todo cygwin "/cygdrive/c/" to c:/ -->

<h1 Links></h1>
<div>
Expand All @@ -67,8 +75,13 @@
// import {win32ToWin32JS} from "~/src/win32ToWin32JS.mjs";
// import {win32ToWin32Slash, win32ToWin32WSL2} from "~/src/win32ToWin32WSL2.mjs";

//1. ~/lib
import {posixTests, win32Tests} from "~/lib/nodePathTestExamples.mjs";
import {pathPosixToWin32, pathWin32ToPosix,win32ToWin32JS,win32ToWin32Slash,win32ToWin32WSL2} from "~/lib/dist/index.mjs";
/* from src - dont use until fixed... arg*/
import {pathPosixToWin32, pathWin32ToPosix,win32ToWin32JS,win32ToWin32Slash,win32ToWin32WSL2,win32ToCygwin} from "~/src/index.mjs";
/* 2.2 from dist... */
// import {pathPosixToWin32, pathWin32ToPosix,win32ToWin32JS,win32ToWin32Slash,win32ToWin32WSL2} from "~/lib/dist/index.mjs";


//## not working for some reason
// import {posixTests, win32Tests} from "##/lib/nodePathTestExamples.mjs";
Expand All @@ -95,6 +108,12 @@ export default {
"C:\\Users\\Public\\Documents",
"C:\\\\Users\\\\Public\\\\Documents",
].join('\n'),
sWin32ToCygwin:[
`"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"`,
`C:\\progra~1\\PowerShell\\7\\pwsh.exe`,
`C:\\cygwin64\\bin\\bash.exe`,
//try appdata / localappdata
].join('\n'),
sWin32ToSlash:
[
"C:\\Users\\Public\\Documents",
Expand Down Expand Up @@ -131,6 +150,11 @@ export default {
return win32ToWin32WSL2(val);
}).join('\n')
},
sOutputWin32ToCygwin() {
return this.sWin32ToCygwin.split('\n').map( val =>{
return win32ToCygwin(val);
}).join('\n')
},
sOutputWin32ToSlash(){
return this.sWin32ToSlash.split('\n').map( val =>{
return win32ToWin32Slash(val);
Expand Down
3 changes: 2 additions & 1 deletion lib/deploy/ghPagesDeploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ if($pwd -notmatch "nuxt3-win32-posix-path"){
$pwd
exit
}
# 2. verify node / maybe pnpm
# 2. verify node / maybe pnpm - if needed
# fixme. that doesnt sound right for this project... only nuxt3
$isNod316=node -v | Select-String -Pattern "v16" -Quiet
if(!$isNod316){
Write-Host "node version 16 required"
Expand Down
25 changes: 25 additions & 0 deletions lib/test-utils/ConstPathTests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,29 @@ for (let i = 0; i < ogLength; i++) {
WSLPassTests.push([`'${row[0]}'`,row[1],`${i}1`]);//append with single quotes
WSLPassTests.push([`"${row[0]}"`,row[1],`${i}2`]);//append with double quotes

}

//todo add the ones inside of cygwin64...
// but should be ok? add issue to github
export const CygwinPassTests = [
["C:\\cygwin64\\bin\\bash.exe","/cygdrive/c/cygwin64/bin/bash.exe"],
["C:\\Users\\Public\\Documents","/cygdrive/c/Users/Public/Documents"],//maybe append with quotes instead?
["C:\\Users\\Public\\Documents","/cygdrive/c/Users/Public/Documents"],//maybe append with quotes instead?
["C:\\Users\\Public\\temp spaces\\a\\b c\\d","/cygdrive/c/Users/Public/temp\\ spaces/a/b\\ c/d"],
["C:\\Users\\Public\\temp spaces\\a\\b c\\d","/cygdrive/c/Users/Public/temp\\ spaces/a/b\\ c/d"],
["C:\\\\Users\\\\Public\\\\Documents","/cygdrive/c/Users/Public/Documents"],
//todo look into thje backtick
// ["C:\\Users\\Public\\temp` spaces\\a\\b` c\\d","/mnt/c/Users/Public/temp\\ spaces/a/b\\ c/d"],
]
//should work with changing the length of the array
//clean up this. maybe convert it to yaml
{
const ogLength = CygwinPassTests.length
for (let i = 0; i < ogLength; i++) {
const row = CygwinPassTests[i];
row[2] = i;
CygwinPassTests.push([`'${row[0]}'`, row[1], `${i}1`]);//append with single quotes
CygwinPassTests.push([`"${row[0]}"`, row[1], `${i}2`]);//append with double quotes

}
}
9 changes: 9 additions & 0 deletions nuxt.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
// const baseURL = process.env.NUXT_APP_BASE_URL || '/'
process.env.NUXT_APP_BASE_URL = '/nuxt3-win32-posix-path/'
//this works easiest way fixme
const baseURL = process.env.NUXT_APP_BASE_URL || '/nuxt3-win32-posix-path/'
export default defineNuxtConfig({
ssr:false,
// baseURL,//this breaks it? wth
// env: {
// NUXT_APP_BASE_URL: process.env.NUXT_APP_BASE_URL || 'http://localhost:3000',
// }

})
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"pwsh:generate:gh": "set NUXT_APP_BASE_URL=\"/nuxt3-win32-posix-path/\" && nuxt generate",
"generate": "nuxt generate --config nuxt.config.mjs",
"pwsh:generate:gh": "set NUXT_APP_BASE_URL=\"/nuxt3-win32-posix-path/\" && nuxt generate --config nuxt.config.mjs --no",
"gh-pages-deploy": "gh-pages --dotfiles --dist dist",
"preview": "nuxt preview",
"postinstall": "nuxt prepare",
"test:unit": "mocha --recursive --timeout 10000 --exit tests/unit",
"test:unit": "mocha --recursive --timeout 10000 --exit --ui bdd tests/unit/",
"testPathSep:os": "node tests/concepts/printSep.dev.mjs",
"gh-pages-deploy": "gh-pages --dotfiles --dist dist",
"ghGenerateAndDeploy": "node lib/deploy/ghPagesDeploy.mjs",
"pwsh:ghGenerateAndDeploy": "c:/progra~1/PowerShell/7/pwsh.exe -File lib/deploy/ghPagesDeploy.ps1",
"docs:dev": "vitepress dev docs",
"docs:build": "vitepress build docs",
"docs:preview": "vitepress preview docs",
"build-rollup:vite": "vite build --mode production",
"build-rollup:pkg": "pkg lib/dist/index.js --out-path lib/dist/bins",
"build-bins": "pnpm run /build-bins:.*/",
"build-bins:rollup": "vite build --mode production --config lib/bin_build/bin-vite.config.mjs",
"build-bins:pkg": "pkg lib/bin_build/.output/index.js --out-path lib/bin_build/dist/"
"build-bins:pkg": "pkg lib/bin_build/.output/index.js --out-path lib/bin_build/dist/",
"pwsh:ghGenerateAndDeploy": "c:/progra~1/PowerShell/7/pwsh.exe -File lib/deploy/ghPagesDeploy.ps1"
},
"devDependencies": {
"gh-pages": "^4.0.0",
Expand Down
11 changes: 7 additions & 4 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
* that's one ay of oding it
*/

import {pathWin32ToPosix,pathPosixToWin32} from "#src/pathReplacement.mjs";
// import {pathWin32ToPosix,pathPosixToWin32} from "#src/pathReplacement.mjs";
import {pathWin32ToPosix,pathPosixToWin32} from "~/src/pathReplacement.mjs";
export {pathWin32ToPosix,pathPosixToWin32}

import {win32ToWin32WSL2,win32ToWin32Slash} from "#src/win32ToWin32WSL/win32ToWin32WSL2.mjs";
export {win32ToWin32WSL2,win32ToWin32Slash}
// import {win32ToWin32WSL2,win32ToWin32Slash} from "#src/win32ToWin32WSL/win32ToWin32WSL2.mjs";
import {win32ToWin32WSL2,win32ToWin32Slash,win32ToCygwin} from "~/src/win32ToWin32WSL/win32ToWin32WSL2.mjs";
export {win32ToWin32WSL2,win32ToWin32Slash,win32ToCygwin}

import {win32ToWin32JS} from "#src/win32ToWin32JS.mjs";
// import {win32ToWin32JS} from "#src/win32ToWin32JS.mjs";
import {win32ToWin32JS} from "~/src/win32ToWin32JS.mjs";
export {win32ToWin32JS}

// <!-- todo cygwin "/cygdrive/c/" to c:/ -->
51 changes: 43 additions & 8 deletions src/win32ToWin32WSL/win32ToWin32WSL2.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
/**
* Should be renamed i feel to better reflect
* wsl / mnt.
1. js c:/
2. wsl
3. cygwin
* Quick and dirty script to convert a Windows path to a WSL2 path
* been doing this manually for too much today.
*
Expand All @@ -11,6 +16,28 @@
// import {pathWin32ToPosix} from "./pathReplacement.mjs";
import {pathWin32ToPosix} from "#src/pathReplacement.mjs";

/**
* Generic Function
* @param win32Path {string} - Path
* @param mntPrefix {string} /mnt/ - to validate
* @param options {object} fixme
* @param mntPrefix
*/
export function win32ToMntPath(win32Path,mntPrefix='/mnt/',options){
let slashPath;
const {spaceEscape} = options || {spaceEscape:undefined};
/* replace \ with / */
slashPath = pathWin32ToPosix(win32Path,spaceEscape)
/* convert Drive letter to /mnt/<lowercase>/ */
slashPath = slashPath.replace(/^([a-zA-Z]):/,(match,p1)=>{
// console.log(match);//match is C:
return mntPrefix + p1.toLowerCase();// /mnt/c/... might want to add quote etc.
// return '/mnt/' + p1.toLowerCase();// /mnt/c/... might want to add quote etc.
})
//trim check for quotes / validation later

return slashPath;
}
/**
*
* @param win32Path {string} - Windows Path - Example: C:\Users\Public\Documents
Expand All @@ -20,14 +47,22 @@ import {pathWin32ToPosix} from "#src/pathReplacement.mjs";
*/
export function win32ToWin32WSL2(win32Path){
let wsl2Path;
/* replace \ with / */
wsl2Path = pathWin32ToPosix(win32Path);
/* convert Drive letter to /mnt/<lowercase>/ */
wsl2Path = wsl2Path.replace(/^([a-zA-Z]):/,(match,p1)=>{
// console.log(match);//match is C:
return '/mnt/' + p1.toLowerCase();
})
//trim check for quotes / validation later
wsl2Path = win32ToMntPath(win32Path,'/mnt/')
// win32ToMntPath(win32Path,'/mnt/',{spaceEscape:'` '})

return wsl2Path;
}

/**
* Returns cywin path
* @param win32Path {string}
* @return {string} - /cygdrive/c/Users/Public/Documents
* todo add /usr/bin, pass in options
*/
export function win32ToCygwin(win32Path){
let wsl2Path;
wsl2Path = win32ToMntPath(win32Path,'/cygdrive/')
// win32ToMntPath(win32Path,'/mnt/',{spaceEscape:'` '})

return wsl2Path;
}
Expand Down
21 changes: 18 additions & 3 deletions tests/unit/win32ToWin32WSL2.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


*/
import {WSLPassTests} from "##/lib/test-utils/ConstPathTests.mjs";
import {CygwinPassTests, WSLPassTests} from "##/lib/test-utils/ConstPathTests.mjs";
// import { createRequire } from 'module';
// const require = createRequire(import.meta.url);
// const assert = require('assert');
Expand Down Expand Up @@ -66,7 +66,7 @@ this.timeout(500);//500ms
*/
import fs from 'node:fs';
// import {win32ToWin32WSL2} from "##/dev/win-to-wsl/win32ToWin32WSL2.mjs";
import {win32ToWin32Slash, win32ToWin32WSL2} from "##/src/win32ToWin32WSL/win32ToWin32WSL2.mjs";//fixme check the import subpath in package.json in other branch
import {win32ToCygwin, win32ToWin32Slash, win32ToWin32WSL2} from "##/src/win32ToWin32WSL/win32ToWin32WSL2.mjs";//fixme check the import subpath in package.json in other branch
function writeToFile(fileName,data,space=2){
const sFileName = /\./.test(fileName) ? fileName : fileName + '.json';
const filePath = `temp/${sFileName}`
Expand All @@ -78,7 +78,7 @@ function writeToFile(fileName,data,space=2){
/**
* To integrate and move with other tests
*/

//todo win32ToMntPath
describe('win32ToWin32WSL2.test.mjs', function(){
it('wsl', function(){
//assert.strictEqual(1,1);//require assert
Expand Down Expand Up @@ -173,3 +173,18 @@ describe('WSLPassTests', function(){
}
});

describe('CygwinPassTests', function(){
/* if windows */
// if(process.platform !== 'win32'){
// return;
// }
/**/
for (let i = 0; i < CygwinPassTests.length; i++) {
const [inputWinPath, expectedMntPath, wslPassTestIndex] = CygwinPassTests[i];
it(`CygwinPassTests MJS ${wslPassTestIndex}`, function () {
// console.log(wslPassTestIndex,inputWinPath);
const actual = win32ToCygwin(inputWinPath);
assert.strictEqual(actual,expectedMntPath);
});
}
});
Loading