-
Notifications
You must be signed in to change notification settings - Fork 36
/
gulpfile.js
86 lines (70 loc) · 3.04 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const rename = require('gulp-rename');
const gulp = require('gulp');
const removeFiles = require('gulp-remove-files');
const fs = require('fs').promises;
const merge = require('merge-stream');
const { modules, scripts } = require('./src/FusionChartsModule.js');
const { replacePathsWithContents } = require('./gulpUtil.js');
const filePath = './src/modules/fusioncharts/';
const inputFilePath = './src/modules/index.html';
const outputFilePath = './src/modules/layout.js';
const jsOutputFilePath = './src/modules/scripts.js';
const modulesOutputFilePath = './src/modules/modules.js';
// Task for renaming and removing files
gulp.task('rename', function () {
const renameModuleStream = gulp.src(filePath + '*.js')
.pipe(rename(function (path) {
path.extname = '.fcscript';
}))
.pipe(gulp.dest(filePath));
// remove duplicates
gulp.src(filePath + '*.js')
.pipe(removeFiles());
// rename modules in maps folder
gulp.src(filePath + 'maps/es/*.js')
.pipe(rename(function (path) {
path.extname = '.fcscript';
}))
.pipe(gulp.dest(filePath + 'maps/es/'));
// remove duplicates in maps folder
gulp.src(filePath + 'maps/es/*.js')
.pipe(removeFiles());
// rename modules in themes folder
gulp.src(filePath + 'themes/*.js')
.pipe(rename(function (path) {
path.extname = '.fcscript';
}))
.pipe(gulp.dest(filePath + 'themes/'));
// remove duplicates in theme folder
gulp.src(filePath + 'themes/*.js')
.pipe(removeFiles());
return renameModuleStream
});
// Default task
gulp.task('default', gulp.series('rename', async function (done) {
try {
// Read the content of index.html
const data = await fs.readFile(inputFilePath, 'utf8');
// Escape backticks and dollar signs to prevent issues in the template string
const escapedContent = data.replace(/`/g, '\\`').replace(/\$/g, '\\$');
// Prepare the JavaScript content
const outputContent = `export default \`${escapedContent}\`;`;
// Write the content to layout.js
await fs.writeFile(outputFilePath, outputContent);
console.log('layout.js created successfully!');
// Read Scripts and Modules and create a single output.js file
await replacePathsWithContents(scripts);
const jsOutputContent = `export default ${JSON.stringify(scripts)};`;
await fs.writeFile(jsOutputFilePath, jsOutputContent);
console.log('scripts.js created successfully!');
// Process modules
await replacePathsWithContents(modules);
const modulesOutputContent = `export default ${JSON.stringify(modules)};`;
await fs.writeFile(modulesOutputFilePath, modulesOutputContent);
console.log('modules.js created successfully!');
} catch (err) {
console.error('Error:', err);
} finally {
done(); // Ensure done is called even if an error occurs
}
}));