Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8e58d9e
added the readline-debug.mjs
hychan48 Jun 26, 2023
898f065
updated notes on paths
hychan48 Jun 28, 2023
8d07eec
updated all of the resolve paths
hychan48 Jun 28, 2023
8222c8e
updated all of the resolve paths
hychan48 Jun 28, 2023
a564426
read
hychan48 Jun 30, 2023
590dd83
updated the function to try with cli
hychan48 Jul 1, 2023
1ae6cac
added pkg builder
hychan48 Jul 1, 2023
ae69b88
added pkg builder
hychan48 Jul 1, 2023
a2fd840
updated to proper binary...
hychan48 Jul 1, 2023
1d34b92
updated mac and linux runners
hychan48 Jul 1, 2023
facd267
updated to proper binary...
hychan48 Jul 1, 2023
5df654e
why can i not edit?
hychan48 Jul 1, 2023
59f8de1
updated unit tests
hychan48 Jul 1, 2023
0c70a68
updated unit test
hychan48 Jul 1, 2023
7aa1266
just had to single quote for mac and linux to work
hychan48 Jul 1, 2023
eb6ea06
do i need a path / cmd execute wiki?
hychan48 Jul 1, 2023
997e9a2
updated paths to full
hychan48 Jul 2, 2023
b78e777
updated SpawnCmd.mjs
hychan48 Jul 2, 2023
686cf15
updated paths
hychan48 Jul 2, 2023
d2e0e62
reverted vite.config.mjsi
hychan48 Jul 2, 2023
58023ee
updated build back... gives index2.mjs
hychan48 Jul 2, 2023
b659cb6
failing two tests... might be how im calling the script as well
hychan48 Jul 3, 2023
bdca551
updated test file... but still having issues
hychan48 Jul 3, 2023
745e96c
updated test file... but still having issues
hychan48 Jul 3, 2023
b306d8d
updated typedef
hychan48 Jul 3, 2023
b58c743
updated the vite build process
hychan48 Jul 3, 2023
14d929f
fixed the exe... might want to change the order again though
hychan48 Jul 3, 2023
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 app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import {posixTests, win32Tests} from "~/lib/nodePathTestExamples.mjs";
// import {posixTests, win32Tests} from "##/lib/nodePathTestExamples.mjs";
// import {pathPosixToWin32, pathWin32ToPosix,win32ToWin32JS,win32ToWin32Slash,win32ToWin32WSL2} from "##/lib/dist/index.mjs";
import {pathPosixToWin32, pathWin32ToPosix,win32ToWin32JS,win32ToWin32Slash,win32ToWin32WSL2} from "~/lib/dist/index.mjs";
import {pathPosixToWin32, pathWin32ToPosix,win32ToWin32JS,win32ToWin32Slash,win32ToWin32WSL2} from "##/lib/dist/index.mjs";
export default {
name:'app',
mounted(){
Expand Down
9 changes: 6 additions & 3 deletions dev/node-fs-utils-dev/SpawnCmd.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,26 @@ import { spawn } from 'node:child_process'
import {stdout,stderr} from 'node:process'

/** might be better just to use buffer like they are */
export function spawnExecCmd(cmd,...args){
export function spawnExecCmd(cmd,args=[],opts={}){
const actual = {shell:true,...opts}
return new Promise((resolve, reject) => {
let code, stdouts = [], stderrs = [], signal;

let spawnCmd = spawn(cmd,[],{shell:true});
// let spawnCmd = spawn(cmd,[],{shell:true});
let spawnCmd = spawn(cmd,args,actual);

//i think on error need to double check
spawnCmd.on('error',(err)=>{
reject(err);
});
spawnCmd.stdout.pipe(stdout);//works
spawnCmd.stdout.on('data', (data) => {
// console.log(`stdout: ${data}`);
stdouts.push(data);
});
spawnCmd.stdout.pipe(stdout);//works
/* doesnt work pipe on chai, but two on's work n*/

spawnCmd.stderr.pipe(stderr)
spawnCmd.stderr.on('data', (data) => {
// console.error(`stderr: ${data}`);
stderrs.push(data);
Expand Down
14 changes: 14 additions & 0 deletions dev/node-fs-utils-dev/readline-debug.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import readline from 'node:readline'
import { stdin as input, stdout as output } from 'node:process';
import {promisify} from 'node:util';

let rl = readline.createInterface({
input,
output,
prompt:'hit enter to continue'
});
const question = promisify(rl.question).bind(rl);
const tmp = await question('What is your name?')
console.log('tmp is ',tmp);

rl.close();
122 changes: 122 additions & 0 deletions dev/node-fs-utils-dev/vite-press-path-utils.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/**
* Also in material design 3.. git
*/

/**
yarn add mocha -D

package.json
"imports": {
"##/*": {
"default": "./*"
},
},
"type": "module",

jsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"##/*": ["./*"]
}
},
"exclude": ["node_modules", ".nuxt", "dist"]
}



*/
// import { createRequire } from 'module';
// const require = createRequire(import.meta.url);
// const assert = require('assert');
// const {describe,it} = require('mocha');
import assert from 'node:assert';
import { describe, it} from 'mocha';
/*
1.
yarn add mocha @babel/polyfill @babel/register @babel/preset-env babel-plugin-module-resolver --dev
yarn add @babel/core --dev
2.
-r @babel/register -r babel-plugin-module-resolver

3.
.babelrc
{

"presets": ["@babel/preset-env"],
"plugins": [
["module-resolver", {
"root": ["./src"],
"alias": {
"test": "./test",
"underscore": "lodash",

"~": "./"
}
}]
]

}
test specific timeout
this.timeout(500);//500ms
*/
/**
* Should put this somewhere safe
* todo filepath needs to be initialized as well...
* @param fileName .json
* @param data will automatically be changed
*/
import fs from 'node:fs';
function writeToFile(fileName,data,space=2){
const sFileName = /\./.test(fileName) ? fileName : fileName + '.json';
const filePath = `dev/pbs/test/${sFileName}`
fs.writeFileSync(filePath,
typeof data === 'string' ? data :JSON.stringify(data,null,+space)
);
}
import {relative,resolve,join} from "node:path/posix";
import {fileURLToPath} from "url";

describe('vite-press-path-utils.test.mjs', function(){
let viteConfigFile;
/** @type {'docs/.vitepress' | string} - .vitepress config */
viteConfigFile = 'docs/.vitepress';

const testMatrix = [
//"" is cwd
[resolve(""),"../.."],//,cwd, new URL('./',import.meta.url).pathname???
[resolve("./src"),"../../src"],//cwd/src, cant be ../src
[resolve("src"),"../../src"],//cwd/src, same as above. left is okay to repeat
[resolve("./docs/src"),"../src"],
// [resolve("./docs"),"../"],//'../' also works and is more clear
[resolve("./docs"),".."],//'../' also works and is more clear
]
it('first try', function(){
for (let i = 0; i < testMatrix.length; i++) {
const [expectedPath,inputRelativePathParam] = testMatrix[i];
// destDirCWD = '';
// const out = relative(inputRelativePathParam,viteConfigFile);
/** Resolve docs/.vitepress with relative path to destination dir */
const out = resolve(viteConfigFile,inputRelativePathParam);//reverse
// const out = resolve('./',viteConfigFile);
// console.log(import.meta.url);
// const tmp = fileURLToPath(new URL('../..', import.meta.url))
assert.strictEqual(out,expectedPath);
}


//assert.strictEqual(1,1);//require assert
});
it('reverse use case', function(){
for (let i = 0; i < testMatrix.length; i++) {
const [inputDestinationPath,expectedRelativePath] = testMatrix[i]; //reversed
const out = relative(viteConfigFile, inputDestinationPath);// some of the relative paths may not work
assert.strictEqual(out,expectedRelativePath);
}


//assert.strictEqual(1,1);//require assert
});

});
41 changes: 36 additions & 5 deletions docs/src/readme_vite_press.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,41 @@
1. Need to use vscode / webstorm to inject the header or w/e
* i think there is also called a snippet / wrapper / file template


## Install
```bash
pnpm add -D vitepress
pnpm dlx vitepress init
```
```gitignore
/docs/.vitepress/cache/
/docs/.vitepress/dist/
```
```js
import { defineConfig } from 'vitepress'
//append to generated:
export default defineConfig({
base:"/material-design-3-import-export-ext/",
srcDir: './src',//relative to the package.json vitepress dev <dir>
lang: 'en-ca',
//section inside
themeConfig: {
//add better search. https://vitepress.dev/reference/default-theme-search#local-search
search: {
provider: 'local'
},
socialLinks: [
{ icon: 'github', link: 'https://github.com/codeforwings/material-design-3-import-export-ext' }
],
markdown:{
//https://vitepress.dev/reference/site-config#markdown
lineNumbers: true,
space_size: 2,//not sure if this works
}
}
})

```
# Concepts
* "On this page"
* Edit on GitHub
Expand Down Expand Up @@ -29,11 +64,7 @@

Notes
---
## Git Ignore
```gitignore
/docs/.vitepress/cache/
/docs/.vitepress/dist/
```

# Syntax Highlighting
[https://github.com/shikijs/shiki/blob/main/docs/languages.md](https://github.com/shikijs/shiki/blob/main/docs/languages.md)
```js
Expand Down
8 changes: 7 additions & 1 deletion docs/src/vitepress/readme_vite_press_paths.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,10 @@ docs/src/public/
<<< @/public/some_folder/some_file.json


```
```

## Interesting
```ps1
# mixing paths actually works in powershell and pwd... with no spaces at least and explorer... crazy
cd C:\Users\Public/bins
```
36 changes: 36 additions & 0 deletions lib/bin_build/bin-vite.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Bin builder for vite config
*/
// Utilities
import { defineConfig } from 'vite'
import { fileURLToPath, URL } from 'node:url'
import {rootFileUrl, viteBaseConfig} from "##/vite.config.mjs";
// import { resolve } from 'node:path'
// https://vitejs.dev/config/
export default defineConfig({
...viteBaseConfig,
build: {
//https://vitejs.dev/guide/build.html#library-mode
outDir: fileURLToPath(new URL('./lib/bin_build/.output/', rootFileUrl)),
lib: {
name: 'nuxt3-win32-posix-path',
formats: ['es', 'cjs'],//('es' | 'cjs' | 'umd' | 'iife')
entry: [ //"entry" can be a dictionary or array of multiple entry points
fileURLToPath(new URL('./lib/bin_build/index.mjs', rootFileUrl)),
]
},
rollupOptions: {
// make sure to externalize deps that shouldn't be bundled
// into your library
// external: ['puppeteer',"puppeteer-core","node:path/posix","node*"],
output: {
// Provide global variables to use in the UMD build
// for externalized deps
// globals: {
// vue: 'Vue',//not sure what this means
// },
},
},
},

})
22 changes: 22 additions & 0 deletions lib/bin_build/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Bin Build Index Packager
* maybe add cli builder / handler here
lib/bin_build/dist/index-win.exe c:/Users/Public/Documents

node lib/bin_build/index.mjs c:/Users/Public/Documents
node lib/bin_build/index.mjs "c:/Users/Public/Docum ents"
node lib/bin_build/index.mjs c:/Users/Public/Docum ents
*
* todo think about how to test this properly performance wise
* it's surprisingly not bad. powershell was much slower...
*/
// import process from "node:process";
import {win32ToWin32WSL2} from "##/src/win32ToWin32WSL/win32ToWin32WSL2.mjs";
// export {win32ToWin32WSL2}

/* take arguments from command line */
const args = process.argv.slice(2);
// console.log(args);
// console.log(win32ToWin32WSL2(args[0]))
console.log(win32ToWin32WSL2(args.join(' ')))
process.exit(0)
37 changes: 37 additions & 0 deletions lib/test-utils/mocha-cli-exec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {spawnSync} from "node:child_process";
import assert from "node:assert";

/**
* factory function
*/
/**
*
* @param pathToExe
* @param args
* @param options
* @return {(function(*, *): void)|*}
* @example
* const assertW2Wb = createMochaCliExe(W2WB);1
*/
export function createMochaCliExe(pathToExe,args=[],options={}){
//todo add better defaulting etc... didnt think i neeeded to modify the input
const actualOptions = {shell:true,...options}

return function(expectedValue,...inputToTest){
const output = spawnSync(
// `"${W2WB}" [C:\\` //cmd needs to double quote
// `"${pathToExe}"`,[WSLPassTests[0][0]],actualOptions
`"${pathToExe}"`,[...inputToTest],actualOptions
);
if(output.status !== 0){
console.error(output);
console.log(output.stdout.toString())
console.error(output.stderr.toString())
throw new Error("status not 0");
}
const actual = output.stdout.toString().trim();
console.assert(actual === expectedValue,`inputToTest: ${inputToTest}`)
assert.strictEqual(actual,expectedValue);
}

}
16 changes: 16 additions & 0 deletions lib/test-utils/pwsh-test-mocha.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!pwsh.exe
<#
todo move this somewhere
Test powershell inside of mocha... source and import?
cd C:\Users\Jason\WebstormProjects\nuxt3-win32-posix-path
pwsh.exe -File pwsh-test-mocha.ps1 c:\hi
pwsh.exe -File lib/test-utils/pwsh-test-mocha.ps1 c:\hi s
#>

# import-module -Name ./src/win32ToWin32WSL/win32ToWin32WSL2.ps1 -Function pathWin32ToPosix
# source
# powershell -Command ./src/win32ToWin32WSL/win32ToWin32WSL2.ps1; pathWin32ToPosix 'c:\hi'
#write-host -NoNewline $args[0]
. ./src/win32ToWin32WSL/win32ToWin32WSL2.ps1;
$tmp=pathWin32ToPosix $args[0]
write-host -NoNewline $tmp
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
"docs:dev": "vitepress dev docs",
"docs:build": "vitepress build docs",
"docs:preview": "vitepress preview docs",
"build-rollup:vite": "vite build --mode production"
"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/"
},
"devDependencies": {
"gh-pages": "^4.0.0",
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading