Skip to content
Open
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
4 changes: 3 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@
"cypress/**/*.ts",
"lint/**/*.ts",
"src/**/*.html",
"src/**/*.json5"
"src/**/*.json5",
"scripts/*.ts",
"webpack/*.ts"
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = function (config) {
}
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, './coverage/dspace-angular'),
dir: require('node:path').join(__dirname, './coverage/dspace-angular'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
Expand Down
11 changes: 7 additions & 4 deletions scripts/base-href.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { existsSync, writeFileSync } from 'fs';
import { join } from 'path';
import {
existsSync,
writeFileSync,
} from 'node:fs';
import { join } from 'node:path';

import { AppConfig } from '../src/config/app-config.interface';
import { buildAppConfig } from '../src/config/config.server';

/**
* Script to set baseHref as `ui.nameSpace` for development mode. Adds `baseHref` to angular.json build options.
*
*
* Usage (see package.json):
*
*
* yarn base-href
*/

Expand Down
10 changes: 7 additions & 3 deletions scripts/env-to-yaml.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { existsSync, writeFileSync } from 'fs';
import {
existsSync,
writeFileSync,
} from 'node:fs';
import { join } from 'node:path';

import { dump } from 'js-yaml';
import { join } from 'path';

/**
* Script to help convert previous version environment.*.ts to yaml.
*
* Usage (see package.json):
*
*
* yarn env:yaml [relative path to environment.ts file] (optional relative path to write yaml file) *
*/

Expand Down
6 changes: 3 additions & 3 deletions scripts/merge-i18n-files.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { projectRoot} from '../webpack/helpers';
import { projectRoot } from '../webpack/helpers';

const commander = require('commander');
const fs = require('fs');
const fs = require('node:fs');
const JSON5 = require('json5');
const _cliProgress = require('cli-progress');
const _ = require('lodash');

const program = new commander.Command();
program.version('1.0.0', '-v, --version');
Expand Down
4 changes: 2 additions & 2 deletions scripts/serve.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { spawn } from 'child_process';
import { spawn } from 'node:child_process';

import { AppConfig } from '../src/config/app-config.interface';
import { buildAppConfig } from '../src/config/config.server';
Expand All @@ -11,5 +11,5 @@ const appConfig: AppConfig = buildAppConfig();
*/
spawn(
`ng serve --host ${appConfig.ui.host} --port ${appConfig.ui.port} --serve-path ${appConfig.ui.nameSpace} --ssl ${appConfig.ui.ssl} ${process.argv.slice(2).join(' ')} --configuration development`,
{ stdio: 'inherit', shell: true }
{ stdio: 'inherit', shell: true },
);
74 changes: 38 additions & 36 deletions scripts/sync-i18n-files.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import isEmpty from 'lodash/isEmpty';
import isEqual from 'lodash/isEqual';

import { projectRoot } from '../webpack/helpers';

const commander = require('commander');
const fs = require('fs');
const fs = require('node:fs');
const JSON5 = require('json5');
const _cliProgress = require('cli-progress');
const _ = require('lodash');

const program = new commander.Command();
program.version('1.0.0', '-v, --version');
Expand Down Expand Up @@ -41,13 +43,13 @@ function parseCliInput() {
if (!program.targetFile) {
fs.readdirSync(projectRoot(LANGUAGE_FILES_LOCATION)).forEach(file => {
if (!program.sourceFile.toString().endsWith(file)) {
const targetFileLocation = projectRoot(LANGUAGE_FILES_LOCATION + "/" + file);
const targetFileLocation = projectRoot(LANGUAGE_FILES_LOCATION + '/' + file);
console.log('Syncing file at: ' + targetFileLocation + ' with source file at: ' + program.sourceFile);
if (program.outputDir) {
if (!fs.existsSync(program.outputDir)) {
fs.mkdirSync(program.outputDir);
}
const outputFileLocation = program.outputDir + "/" + file;
const outputFileLocation = program.outputDir + '/' + file;
console.log('Output location: ' + outputFileLocation);
syncFileWithSource(targetFileLocation, outputFileLocation);
} else {
Expand Down Expand Up @@ -97,12 +99,12 @@ function syncFileWithSource(pathToTargetFile, pathToOutputFile) {
const sourceLines = [];
const targetLines = [];
const existingTargetFile = readFileIfExists(pathToTargetFile);
existingTargetFile.toString().split("\n").forEach((function (line) {
existingTargetFile.toString().split('\n').forEach((function (line) {
targetLines.push(line.trim());
}));
progressBar.update(10);
const sourceFile = readFileIfExists(program.sourceFile);
sourceFile.toString().split("\n").forEach((function (line) {
sourceFile.toString().split('\n').forEach((function (line) {
sourceLines.push(line.trim());
}));
progressBar.update(20);
Expand All @@ -113,22 +115,22 @@ function syncFileWithSource(pathToTargetFile, pathToOutputFile) {

const file = fs.createWriteStream(pathToOutputFile);
file.on('error', function (err) {
console.error('Something went wrong writing to output file at: ' + pathToOutputFile + err)
console.error('Something went wrong writing to output file at: ' + pathToOutputFile + err);
});
file.on('open', function() {
file.write("{\n");
file.write('{\n');
outputChunks.forEach(function (chunk) {
progressBar.increment();
chunk.split("\n").forEach(function (line) {
file.write((line === '' ? '' : ` ${line}`) + "\n");
chunk.split('\n').forEach(function (line) {
file.write((line === '' ? '' : ` ${line}`) + '\n');
});
});
file.write("\n}");
file.write('\n}');
file.end();
});
file.on('finish', function() {
const osName = process.platform;
if (osName.startsWith("win")) {
if (osName.startsWith('win')) {
replaceLineEndingsToCRLF(pathToOutputFile);
}
});
Expand All @@ -151,10 +153,10 @@ function compareChunksAndCreateOutput(sourceChunks, targetChunks, progressBar) {
sourceChunks.map((sourceChunk) => {
progressBar.increment();
if (sourceChunk.trim().length !== 0) {
let newChunk = [];
const sourceList = sourceChunk.split("\n");
const newChunk = [];
const sourceList = sourceChunk.split('\n');
const keyValueSource = sourceList[sourceList.length - 1];
const keySource = getSubStringBeforeLastString(keyValueSource, ":");
const keySource = getSubStringBeforeLastString(keyValueSource, ':');
const commentSource = getSubStringBeforeLastString(sourceChunk, keyValueSource);

const correspondingTargetChunk = targetChunks.find((targetChunk) => {
Expand All @@ -163,15 +165,15 @@ function compareChunksAndCreateOutput(sourceChunks, targetChunks, progressBar) {

// Create new chunk with: the source comments, the commented source key-value, the todos and either the old target key-value pair or if it's a new pair, the source key-value pair
newChunk.push(removeWhiteLines(commentSource));
newChunk.push("// " + keyValueSource);
newChunk.push('// ' + keyValueSource);
if (correspondingTargetChunk === undefined) {
newChunk.push(NEW_MESSAGE_TODO);
newChunk.push(keyValueSource);
} else {
createNewChunkComparingSourceAndTarget(correspondingTargetChunk, sourceChunk, commentSource, keyValueSource, newChunk);
}

outputChunks.push(newChunk.filter(Boolean).join("\n"));
outputChunks.push(newChunk.filter(Boolean).join('\n'));
} else {
outputChunks.push(sourceChunk);
}
Expand All @@ -191,23 +193,23 @@ function createNewChunkComparingSourceAndTarget(correspondingTargetChunk, source
let commentsOfSourceHaveChanged = false;
let messageOfSourceHasChanged = false;

const targetList = correspondingTargetChunk.split("\n");
const oldKeyValueInTargetComments = getSubStringWithRegex(correspondingTargetChunk, "\\s*\\/\\/\\s*\".*");
const targetList = correspondingTargetChunk.split('\n');
const oldKeyValueInTargetComments = getSubStringWithRegex(correspondingTargetChunk, '\\s*\\/\\/\\s*".*');
let keyValueTarget = targetList[targetList.length - 1];
if (!keyValueTarget.endsWith(",")) {
keyValueTarget = keyValueTarget + ",";
if (!keyValueTarget.endsWith(',')) {
keyValueTarget = keyValueTarget + ',';
}

if (oldKeyValueInTargetComments != null) {
const oldKeyValueUncommented = getSubStringWithRegex(oldKeyValueInTargetComments[0], "\".*")[0];
const oldKeyValueUncommented = getSubStringWithRegex(oldKeyValueInTargetComments[0], '".*')[0];

if (!(_.isEmpty(correspondingTargetChunk) && _.isEmpty(commentSource)) && !removeWhiteLines(correspondingTargetChunk).includes(removeWhiteLines(commentSource.trim()))) {
if (!(isEmpty(correspondingTargetChunk) && isEmpty(commentSource)) && !removeWhiteLines(correspondingTargetChunk).includes(removeWhiteLines(commentSource.trim()))) {
commentsOfSourceHaveChanged = true;
newChunk.push(COMMENTS_CHANGED_TODO);
}
const parsedOldKey = JSON5.stringify("{" + oldKeyValueUncommented + "}");
const parsedSourceKey = JSON5.stringify("{" + keyValueSource + "}");
if (!_.isEqual(parsedOldKey, parsedSourceKey)) {
const parsedOldKey = JSON5.stringify('{' + oldKeyValueUncommented + '}');
const parsedSourceKey = JSON5.stringify('{' + keyValueSource + '}');
if (!isEqual(parsedOldKey, parsedSourceKey)) {
messageOfSourceHasChanged = true;
newChunk.push(MESSAGE_CHANGED_TODO);
}
Expand All @@ -219,7 +221,7 @@ function createNewChunkComparingSourceAndTarget(correspondingTargetChunk, source
// Adds old todos found in target comments if they've not been added already
function addOldTodosIfNeeded(targetList, newChunk, commentsOfSourceHaveChanged, messageOfSourceHasChanged) {
targetList.map((targetLine) => {
const foundTODO = getSubStringWithRegex(targetLine, "\\s*//\\s*TODO.*");
const foundTODO = getSubStringWithRegex(targetLine, '\\s*//\\s*TODO.*');
if (foundTODO != null) {
const todo = foundTODO[0];
if (!((todo.includes(COMMENTS_CHANGED_TODO) && commentsOfSourceHaveChanged)
Expand Down Expand Up @@ -262,7 +264,7 @@ function createChunks(lines, progressBar, creatingTarget) {
nextChunk.push(line);
const newMessageLineIfExists = nextChunk.find((lineInChunk) => lineInChunk.trim().startsWith(NEW_MESSAGE_TODO));
if (newMessageLineIfExists === undefined || !creatingTarget) {
chunks.push(nextChunk.join("\n"));
chunks.push(nextChunk.join('\n'));
}
nextChunk = [];
}
Expand All @@ -284,19 +286,19 @@ function readFileIfExists(pathToFile) {
}

function isOneLineCommentLine(line) {
return (line.startsWith("//"));
return (line.startsWith('//'));
}

function isStartOfMultiLineComment(line) {
return (line.startsWith("/*"));
return (line.startsWith('/*'));
}

function isEndOfMultiLineComment(line) {
return (line.endsWith("*/"));
return (line.endsWith('*/'));
}

function isKeyValuePair(line) {
return (line.startsWith("\""));
return (line.startsWith('"'));
}


Expand All @@ -318,7 +320,7 @@ function getOutputFileLocationIfExistsElseTargetFileLocation(targetLocation) {
}

function checkIfPathToFileIsValid(pathToCheck) {
if (!pathToCheck.includes("/")) {
if (!pathToCheck.includes('/')) {
return true;
}
return checkIfFileExists(getPathOfDirectory(pathToCheck));
Expand All @@ -329,11 +331,11 @@ function checkIfFileExists(pathToCheck) {
}

function getPathOfDirectory(pathToCheck) {
return getSubStringBeforeLastString(pathToCheck, "/");
return getSubStringBeforeLastString(pathToCheck, '/');
}

function removeWhiteLines(string) {
return string.replace(/^(?=\n)$|^\s*|\s*$|\n\n+/gm, "")
return string.replace(/^(?=\n)$|^\s*|\s*$|\n\n+/gm, '');
}

/**
Expand All @@ -342,6 +344,6 @@ function removeWhiteLines(string) {
*/
function replaceLineEndingsToCRLF(filePath) {
const data = readFileIfExists(filePath);
const result = data.replace(/\n/g,"\r\n");
const result = data.replace(/\n/g,'\r\n');
fs.writeFileSync(filePath, result, 'utf8');
}
Loading