@tilli-pro/cookieconsent-plugin 0.2.0 → 0.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/package.json +11 -11
- package/scripts/postbuild/inject-plugin.ts +78 -8
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@tilli-pro/cookieconsent-plugin",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.1",
|
4
4
|
"private": false,
|
5
5
|
"publishConfig": {
|
6
6
|
"access": "public"
|
@@ -19,14 +19,6 @@
|
|
19
19
|
]
|
20
20
|
}
|
21
21
|
},
|
22
|
-
"scripts": {
|
23
|
-
"build": "tsc && cpx \"src/**/*.css\" dist",
|
24
|
-
"postbuild": "tsx ./scripts/postbuild/inject-plugin.ts",
|
25
|
-
"clean": "git clean -xdf .cache .turbo dist node_modules",
|
26
|
-
"format": "prettier --check . --ignore-path ../../.gitignore --ignore-path .gitignore",
|
27
|
-
"lint": "eslint",
|
28
|
-
"typecheck": "tsc --noEmit --emitDeclarationOnly false"
|
29
|
-
},
|
30
22
|
"dependencies": {
|
31
23
|
"@tilli-pro/cookieconsent": "3.0.1",
|
32
24
|
"next": "14.2.15",
|
@@ -45,5 +37,13 @@
|
|
45
37
|
"tsx": "4.19.3",
|
46
38
|
"typescript": "5.6.2"
|
47
39
|
},
|
48
|
-
"prettier": "@tilli-pro/prettier-config"
|
49
|
-
|
40
|
+
"prettier": "@tilli-pro/prettier-config",
|
41
|
+
"scripts": {
|
42
|
+
"build": "tsc && cpx \"src/**/*.css\" dist",
|
43
|
+
"postbuild": "tsx ./scripts/postbuild/inject-plugin.ts",
|
44
|
+
"clean": "git clean -xdf .cache .turbo dist node_modules",
|
45
|
+
"format": "prettier --check . --ignore-path ../../.gitignore --ignore-path .gitignore",
|
46
|
+
"lint": "eslint",
|
47
|
+
"typecheck": "tsc --noEmit --emitDeclarationOnly false"
|
48
|
+
}
|
49
|
+
}
|
@@ -10,24 +10,94 @@ const sourceDir = path.resolve(__dirname, "..", "..", "dist");
|
|
10
10
|
const destDir = path.resolve(__dirname, "..", "..", "..", "dist", "plugin"); // new plugin folder
|
11
11
|
|
12
12
|
function injectPlugin(src: string, dest: string): void {
|
13
|
-
|
14
|
-
|
13
|
+
try {
|
14
|
+
if (!fs.existsSync(dest)) fs.mkdirSync(dest, { recursive: true });
|
15
|
+
} catch (err) {
|
16
|
+
console.error(`Failed to create directory ${dest}:`, err);
|
17
|
+
throw err;
|
18
|
+
}
|
15
19
|
|
16
|
-
|
20
|
+
let entries;
|
21
|
+
try {
|
22
|
+
entries = fs.readdirSync(src, { withFileTypes: true });
|
23
|
+
} catch (err) {
|
24
|
+
console.error(`Failed to read directory ${src}:`, err);
|
25
|
+
throw err;
|
26
|
+
}
|
17
27
|
|
18
28
|
for (const entry of entries) {
|
19
29
|
const srcPath = path.join(src, entry.name);
|
20
30
|
const destPath = path.join(dest, entry.name);
|
21
31
|
|
22
|
-
if (entry.isDirectory())
|
23
|
-
|
32
|
+
if (entry.isDirectory()) {
|
33
|
+
try {
|
34
|
+
injectPlugin(srcPath, destPath);
|
35
|
+
} catch (err) {
|
36
|
+
console.error(`Error processing directory ${srcPath}:`, err);
|
37
|
+
}
|
38
|
+
} else if (entry.isFile()) {
|
24
39
|
const ext = path.extname(entry.name);
|
25
40
|
/** only copy .js and .css files */
|
26
|
-
if (ext === ".js" || ext === ".css")
|
41
|
+
if (ext === ".js" || ext === ".css") {
|
42
|
+
try {
|
43
|
+
fs.copyFileSync(srcPath, destPath);
|
44
|
+
} catch (err) {
|
45
|
+
console.error(`Failed to copy file from ${srcPath} to ${destPath}:`, err);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
function transformImportPaths(filePath: string): void {
|
53
|
+
try {
|
54
|
+
let code = fs.readFileSync(filePath, "utf8");
|
55
|
+
code = code.replace(
|
56
|
+
/(import\s+.*?\s+from\s+["'])(\.\/[^"']+)(["'])/g,
|
57
|
+
(match, prefix, importPath, suffix) => {
|
58
|
+
const absolutePath = path.resolve(path.dirname(filePath), importPath);
|
59
|
+
if (fs.existsSync(absolutePath + ".js")) {
|
60
|
+
return `${prefix}${importPath}.js${suffix}`;
|
61
|
+
} else if (fs.existsSync(path.join(absolutePath, "index.js"))) {
|
62
|
+
return `${prefix}${importPath}/index.js${suffix}`;
|
63
|
+
}
|
64
|
+
return match;
|
65
|
+
}
|
66
|
+
);
|
67
|
+
fs.writeFileSync(filePath, code, "utf8");
|
68
|
+
} catch (err) {
|
69
|
+
console.error(`Error processing file ${filePath}:`, err);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
function processDirectoryForTransform(dir: string): void {
|
74
|
+
let entries;
|
75
|
+
try {
|
76
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
77
|
+
} catch (err) {
|
78
|
+
console.error(`Failed to read directory ${dir}:`, err);
|
79
|
+
return;
|
80
|
+
}
|
81
|
+
for (const entry of entries) {
|
82
|
+
const fullPath = path.join(dir, entry.name);
|
83
|
+
if (entry.isDirectory()) {
|
84
|
+
processDirectoryForTransform(fullPath);
|
85
|
+
} else if (entry.isFile() && path.extname(entry.name) === ".js") {
|
86
|
+
transformImportPaths(fullPath);
|
27
87
|
}
|
28
88
|
}
|
29
89
|
}
|
30
90
|
|
31
|
-
|
91
|
+
try {
|
92
|
+
injectPlugin(sourceDir, destDir);
|
93
|
+
console.log(`Plugin files copied from ${sourceDir} to ${destDir}`);
|
94
|
+
} catch (err) {
|
95
|
+
console.error("Error during plugin injection:", err);
|
96
|
+
}
|
32
97
|
|
33
|
-
|
98
|
+
try {
|
99
|
+
processDirectoryForTransform(destDir);
|
100
|
+
console.log("Import paths in JS files have been transformed to include explicit file extensions.");
|
101
|
+
} catch (err) {
|
102
|
+
console.error("Error during import path transformation:", err);
|
103
|
+
}
|