@bouygues-telecom/staticjs 0.1.6 → 0.1.7

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bouygues-telecom/staticjs",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -9,11 +9,13 @@
9
9
  ],
10
10
  "bin": {
11
11
  "create-staticjs-app": "./dist/scripts/create-static-app.js",
12
- "bt-staticjs": "./dist/scripts/cli.js"
12
+ "bt-staticjs": "./dist/scripts/cli.js",
13
+ "generate-test-multiapps": "./scripts/generate-test-multiapps.js"
13
14
  },
14
15
  "scripts": {
15
16
  "prebuild": "tsc -p ./tsconfig.json",
16
17
  "build": "cd templates/react && rimraf dist && rimraf cache && node ../../dist/helpers/cachePages.js && vite build --config ../../vite.config.js && tsx ../../dist/scripts/build-html.js",
18
+ "generate:test": "cd templates/react && node ../../scripts/generate-test-multiapps.js",
17
19
  "start": "cd templates/react && npm start"
18
20
  },
19
21
  "dependencies": {
@@ -0,0 +1,62 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+
4
+ const sourceDir = './dist';
5
+
6
+ const htmlFiles = ['page1.html', 'page2.html'];
7
+
8
+ const outputDir = 'test';
9
+ const outputFile = 'test-multi-app.html';
10
+
11
+ const readFile = (filePath) => {
12
+ return new Promise((resolve, reject) => {
13
+ fs.readFile(filePath, 'utf8', (err, data) => {
14
+ if (err) {
15
+ reject(err);
16
+ } else {
17
+ resolve(data);
18
+ }
19
+ });
20
+ });
21
+ };
22
+
23
+ const writeOutputFile = (filePath, content) => {
24
+ return new Promise((resolve, reject) => {
25
+ fs.writeFile(filePath, content, 'utf8', (err) => {
26
+ if (err) {
27
+ reject(err);
28
+ } else {
29
+ resolve();
30
+ }
31
+ });
32
+ });
33
+ };
34
+
35
+ const createDir = (dirPath) => {
36
+ if (!fs.existsSync(dirPath)) {
37
+ fs.mkdirSync(dirPath, { recursive: true });
38
+ }
39
+ };
40
+
41
+ const generateHtmlFile = async () => {
42
+ try {
43
+ createDir(outputDir);
44
+
45
+ const htmlContents = await Promise.all(
46
+ htmlFiles.map(file => readFile(path.join(sourceDir, file)))
47
+ );
48
+
49
+ let combinedContent = htmlContents.join("\n<!-- Page Separator -->\n");
50
+
51
+ combinedContent = combinedContent.replace(/src="page1.js"/g, 'src="../dist/page1.js"');
52
+ combinedContent = combinedContent.replace(/src="page2.js"/g, 'src="../dist/page2.js"');
53
+
54
+ await writeOutputFile(path.join(outputDir, outputFile), combinedContent);
55
+
56
+ console.log(`Le fichier ${outputFile} a été créé avec succès dans le dossier ${outputDir}.`);
57
+ } catch (error) {
58
+ console.error(`Une erreur est survenue: ${error.message}`);
59
+ }
60
+ };
61
+
62
+ generateHtmlFile();