juisy 2.0.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli/index.js +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/index.js +85 -12
- package/dist/templater/index.js +1 -1
- package/dist/utils/misc.d.ts +64 -1
- package/dist/vite/plugins/inject-css-variables/index.js +1 -1
- package/dist/vite/plugins/inject-project-globals/index.js +1 -1
- package/package.json +2 -2
package/bin/cli/index.js
CHANGED
package/dist/cli/index.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* juisy v2.0
|
|
2
|
+
* juisy v2.2.0
|
|
3
3
|
* Copyright © 2022-Present Hervé Perchec
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import path, { dirname } from 'node:path';
|
|
6
|
+
import path$1, { dirname } from 'node:path';
|
|
7
7
|
import { readdir, readFileSync } from 'node:fs';
|
|
8
8
|
import { glob } from 'glob';
|
|
9
|
+
import { packageDirectorySync } from 'pkg-dir';
|
|
9
10
|
import yaml from 'yaml';
|
|
10
11
|
import { json2csv } from 'json-2-csv';
|
|
11
12
|
import jstoxml from 'jstoxml';
|
|
12
13
|
import fs from 'fs-extra';
|
|
13
14
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
14
|
-
import { packageDirectorySync } from 'pkg-dir';
|
|
15
15
|
import log from 'loglevel';
|
|
16
16
|
import { Templater } from 'juisy/templater';
|
|
17
17
|
import dotenv from '@dotenvx/dotenvx';
|
|
@@ -24,7 +24,7 @@ function getFileUrls(pattern, options) {
|
|
|
24
24
|
async function* getFiles(dir) {
|
|
25
25
|
const dirents = await readdir(dir, { withFileTypes: true });
|
|
26
26
|
for (const dirent of dirents) {
|
|
27
|
-
const res = path.resolve(dir, dirent.name);
|
|
27
|
+
const res = path$1.resolve(dir, dirent.name);
|
|
28
28
|
if (dirent.isDirectory()) {
|
|
29
29
|
yield* getFiles(res);
|
|
30
30
|
} else {
|
|
@@ -32,11 +32,84 @@ async function* getFiles(dir) {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
+
function getRootDir() {
|
|
36
|
+
return packageDirectorySync();
|
|
37
|
+
}
|
|
38
|
+
const path = {
|
|
39
|
+
/**
|
|
40
|
+
* Convert a path to win32 format (with `\\` separator)
|
|
41
|
+
* @param val - The path to convert
|
|
42
|
+
* @example
|
|
43
|
+
* utils.path.toWin32('a/posix/path') // => 'a\posix\path'
|
|
44
|
+
* utils.path.toWin32('C:\\a\\win32\\absolute\\path') // => 'C:\a\win32\absolute\path'
|
|
45
|
+
* utils.path.toWin32('a/mixed\\path') // => 'a\mixed\path'
|
|
46
|
+
*/
|
|
47
|
+
toWin32(val) {
|
|
48
|
+
return val.split(path$1.posix.sep).join(path$1.win32.sep);
|
|
49
|
+
},
|
|
50
|
+
/**
|
|
51
|
+
* Convert a path to posix format (with `/` separator)
|
|
52
|
+
* @param val - The path to convert
|
|
53
|
+
* @example
|
|
54
|
+
* utils.path.toPosix('a/posix/path') // => 'a/posix/path'
|
|
55
|
+
* utils.path.toPosix('C:\\a\\win32\\absolute\\path') // => 'C:/a/win32/absolute/path'
|
|
56
|
+
* utils.path.toPosix('a/mixed\\path') // => 'a/mixed/path'
|
|
57
|
+
*/
|
|
58
|
+
toPosix(val) {
|
|
59
|
+
return val.split(path$1.win32.sep).join(path$1.posix.sep);
|
|
60
|
+
},
|
|
61
|
+
/**
|
|
62
|
+
* Automatically convert a path to OS specific format
|
|
63
|
+
* @param val - The path to convert
|
|
64
|
+
*/
|
|
65
|
+
toOsFormat(val) {
|
|
66
|
+
const platform = process.platform;
|
|
67
|
+
return platform === "win32" ? path.toWin32(val) : path.toPosix(val);
|
|
68
|
+
},
|
|
69
|
+
/**
|
|
70
|
+
* Util to resolve a relative file path
|
|
71
|
+
* @param from - The "from" absolute file path
|
|
72
|
+
* @param to - The "to" absolute file path
|
|
73
|
+
* @param separator - (Optional) The separator type: can be `"posix"` or `"win32"`
|
|
74
|
+
* @returns The resolved relative path
|
|
75
|
+
* @example
|
|
76
|
+
* const base = 'C:\\Users\\JohnDoe\\Documents\\Projects\\MyProject'
|
|
77
|
+
*
|
|
78
|
+
* utils.path.resolveRel(base, 'C:\\Users\\JohnDoe\\Documents\\Projects\\MyProject\\src\\index.ts') // 'src\\index.ts'
|
|
79
|
+
* utils.path.resolveRel('C:\\Users\\JohnDoe\\Documents\\Projects\\MyProject\\src\\index.ts', base) // '..\\..'
|
|
80
|
+
* utils.path.resolveRel(base, 'C:\\Users\\JohnDoe\\Documents\\Projects\\MyProject\\src\\index.ts', 'posix') // 'src/index.ts'
|
|
81
|
+
*/
|
|
82
|
+
resolveRel(from, to, separator) {
|
|
83
|
+
const relativePath = path$1.relative(from, to);
|
|
84
|
+
return separator ? separator === "posix" ? path.toPosix(relativePath) : path.toWin32(relativePath) : path.toOsFormat(relativePath);
|
|
85
|
+
},
|
|
86
|
+
/**
|
|
87
|
+
* Util to resolve relative file path from root directory
|
|
88
|
+
* @param to - The absolute file path
|
|
89
|
+
* @param separator - (Optional) The separator type: can be `"posix"` or `"win32"`
|
|
90
|
+
* @returns The resolved relative path from root directory
|
|
91
|
+
*/
|
|
92
|
+
resolveRelFromRoot(to, separator) {
|
|
93
|
+
return path.resolveRel(getRootDir(), to, separator);
|
|
94
|
+
},
|
|
95
|
+
/**
|
|
96
|
+
* Util to resolve absolute file path from root directory
|
|
97
|
+
* @param to - The relative file path
|
|
98
|
+
* @param separator - (Optional) The separator type: can be `"posix"` or `"win32"`
|
|
99
|
+
* @returns The resolved absolute path from root directory
|
|
100
|
+
*/
|
|
101
|
+
resolveAbsFromRoot(to, separator) {
|
|
102
|
+
const absolutePath = path$1.join(getRootDir(), to);
|
|
103
|
+
return separator ? separator === "posix" ? path.toPosix(absolutePath) : path.toWin32(absolutePath) : path.toOsFormat(absolutePath);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
35
106
|
|
|
36
107
|
const misc = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
37
108
|
__proto__: null,
|
|
38
109
|
getFileUrls,
|
|
39
|
-
getFiles
|
|
110
|
+
getFiles,
|
|
111
|
+
getRootDir,
|
|
112
|
+
path
|
|
40
113
|
}, Symbol.toStringTag, { value: 'Module' }));
|
|
41
114
|
|
|
42
115
|
const xml = jstoxml.toXML;
|
|
@@ -121,7 +194,7 @@ async function isFile(filePath) {
|
|
|
121
194
|
}
|
|
122
195
|
}
|
|
123
196
|
async function ejectFile(from, to, identifier = null, options) {
|
|
124
|
-
identifier = identifier || path.basename(from);
|
|
197
|
+
identifier = identifier || path$1.basename(from);
|
|
125
198
|
const force = options?.force || false;
|
|
126
199
|
const templateData = options?.templateData;
|
|
127
200
|
const processor = options?.processor || (async (str, _identifier) => str);
|
|
@@ -157,10 +230,10 @@ async function eject(templateDir, identifier, options) {
|
|
|
157
230
|
throw new Error("eject: identifier is required");
|
|
158
231
|
} else {
|
|
159
232
|
try {
|
|
160
|
-
const fullPath = path.resolve(templateDir, identifier);
|
|
233
|
+
const fullPath = path$1.resolve(templateDir, identifier);
|
|
161
234
|
if (await isFile(fullPath)) {
|
|
162
235
|
if (!ignoreFiles.includes(identifier)) {
|
|
163
|
-
await ejectFile(fullPath, path.resolve(targetDir, identifier), identifier, {
|
|
236
|
+
await ejectFile(fullPath, path$1.resolve(targetDir, identifier), identifier, {
|
|
164
237
|
force: options?.force,
|
|
165
238
|
templateData: options?.templateData,
|
|
166
239
|
processor: options?.processor,
|
|
@@ -171,9 +244,9 @@ async function eject(templateDir, identifier, options) {
|
|
|
171
244
|
} else {
|
|
172
245
|
const globPattern = await isDirectory(fullPath) ? identifier + "/**/*" : identifier;
|
|
173
246
|
for (const fileRelativePath of getFileUrls(globPattern, { cwd: templateDir, nodir: true, posix: true, dot: true })) {
|
|
174
|
-
const fullTemplateFilePath = path.resolve(templateDir, fileRelativePath);
|
|
247
|
+
const fullTemplateFilePath = path$1.resolve(templateDir, fileRelativePath);
|
|
175
248
|
if (!ignoreFiles.includes(fileRelativePath)) {
|
|
176
|
-
await ejectFile(fullTemplateFilePath, path.resolve(targetDir, fileRelativePath), fileRelativePath, {
|
|
249
|
+
await ejectFile(fullTemplateFilePath, path$1.resolve(targetDir, fileRelativePath), fileRelativePath, {
|
|
177
250
|
force: options?.force,
|
|
178
251
|
templateData: options?.templateData,
|
|
179
252
|
processor: options?.processor,
|
|
@@ -191,7 +264,7 @@ async function eject(templateDir, identifier, options) {
|
|
|
191
264
|
}
|
|
192
265
|
|
|
193
266
|
function getPackageInfo() {
|
|
194
|
-
const pkgPath = path.resolve(packageDirectorySync(), "./package.json");
|
|
267
|
+
const pkgPath = path$1.resolve(packageDirectorySync(), "./package.json");
|
|
195
268
|
return JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
196
269
|
}
|
|
197
270
|
|
|
@@ -247,7 +320,7 @@ function defineGlobals(config, builder) {
|
|
|
247
320
|
return deepmerge(GLOBALS, JSON.parse(JSON.stringify(builder(ctx))));
|
|
248
321
|
}
|
|
249
322
|
async function getProjectGlobals(filePath = "./project.globals.js") {
|
|
250
|
-
return (await import(pathToFileURL(path.resolve(filePath)))).default;
|
|
323
|
+
return (await import(pathToFileURL(path$1.resolve(filePath)))).default;
|
|
251
324
|
}
|
|
252
325
|
|
|
253
326
|
export { DataExporter, defineGlobals, eject, getPackageInfo, getProjectGlobals, misc as utils };
|
package/dist/templater/index.js
CHANGED
package/dist/utils/misc.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GlobOptions } from 'glob';
|
|
2
2
|
/**
|
|
3
3
|
* @param pattern - Same as node-glob pattern argument
|
|
4
|
-
* @param options - Same as
|
|
4
|
+
* @param options - Same as glob options argument
|
|
5
5
|
* @returns {string[]} Returns an array of file path
|
|
6
6
|
* @description
|
|
7
7
|
* Get file urls that match glob (see: https://github.com/isaacs/node-glob)
|
|
@@ -19,3 +19,66 @@ export declare function getFileUrls(pattern: string, options?: GlobOptions): str
|
|
|
19
19
|
* utils.getFiles(path) // => [ 'path/to/file1', 'path/to/file2', ... ]
|
|
20
20
|
*/
|
|
21
21
|
export declare function getFiles(dir: string): AsyncGenerator<string[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Synchronously find the root directory of the project in which juisy is installed.
|
|
24
|
+
*
|
|
25
|
+
* It is just a wrapper around the `packageDirectorySync` function
|
|
26
|
+
* from [pkg-dir](https://www.npmjs.com/package/pkg-dir) library.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getRootDir(): string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Utils related to path
|
|
31
|
+
*/
|
|
32
|
+
export declare const path: {
|
|
33
|
+
/**
|
|
34
|
+
* Convert a path to win32 format (with `\\` separator)
|
|
35
|
+
* @param val - The path to convert
|
|
36
|
+
* @example
|
|
37
|
+
* utils.path.toWin32('a/posix/path') // => 'a\posix\path'
|
|
38
|
+
* utils.path.toWin32('C:\\a\\win32\\absolute\\path') // => 'C:\a\win32\absolute\path'
|
|
39
|
+
* utils.path.toWin32('a/mixed\\path') // => 'a\mixed\path'
|
|
40
|
+
*/
|
|
41
|
+
toWin32(val: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* Convert a path to posix format (with `/` separator)
|
|
44
|
+
* @param val - The path to convert
|
|
45
|
+
* @example
|
|
46
|
+
* utils.path.toPosix('a/posix/path') // => 'a/posix/path'
|
|
47
|
+
* utils.path.toPosix('C:\\a\\win32\\absolute\\path') // => 'C:/a/win32/absolute/path'
|
|
48
|
+
* utils.path.toPosix('a/mixed\\path') // => 'a/mixed/path'
|
|
49
|
+
*/
|
|
50
|
+
toPosix(val: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* Automatically convert a path to OS specific format
|
|
53
|
+
* @param val - The path to convert
|
|
54
|
+
*/
|
|
55
|
+
toOsFormat(val: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* Util to resolve a relative file path
|
|
58
|
+
* @param from - The "from" absolute file path
|
|
59
|
+
* @param to - The "to" absolute file path
|
|
60
|
+
* @param separator - (Optional) The separator type: can be `"posix"` or `"win32"`
|
|
61
|
+
* @returns The resolved relative path
|
|
62
|
+
* @example
|
|
63
|
+
* const base = 'C:\\Users\\JohnDoe\\Documents\\Projects\\MyProject'
|
|
64
|
+
*
|
|
65
|
+
* utils.path.resolveRel(base, 'C:\\Users\\JohnDoe\\Documents\\Projects\\MyProject\\src\\index.ts') // 'src\\index.ts'
|
|
66
|
+
* utils.path.resolveRel('C:\\Users\\JohnDoe\\Documents\\Projects\\MyProject\\src\\index.ts', base) // '..\\..'
|
|
67
|
+
* utils.path.resolveRel(base, 'C:\\Users\\JohnDoe\\Documents\\Projects\\MyProject\\src\\index.ts', 'posix') // 'src/index.ts'
|
|
68
|
+
*/
|
|
69
|
+
resolveRel(from: string, to: string, separator?: "posix" | "win32"): string;
|
|
70
|
+
/**
|
|
71
|
+
* Util to resolve relative file path from root directory
|
|
72
|
+
* @param to - The absolute file path
|
|
73
|
+
* @param separator - (Optional) The separator type: can be `"posix"` or `"win32"`
|
|
74
|
+
* @returns The resolved relative path from root directory
|
|
75
|
+
*/
|
|
76
|
+
resolveRelFromRoot(to: string, separator?: "posix" | "win32"): string;
|
|
77
|
+
/**
|
|
78
|
+
* Util to resolve absolute file path from root directory
|
|
79
|
+
* @param to - The relative file path
|
|
80
|
+
* @param separator - (Optional) The separator type: can be `"posix"` or `"win32"`
|
|
81
|
+
* @returns The resolved absolute path from root directory
|
|
82
|
+
*/
|
|
83
|
+
resolveAbsFromRoot(to: string, separator?: "posix" | "win32"): string;
|
|
84
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "juisy",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Make you JavaScript (and/or TypeScript) project juicy!",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
},
|
|
93
93
|
"homepage": "https://hperchec.gitlab.io/juisy",
|
|
94
94
|
"bin": {
|
|
95
|
-
"juisy": "
|
|
95
|
+
"juisy": "bin/cli/index.js"
|
|
96
96
|
},
|
|
97
97
|
"peerDependencies": {
|
|
98
98
|
"@commitlint/cli": "^19.6.1",
|