chokibasic 1.1.12 → 1.2.1
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/index.d.ts +33 -58
- package/index.js +1 -0
- package/package.json +3 -1
- package/readme.md +1 -1
- package/src/buildconf.js +74 -0
package/index.d.ts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
|
-
|
|
2
1
|
declare namespace chokibasic {
|
|
2
|
+
// --- NOUVEAUX TYPES POUR buildConf ---
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Callback pour buildConf.
|
|
6
|
+
* Reçoit le contenu brut (Buffer) et le chemin relatif du fichier.
|
|
7
|
+
* Doit retourner la nouvelle valeur (string, objet, etc.) qui remplacera le chemin dans le JSON final.
|
|
8
|
+
*/
|
|
9
|
+
export type BuildConfCallback = (content: Buffer, relPath: string) => any | Promise<any>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Dictionnaire de patterns globaux associés à des callbacks de transformation.
|
|
13
|
+
* Exemple: { "** / *.mid": (buf) => processMidi(buf) }
|
|
14
|
+
*/
|
|
15
|
+
export interface BuildConfMatchers {
|
|
16
|
+
[glob: string]: BuildConfCallback;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// --- TYPES EXISTANTS ---
|
|
20
|
+
|
|
3
21
|
export type GlobPattern = string;
|
|
4
22
|
|
|
5
23
|
export type IgnoreMatcher =
|
|
@@ -10,9 +28,7 @@ declare namespace chokibasic {
|
|
|
10
28
|
export type WatchEventType = "add" | "change" | "unlink" | (string & {});
|
|
11
29
|
|
|
12
30
|
export interface WatchEvent {
|
|
13
|
-
/** Type d’évènement (dans le code actuel: surtout "change") */
|
|
14
31
|
type: WatchEventType;
|
|
15
|
-
/** Chemin relatif à cwd, normalisé POSIX (slash "/") */
|
|
16
32
|
file: string;
|
|
17
33
|
}
|
|
18
34
|
|
|
@@ -21,22 +37,10 @@ declare namespace chokibasic {
|
|
|
21
37
|
}
|
|
22
38
|
|
|
23
39
|
export interface WatchRule {
|
|
24
|
-
/** Nom affiché en debug */
|
|
25
40
|
name?: string;
|
|
26
|
-
|
|
27
|
-
/** Globs d’inclusion (ex: "src/styles/ ** / *.scss") */
|
|
28
41
|
patterns: GlobPattern | GlobPattern[];
|
|
29
|
-
|
|
30
|
-
/** Ignorés additionnels (globs / regex / function) */
|
|
31
42
|
ignored?: IgnoreMatcher[];
|
|
32
|
-
|
|
33
|
-
/** Debounce en ms (défaut: 150) */
|
|
34
43
|
debounceMs?: number;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Callback appelé avec un batch d’évènements.
|
|
38
|
-
* Le batch contient des objets { type, file }.
|
|
39
|
-
*/
|
|
40
44
|
callback: (events: WatchEvent[], ctx: WatchRuleContext) => void | Promise<void>;
|
|
41
45
|
}
|
|
42
46
|
|
|
@@ -46,39 +50,18 @@ declare namespace chokibasic {
|
|
|
46
50
|
}
|
|
47
51
|
|
|
48
52
|
export interface CreateWatchersOptions {
|
|
49
|
-
/** Répertoire racine utilisé pour calculer les chemins relatifs */
|
|
50
53
|
cwd?: string;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Ignorés globaux (appliqués dans queue(), pas via chokidar "ignored")
|
|
54
|
-
* Défaut: ["** /node_modules/ **","** /.git/ **","** /dist/ **"]
|
|
55
|
-
*/
|
|
56
54
|
globalIgnored?: string[];
|
|
57
|
-
|
|
58
|
-
/** chokidar: ignoreInitial */
|
|
59
55
|
ignoreInitial?: boolean;
|
|
60
|
-
|
|
61
|
-
/** chokidar: awaitWriteFinish */
|
|
62
56
|
awaitWriteFinish?: boolean | AwaitWriteFinishOptions;
|
|
63
|
-
|
|
64
|
-
/** chokidar: usePolling */
|
|
65
57
|
usePolling?: boolean;
|
|
66
|
-
|
|
67
|
-
/** chokidar: interval */
|
|
68
58
|
interval?: number;
|
|
69
|
-
|
|
70
|
-
/** chokidar: binaryInterval */
|
|
71
59
|
binaryInterval?: number;
|
|
72
|
-
|
|
73
|
-
/** Log console */
|
|
74
60
|
debug?: boolean;
|
|
75
|
-
|
|
76
|
-
/** Permet d’accepter d’autres options sans casser les types */
|
|
77
61
|
[key: string]: unknown;
|
|
78
62
|
}
|
|
79
63
|
|
|
80
64
|
export interface WatchersController {
|
|
81
|
-
/** Ferme tous les watchers et annule les timers */
|
|
82
65
|
close: () => Promise<void>;
|
|
83
66
|
}
|
|
84
67
|
|
|
@@ -94,23 +77,28 @@ declare namespace chokibasic {
|
|
|
94
77
|
filter?: (relPath: string) => boolean;
|
|
95
78
|
}
|
|
96
79
|
|
|
97
|
-
/** Options forwardées à esbuild.build() */
|
|
98
80
|
export type BuildJSOptions = Parameters<typeof import("esbuild").build>[0];
|
|
99
|
-
|
|
100
|
-
/** Options forwardées à sass.compile() */
|
|
101
81
|
export type BuildCSSOptions = NonNullable<Parameters<typeof import("sass").compile>[1]>;
|
|
102
82
|
|
|
83
|
+
// --- FONCTIONS EXPORTÉES ---
|
|
84
|
+
|
|
103
85
|
/**
|
|
104
|
-
*
|
|
86
|
+
* Transforme un fichier YAML en JSON en appliquant des transformations sur les fichiers référencés.
|
|
87
|
+
* @param src Chemin vers le fichier source YAML.
|
|
88
|
+
* @param dst Chemin vers le fichier de destination JSON.
|
|
89
|
+
* @param matchers Dictionnaire de patterns et callbacks de transformation.
|
|
105
90
|
*/
|
|
91
|
+
export function buildConf(
|
|
92
|
+
src: string,
|
|
93
|
+
dst: string,
|
|
94
|
+
matchers?: BuildConfMatchers
|
|
95
|
+
): Promise<void>;
|
|
96
|
+
|
|
106
97
|
export function createWatchers(
|
|
107
98
|
rules: WatchRule[],
|
|
108
99
|
options?: CreateWatchersOptions
|
|
109
100
|
): WatchersController;
|
|
110
101
|
|
|
111
|
-
/**
|
|
112
|
-
* Exporte un dossier `src` vers `dist` en respectant .gitignore + exclusions.
|
|
113
|
-
*/
|
|
114
102
|
export function exportDist(
|
|
115
103
|
src: string,
|
|
116
104
|
dist: string,
|
|
@@ -118,38 +106,25 @@ declare namespace chokibasic {
|
|
|
118
106
|
options?: ExportDistOptions
|
|
119
107
|
): Promise<ExportDistStats>;
|
|
120
108
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Compile SCSS -> CSS minifié (csso), écrit dans outCssMin.
|
|
125
|
-
*/
|
|
126
109
|
export function buildCSS(
|
|
127
110
|
inputScss: string,
|
|
128
111
|
outCssMin: string,
|
|
129
112
|
options?: BuildCSSOptions
|
|
130
113
|
): Promise<void>;
|
|
131
114
|
|
|
132
|
-
/**
|
|
133
|
-
* Bundle/minify JS via esbuild.
|
|
134
|
-
*/
|
|
135
115
|
export function buildJS(
|
|
136
116
|
entry: string,
|
|
137
117
|
outfile: string,
|
|
138
118
|
options?: BuildJSOptions
|
|
139
119
|
): Promise<void>;
|
|
140
120
|
|
|
141
|
-
/**
|
|
142
|
-
* Rend un fichier via pxpros.render(file).
|
|
143
|
-
*/
|
|
144
121
|
export function buildPHP(file: string): Promise<void>;
|
|
145
122
|
|
|
146
|
-
/**
|
|
147
|
-
* Génère un sitemap via pxpros.sitemap(file).
|
|
148
|
-
*/
|
|
149
123
|
export function buildSitemap(file: string): Promise<void>;
|
|
150
124
|
}
|
|
151
125
|
|
|
152
126
|
declare const chokibasic: {
|
|
127
|
+
buildConf: typeof chokibasic.buildConf; // Ajouté ici aussi
|
|
153
128
|
createWatchers: typeof chokibasic.createWatchers;
|
|
154
129
|
exportDist: typeof chokibasic.exportDist;
|
|
155
130
|
buildCSS: typeof chokibasic.buildCSS;
|
|
@@ -159,4 +134,4 @@ declare const chokibasic: {
|
|
|
159
134
|
};
|
|
160
135
|
|
|
161
136
|
export = chokibasic;
|
|
162
|
-
export as namespace chokibasic;
|
|
137
|
+
export as namespace chokibasic;
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chokibasic",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Basic chokidar watcher + pxpros + esbuild + sass + csso helpers",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -35,6 +35,8 @@
|
|
|
35
35
|
"csso": "^5.0.5",
|
|
36
36
|
"esbuild": "^0.28.0",
|
|
37
37
|
"ignore": "^7.0.5",
|
|
38
|
+
"js-yaml": "^4.1.1",
|
|
39
|
+
"picomatch": "^4.0.4",
|
|
38
40
|
"pxpros": "^1.1.3",
|
|
39
41
|
"sass": "^1.99.0"
|
|
40
42
|
}
|
package/readme.md
CHANGED
package/src/buildconf.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const fs = require("fs").promises;
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const yaml = require("js-yaml");
|
|
4
|
+
const pm = require("picomatch");
|
|
5
|
+
|
|
6
|
+
const ROOT = process.cwd();
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async function getMetadata() {
|
|
10
|
+
let version = "0.0.0";
|
|
11
|
+
try {
|
|
12
|
+
const pkg = JSON.parse(await fs.readFile(path.join(ROOT, "package.json"), "utf8"));
|
|
13
|
+
version = pkg.version || version;
|
|
14
|
+
} catch (e) {}
|
|
15
|
+
|
|
16
|
+
const now = new Date();
|
|
17
|
+
const pad = (n) => n.toString().padStart(2, '0');
|
|
18
|
+
const dateStr = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}`;
|
|
19
|
+
|
|
20
|
+
return { version, date: dateStr };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
async function walkAndTransform(node, matchers, metadata) {
|
|
25
|
+
if (Array.isArray(node)) {
|
|
26
|
+
return await Promise.all(node.map(item => walkAndTransform(item, matchers, metadata)));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (typeof node === 'object' && node !== null) {
|
|
30
|
+
const newNode = {};
|
|
31
|
+
for (const [key, value] of Object.entries(node)) {
|
|
32
|
+
newNode[key] = await walkAndTransform(value, matchers, metadata);
|
|
33
|
+
}
|
|
34
|
+
return newNode;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (typeof node === 'string') {
|
|
38
|
+
let processedString = node
|
|
39
|
+
.replace(/__VERSION__/g, metadata.version)
|
|
40
|
+
.replace(/__DATE__/g, metadata.date);
|
|
41
|
+
|
|
42
|
+
const fullPath = path.join(ROOT, processedString);
|
|
43
|
+
try {
|
|
44
|
+
const stats = await fs.stat(fullPath);
|
|
45
|
+
if (stats.isFile()) {
|
|
46
|
+
for (const [pattern, callback] of Object.entries(matchers)) {
|
|
47
|
+
if (pm(pattern)(processedString)) {
|
|
48
|
+
const content = await fs.readFile(fullPath);
|
|
49
|
+
return await callback(content, processedString);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} catch (err) {}
|
|
54
|
+
return processedString;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return node;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
async function buildConf(src, dst, matchers = {}) {
|
|
62
|
+
try {
|
|
63
|
+
const metadata = await getMetadata();
|
|
64
|
+
const fileContents = await fs.readFile(src, 'utf8');
|
|
65
|
+
const rawData = yaml.load(fileContents);
|
|
66
|
+
const processedData = await walkAndTransform(rawData, matchers, metadata);
|
|
67
|
+
await fs.writeFile(dst, JSON.stringify(processedData, null, 2), 'utf8');
|
|
68
|
+
console.log(`✅ Build réussi : ${dst} (${metadata.version})`);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error("❌ Erreur :", error);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports = { buildConf };
|