Skip to content

Commit 443bb03

Browse files
authored
Merge pull request #7 from codeforwings/jc0dev
Jc-dev
2 parents 09bd545 + 14d929f commit 443bb03

21 files changed

+823
-23
lines changed

app.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
import {posixTests, win32Tests} from "~/lib/nodePathTestExamples.mjs";
5656
// import {posixTests, win32Tests} from "##/lib/nodePathTestExamples.mjs";
5757
// import {pathPosixToWin32, pathWin32ToPosix,win32ToWin32JS,win32ToWin32Slash,win32ToWin32WSL2} from "##/lib/dist/index.mjs";
58-
import {pathPosixToWin32, pathWin32ToPosix,win32ToWin32JS,win32ToWin32Slash,win32ToWin32WSL2} from "~/lib/dist/index.mjs";
58+
import {pathPosixToWin32, pathWin32ToPosix,win32ToWin32JS,win32ToWin32Slash,win32ToWin32WSL2} from "##/lib/dist/index.mjs";
5959
export default {
6060
name:'app',
6161
mounted(){

dev/node-fs-utils-dev/SpawnCmd.mjs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,26 @@ import { spawn } from 'node:child_process'
1111
import {stdout,stderr} from 'node:process'
1212

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

18-
let spawnCmd = spawn(cmd,[],{shell:true});
19+
// let spawnCmd = spawn(cmd,[],{shell:true});
20+
let spawnCmd = spawn(cmd,args,actual);
1921

2022
//i think on error need to double check
2123
spawnCmd.on('error',(err)=>{
2224
reject(err);
2325
});
26+
spawnCmd.stdout.pipe(stdout);//works
2427
spawnCmd.stdout.on('data', (data) => {
2528
// console.log(`stdout: ${data}`);
2629
stdouts.push(data);
2730
});
28-
spawnCmd.stdout.pipe(stdout);//works
2931
/* doesnt work pipe on chai, but two on's work n*/
3032

33+
spawnCmd.stderr.pipe(stderr)
3134
spawnCmd.stderr.on('data', (data) => {
3235
// console.error(`stderr: ${data}`);
3336
stderrs.push(data);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import readline from 'node:readline'
2+
import { stdin as input, stdout as output } from 'node:process';
3+
import {promisify} from 'node:util';
4+
5+
let rl = readline.createInterface({
6+
input,
7+
output,
8+
prompt:'hit enter to continue'
9+
});
10+
const question = promisify(rl.question).bind(rl);
11+
const tmp = await question('What is your name?')
12+
console.log('tmp is ',tmp);
13+
14+
rl.close();
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/**
2+
* Also in material design 3.. git
3+
*/
4+
5+
/**
6+
yarn add mocha -D
7+
8+
package.json
9+
"imports": {
10+
"##/*": {
11+
"default": "./*"
12+
},
13+
},
14+
"type": "module",
15+
16+
jsconfig.json
17+
{
18+
"compilerOptions": {
19+
"baseUrl": ".",
20+
"paths": {
21+
"##/*": ["./*"]
22+
}
23+
},
24+
"exclude": ["node_modules", ".nuxt", "dist"]
25+
}
26+
27+
28+
29+
*/
30+
// import { createRequire } from 'module';
31+
// const require = createRequire(import.meta.url);
32+
// const assert = require('assert');
33+
// const {describe,it} = require('mocha');
34+
import assert from 'node:assert';
35+
import { describe, it} from 'mocha';
36+
/*
37+
1.
38+
yarn add mocha @babel/polyfill @babel/register @babel/preset-env babel-plugin-module-resolver --dev
39+
yarn add @babel/core --dev
40+
2.
41+
-r @babel/register -r babel-plugin-module-resolver
42+
43+
3.
44+
.babelrc
45+
{
46+
47+
"presets": ["@babel/preset-env"],
48+
"plugins": [
49+
["module-resolver", {
50+
"root": ["./src"],
51+
"alias": {
52+
"test": "./test",
53+
"underscore": "lodash",
54+
55+
"~": "./"
56+
}
57+
}]
58+
]
59+
60+
}
61+
test specific timeout
62+
this.timeout(500);//500ms
63+
*/
64+
/**
65+
* Should put this somewhere safe
66+
* todo filepath needs to be initialized as well...
67+
* @param fileName .json
68+
* @param data will automatically be changed
69+
*/
70+
import fs from 'node:fs';
71+
function writeToFile(fileName,data,space=2){
72+
const sFileName = /\./.test(fileName) ? fileName : fileName + '.json';
73+
const filePath = `dev/pbs/test/${sFileName}`
74+
fs.writeFileSync(filePath,
75+
typeof data === 'string' ? data :JSON.stringify(data,null,+space)
76+
);
77+
}
78+
import {relative,resolve,join} from "node:path/posix";
79+
import {fileURLToPath} from "url";
80+
81+
describe('vite-press-path-utils.test.mjs', function(){
82+
let viteConfigFile;
83+
/** @type {'docs/.vitepress' | string} - .vitepress config */
84+
viteConfigFile = 'docs/.vitepress';
85+
86+
const testMatrix = [
87+
//"" is cwd
88+
[resolve(""),"../.."],//,cwd, new URL('./',import.meta.url).pathname???
89+
[resolve("./src"),"../../src"],//cwd/src, cant be ../src
90+
[resolve("src"),"../../src"],//cwd/src, same as above. left is okay to repeat
91+
[resolve("./docs/src"),"../src"],
92+
// [resolve("./docs"),"../"],//'../' also works and is more clear
93+
[resolve("./docs"),".."],//'../' also works and is more clear
94+
]
95+
it('first try', function(){
96+
for (let i = 0; i < testMatrix.length; i++) {
97+
const [expectedPath,inputRelativePathParam] = testMatrix[i];
98+
// destDirCWD = '';
99+
// const out = relative(inputRelativePathParam,viteConfigFile);
100+
/** Resolve docs/.vitepress with relative path to destination dir */
101+
const out = resolve(viteConfigFile,inputRelativePathParam);//reverse
102+
// const out = resolve('./',viteConfigFile);
103+
// console.log(import.meta.url);
104+
// const tmp = fileURLToPath(new URL('../..', import.meta.url))
105+
assert.strictEqual(out,expectedPath);
106+
}
107+
108+
109+
//assert.strictEqual(1,1);//require assert
110+
});
111+
it('reverse use case', function(){
112+
for (let i = 0; i < testMatrix.length; i++) {
113+
const [inputDestinationPath,expectedRelativePath] = testMatrix[i]; //reversed
114+
const out = relative(viteConfigFile, inputDestinationPath);// some of the relative paths may not work
115+
assert.strictEqual(out,expectedRelativePath);
116+
}
117+
118+
119+
//assert.strictEqual(1,1);//require assert
120+
});
121+
122+
});

docs/src/readme_vite_press.md

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,41 @@
22
1. Need to use vscode / webstorm to inject the header or w/e
33
* i think there is also called a snippet / wrapper / file template
44

5+
6+
## Install
7+
```bash
8+
pnpm add -D vitepress
9+
pnpm dlx vitepress init
10+
```
11+
```gitignore
12+
/docs/.vitepress/cache/
13+
/docs/.vitepress/dist/
14+
```
15+
```js
16+
import { defineConfig } from 'vitepress'
17+
//append to generated:
18+
export default defineConfig({
19+
base:"/material-design-3-import-export-ext/",
20+
srcDir: './src',//relative to the package.json vitepress dev <dir>
21+
lang: 'en-ca',
22+
//section inside
23+
themeConfig: {
24+
//add better search. https://vitepress.dev/reference/default-theme-search#local-search
25+
search: {
26+
provider: 'local'
27+
},
28+
socialLinks: [
29+
{ icon: 'github', link: 'https://github.com/codeforwings/material-design-3-import-export-ext' }
30+
],
31+
markdown:{
32+
//https://vitepress.dev/reference/site-config#markdown
33+
lineNumbers: true,
34+
space_size: 2,//not sure if this works
35+
}
36+
}
37+
})
38+
39+
```
540
# Concepts
641
* "On this page"
742
* Edit on GitHub
@@ -29,11 +64,7 @@
2964

3065
Notes
3166
---
32-
## Git Ignore
33-
```gitignore
34-
/docs/.vitepress/cache/
35-
/docs/.vitepress/dist/
36-
```
67+
3768
# Syntax Highlighting
3869
[https://github.com/shikijs/shiki/blob/main/docs/languages.md](https://github.com/shikijs/shiki/blob/main/docs/languages.md)
3970
```js

docs/src/vitepress/readme_vite_press_paths.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,10 @@ docs/src/public/
8585
<<< @/public/some_folder/some_file.json
8686

8787

88-
```
88+
```
89+
90+
## Interesting
91+
```ps1
92+
# mixing paths actually works in powershell and pwd... with no spaces at least and explorer... crazy
93+
cd C:\Users\Public/bins
94+
```

lib/bin_build/bin-vite.config.mjs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Bin builder for vite config
3+
*/
4+
// Utilities
5+
import { defineConfig } from 'vite'
6+
import { fileURLToPath, URL } from 'node:url'
7+
import {rootFileUrl, viteBaseConfig} from "##/vite.config.mjs";
8+
// import { resolve } from 'node:path'
9+
// https://vitejs.dev/config/
10+
export default defineConfig({
11+
...viteBaseConfig,
12+
build: {
13+
//https://vitejs.dev/guide/build.html#library-mode
14+
outDir: fileURLToPath(new URL('./lib/bin_build/.output/', rootFileUrl)),
15+
lib: {
16+
name: 'nuxt3-win32-posix-path',
17+
formats: ['es', 'cjs'],//('es' | 'cjs' | 'umd' | 'iife')
18+
entry: [ //"entry" can be a dictionary or array of multiple entry points
19+
fileURLToPath(new URL('./lib/bin_build/index.mjs', rootFileUrl)),
20+
]
21+
},
22+
rollupOptions: {
23+
// make sure to externalize deps that shouldn't be bundled
24+
// into your library
25+
// external: ['puppeteer',"puppeteer-core","node:path/posix","node*"],
26+
output: {
27+
// Provide global variables to use in the UMD build
28+
// for externalized deps
29+
// globals: {
30+
// vue: 'Vue',//not sure what this means
31+
// },
32+
},
33+
},
34+
},
35+
36+
})

lib/bin_build/index.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Bin Build Index Packager
3+
* maybe add cli builder / handler here
4+
lib/bin_build/dist/index-win.exe c:/Users/Public/Documents
5+
6+
node lib/bin_build/index.mjs c:/Users/Public/Documents
7+
node lib/bin_build/index.mjs "c:/Users/Public/Docum ents"
8+
node lib/bin_build/index.mjs c:/Users/Public/Docum ents
9+
*
10+
* todo think about how to test this properly performance wise
11+
* it's surprisingly not bad. powershell was much slower...
12+
*/
13+
// import process from "node:process";
14+
import {win32ToWin32WSL2} from "##/src/win32ToWin32WSL/win32ToWin32WSL2.mjs";
15+
// export {win32ToWin32WSL2}
16+
17+
/* take arguments from command line */
18+
const args = process.argv.slice(2);
19+
// console.log(args);
20+
// console.log(win32ToWin32WSL2(args[0]))
21+
console.log(win32ToWin32WSL2(args.join(' ')))
22+
process.exit(0)

lib/test-utils/mocha-cli-exec.mjs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {spawnSync} from "node:child_process";
2+
import assert from "node:assert";
3+
4+
/**
5+
* factory function
6+
*/
7+
/**
8+
*
9+
* @param pathToExe
10+
* @param args
11+
* @param options
12+
* @return {(function(*, *): void)|*}
13+
* @example
14+
* const assertW2Wb = createMochaCliExe(W2WB);1
15+
*/
16+
export function createMochaCliExe(pathToExe,args=[],options={}){
17+
//todo add better defaulting etc... didnt think i neeeded to modify the input
18+
const actualOptions = {shell:true,...options}
19+
20+
return function(expectedValue,...inputToTest){
21+
const output = spawnSync(
22+
// `"${W2WB}" [C:\\` //cmd needs to double quote
23+
// `"${pathToExe}"`,[WSLPassTests[0][0]],actualOptions
24+
`"${pathToExe}"`,[...inputToTest],actualOptions
25+
);
26+
if(output.status !== 0){
27+
console.error(output);
28+
console.log(output.stdout.toString())
29+
console.error(output.stderr.toString())
30+
throw new Error("status not 0");
31+
}
32+
const actual = output.stdout.toString().trim();
33+
console.assert(actual === expectedValue,`inputToTest: ${inputToTest}`)
34+
assert.strictEqual(actual,expectedValue);
35+
}
36+
37+
}

lib/test-utils/pwsh-test-mocha.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!pwsh.exe
2+
<#
3+
todo move this somewhere
4+
Test powershell inside of mocha... source and import?
5+
cd C:\Users\Jason\WebstormProjects\nuxt3-win32-posix-path
6+
pwsh.exe -File pwsh-test-mocha.ps1 c:\hi
7+
pwsh.exe -File lib/test-utils/pwsh-test-mocha.ps1 c:\hi s
8+
#>
9+
10+
# import-module -Name ./src/win32ToWin32WSL/win32ToWin32WSL2.ps1 -Function pathWin32ToPosix
11+
# source
12+
# powershell -Command ./src/win32ToWin32WSL/win32ToWin32WSL2.ps1; pathWin32ToPosix 'c:\hi'
13+
#write-host -NoNewline $args[0]
14+
. ./src/win32ToWin32WSL/win32ToWin32WSL2.ps1;
15+
$tmp=pathWin32ToPosix $args[0]
16+
write-host -NoNewline $tmp

0 commit comments

Comments
 (0)