-
Notifications
You must be signed in to change notification settings - Fork 37
/
gulpfile.js
85 lines (74 loc) · 3.57 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
const gulp = require('gulp');
const { watch, series, parallel } = require('gulp');
const browser = require('browser-sync');
const clean = require('gulp-clean');
const fs = require('fs');
// Get dependencies tasks
const createScssFile = require('./gulp/Tasks/CreateScssFile');
const cssTranspile = require('./gulp/Tasks/ScssTanspile');
const project = require('./gulp/ProjectSpecs/DefaultSpecs');
const tsTranspile = require('./gulp/Tasks/TsTanspile');
const updatetVersion = require('./gulp/Tasks/UpdateVersion');
const ptdNpm = require('./gulp/Tasks/PrepareToDeployNpm');
const gitIgnoreUpdate = require('./gulp/Tasks/GitIgnoreUpdate');
// Local configs
const distFolder = './dist';
const serverPort = 3000;
const watchScssFiles = 'src/**/*.scss';
const watchTsFiles = 'src/**/*.ts';
// Clean Dist Folder
function cleanOldFiles() {
return gulp.src(distFolder + "/*", {read: false}).pipe(clean());
}
// Starts a Browser instance
function initServer() {
updateIndexTemplateFile();
setTimeout(() => {
browser.init({server: distFolder, port: serverPort, cors: true});
}, 0);
}
// Method to update development template code
function updateIndexTemplateFile() {
// Get the index.html base file
let code = fs.readFileSync('./gulp/Template/index.html', 'utf8');
let jsLinks = '';
let scssLinks = '';
if(process.env.npm_config_target !== undefined && project.globalConsts.platformTarget[process.env.npm_config_target] !== undefined) {
code = code.replace(" • --platform--", " • " + project.globalConsts.platformTarget[process.env.npm_config_target]);
jsLinks = `<li><p><a target="blank" href="./dev.${project.globalConsts.platformTarget[process.env.npm_config_target]}.OutSystemsUI.js">${project.globalConsts.platformTarget[process.env.npm_config_target]}.OutSystemsUI.js</a></p></li>`;
scssLinks = `<li><p><a target="blank" href="./dev.${project.globalConsts.platformTarget[process.env.npm_config_target]}.OutSystemsUI.css">${project.globalConsts.platformTarget[process.env.npm_config_target]}.OutSystemsUI.css</a></p></li>`;
} else {
code = code.replace(" • --platform--", "");
const pts = project.globalConsts.platformTarget;
for(const pt in pts) {
jsLinks += `<li><p><a target="blank" href="./dev.${pts[pt]}.OutSystemsUI.js">${pts[pt]}.OutSystemsUI.js</a></p></li>\n`;
scssLinks += `<li><p><a target="blank" href="./dev.${pts[pt]}.OutSystemsUI.css">${pts[pt]}.OutSystemsUI.css</a></p></li>\n`;
}
}
code = code.replace("<li>jsListItemToBeReplaced</li>", jsLinks);
code = code.replace("<li>scssListItemToBeReplaced</li>", scssLinks);
// Create the new index.html at the dist folder!
fs.writeFileSync(`${distFolder}/index.html`, code, 'utf8');
}
// Watch files changed
function watchFiles() {
watch(watchScssFiles, series(cssTranspile.transpileDev));
watch(watchTsFiles, series(tsTranspile.transpileDev));
};
// Gulp tasks
exports.startDevelopment = series(
cleanOldFiles,
createScssFile.update_osui_scss_file_dev,
parallel(cssTranspile.transpileDev, tsTranspile.transpileDev),
parallel(watchFiles, initServer)
);
exports.createProduction = series(
cleanOldFiles,
createScssFile.update_osui_scss_file_prod,
parallel(cssTranspile.transpileProd, tsTranspile.transpileProd),
);
exports.updateScssFile = createScssFile.update_osui_scss_file_dev;
exports.updateVersion = updatetVersion.setVersion;
exports.gtaSetVersion = updatetVersion.gtaSetVersion;
exports.prepareToDeploy = ptdNpm.prepareToDeployNpm;
exports.removeDistFromGitIgnore = gitIgnoreUpdate.removeDist;