Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const Program = require('commander');

// Joomla Build modules
const buildCheck = require('./build/build-modules-js/build-check');
const installer = require('./build/build-modules-js/installation');
const copyAssets = require('./build/build-modules-js/update');
const compileCSS = require('./build/build-modules-js/compilescss');
const compileJS = require('./build/build-modules-js/compilejs');
Expand All @@ -45,8 +44,7 @@ Program
.option('--compile-css, --compile-css path', 'Compiles all the scss files to css')
.option('--compile-ce, --compile-ce path', 'Compiles/traspiles all the custom elements files')
.option('--watch, --watch path', 'Watch file changes and re-compile (Only work for compile-css and compile-js now).')
.option('--installer', 'Creates the language file for installer error page')
.option('--buildcheck', 'Creates the language file for build check error page')
.option('--build-check', 'Creates the error pages for unsupported PHP version & incomplete environment')
.on('--help', () => {
// eslint-disable-next-line no-console
console.log(`Version: ${options.version}`);
Expand Down Expand Up @@ -78,14 +76,10 @@ if (Program.copyAssets) {
});
}

// Create the languages file for the error page on the installer
if (Program.installer) {
installer.installation();
}

// Create the languages file for the error page on incomplete repo build
if (Program.buildcheck) {
buildCheck.buildCheck();
// Creates the error pages for unsupported PHP version & incomplete environment
if (Program.buildCheck) {
buildCheck.buildCheck(options);
}

// Convert scss to css
Expand Down
88 changes: 57 additions & 31 deletions build/build-modules-js/build-check.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/**
* Will produce 2 .html files
* Expects three files:
* build/warning_page/template.css
* build/warning_page/template.html
* build/warning_page/template.js
*
* And also specific strings in the languages in the installation folder!
* Also the base strings are held in build/build-modules-js/settings.json
*/
const fs = require('fs');
const ini = require('ini');
const Recurs = require('recursive-readdir');
Expand All @@ -6,16 +16,16 @@ const uglifyJs = require('uglify-es');
const rootPath = require('./rootpath.js')._();

const dir = `${rootPath}/installation/language`;
const installationFile = `${rootPath}/templates/system/build_incomplete.html`;
const srcPath = `${rootPath}/build/repo_build_incomplete`;
const srcPath = `${rootPath}/build/warning_page`;

// Set the initial template
let template = 'window.errorLocale = {';
let incomplete = 'window.errorLocale = {';
let unsupported = 'window.errorLocale = {';

const buildCheck = () => {
let checkContent = fs.readFileSync(`${srcPath}/incomplete.html`, 'utf-8');
let cssContent = fs.readFileSync(`${srcPath}/incomplete.css`, 'utf-8');
let jsContent = fs.readFileSync(`${srcPath}/incomplete.js`, 'utf-8');
const buildCheck = (options) => {
let initTemplate = fs.readFileSync(`${srcPath}/template.html`, 'utf-8');
let cssContent = fs.readFileSync(`${srcPath}/template.css`, 'utf-8');
let jsContent = fs.readFileSync(`${srcPath}/template.js`, 'utf-8');

cssContent = uglifyCss.processString(cssContent, { expandVars: false });
jsContent = uglifyJs.minify(jsContent);
Expand All @@ -24,40 +34,56 @@ const buildCheck = () => {
(files) => {
files.forEach((file) => {
const languageStrings = ini.parse(fs.readFileSync(file, 'UTF-8'));

// Build the variables into json for the unsupported page
if (languageStrings.MIN_PHP_ERROR_LANGUAGE) {
const name = file.replace('.ini', '').replace(/.+\//, '');
unsupported += `"${name}":{"language":"${languageStrings.MIN_PHP_ERROR_LANGUAGE}","header":"${languageStrings.MIN_PHP_ERROR_HEADER}","text1":"${languageStrings.MIN_PHP_ERROR_TEXT}","help-url-text":"${languageStrings.MIN_PHP_ERROR_URL_TEXT}"},`;
}

// Build the variables into json for the unsupported page
if (languageStrings.BUILD_INCOMPLETE_LANGUAGE) {
const name = file.replace('.ini', '').replace(/.+\//, '');
template += `
"${name}":{"language":"${languageStrings.BUILD_INCOMPLETE_LANGUAGE}","header":"${languageStrings.BUILD_INCOMPLETE_HEADER}","text1":"${languageStrings.BUILD_INCOMPLETE_TEXT}","help-url-text":"${languageStrings.BUILD_INCOMPLETE_URL_TEXT}"},`;
incomplete += `"${name}":{"language":"${languageStrings.BUILD_INCOMPLETE_LANGUAGE}","header":"${languageStrings.BUILD_INCOMPLETE_HEADER}","text1":"${languageStrings.BUILD_INCOMPLETE_TEXT}","help-url-text":"${languageStrings.BUILD_INCOMPLETE_URL_TEXT}"},`;
}
});

template = `${template}
}`;
unsupported = `${unsupported}}`;
incomplete = `${incomplete}}`;

checkContent = checkContent.replace('{{jsonContents}}', template);
for (const name in options.settings.errorPages) {
checkContent = initTemplate;
checkContent = checkContent.replace('{{jsonContents}}', name === 'incomplete' ? incomplete : unsupported);
checkContent = checkContent.replace('{{PHP_VERSION}}', '');
checkContent = checkContent.replace('{{Title}}', options.settings.errorPages[name].title);
checkContent = checkContent.replace('{{Header}}', options.settings.errorPages[name].header);
checkContent = checkContent.replace('{{Description}}', options.settings.errorPages[name].text);
checkContent = checkContent.replace('{{Link}}', options.settings.errorPages[name].link);
checkContent = checkContent.replace('{{LinkText}}', options.settings.errorPages[name].linkText);

if (cssContent) {
checkContent = checkContent.replace('{{cssContents}}', cssContent);
}
if (cssContent) {
checkContent = checkContent.replace('{{cssContents}}', cssContent);
}

if (jsContent) {
checkContent = checkContent.replace('{{jsContents}}', jsContent.code);
}
if (jsContent) {
checkContent = checkContent.replace('{{jsContents}}', jsContent.code);
}

fs.writeFile(
installationFile,
checkContent,
(err) => {
if (err) {
// eslint-disable-next-line no-console
console.log(err);
return;
}
fs.writeFile(
`${rootPath}${options.settings.errorPages[name].destFile}`,
checkContent,
(err) => {
if (err) {
// eslint-disable-next-line no-console
console.log(err);
return;
}

// eslint-disable-next-line no-console
console.log('The build check error page was saved!');
},
);
// eslint-disable-next-line no-console
console.log(`The ${options.settings.errorPages[name].destFile} page was created successfully!`);
},
);
}
},
(error) => {
// eslint-disable-next-line no-console
Expand Down
69 changes: 0 additions & 69 deletions build/build-modules-js/installation.js

This file was deleted.

22 changes: 21 additions & 1 deletion build/build-modules-js/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,26 @@
"dependencies": [],
"licenseFilename": "LICENSE.md"
}
},
"errorPages": {
"incomplete": {
"phpVersionReplaceble": "",
"title": "Joomla: Environment Setup Incomplete",
"header": "Environment Setup Incomplete",
"text": "It looks like you are trying to run Joomla! from our git repository. To do so requires you complete a couple of extra steps first.",
"link": "J4.x:Setting_Up_Your_Local_Environment",
"linkText": "More Details",
"destFile": "/templates/system/build_incomplete.html"
},
"unsupported": {
"phpVersionReplaceble": "data-php-version=\"{{PHP_VERSION}}\"",
"title": "Joomla: unsupported PHP version",
"header": "Sorry, your PHP version is not supported",
"text": "Your host needs to use PHP version {{PHP_VERSION}} or newer to run this version of Joomla!",
"link": "Unsupported_PHP_Version",
"linkText": "Help me resolve this",
"destFile": "/templates/system/incompatible.html"
}
}
}
}
}
Loading