Skip to content

Commit e8d546e

Browse files
authored
Merge pull request DSpace#4739 from alanorth/node-prefix-imports
Adjust imports in scripts and webpack directories
2 parents a52ba24 + f991052 commit e8d546e

12 files changed

Lines changed: 242 additions & 191 deletions

angular.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,9 @@
271271
"cypress/**/*.ts",
272272
"lint/**/*.ts",
273273
"src/**/*.html",
274-
"src/**/*.json5"
274+
"src/**/*.json5",
275+
"scripts/**/*.ts",
276+
"webpack/**/*.ts"
275277
]
276278
}
277279
}

scripts/base-href.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ try {
3030

3131
const baseHref = `${appConfig.ui.nameSpace}${appConfig.ui.nameSpace.endsWith('/') ? '' : '/'}`;
3232

33-
console.log(`Setting baseHref to ${baseHref} in angular.json`);
33+
console.info(`Setting baseHref to ${baseHref} in angular.json`);
3434

3535
angularJson.projects['dspace-angular'].architect.build.options.baseHref = baseHref;
3636

scripts/env-to-yaml.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
import { existsSync, writeFileSync } from 'fs';
1+
import {
2+
existsSync,
3+
writeFileSync,
4+
} from 'node:fs';
5+
import { join } from 'node:path';
6+
27
import { dump } from 'js-yaml';
3-
import { join } from 'path';
48

59
/**
610
* Script to help convert previous version environment.*.ts to yaml.
711
*
812
* Usage (see package.json):
9-
*
13+
*
1014
* yarn env:yaml [relative path to environment.ts file] (optional relative path to write yaml file) *
1115
*/
1216

1317
const args = process.argv.slice(2);
1418
if (args[0] === undefined) {
15-
console.log(`Usage:\n\tyarn env:yaml [relative path to environment.ts file] (optional relative path to write yaml file)\n`);
19+
console.info(`Usage:\n\tyarn env:yaml [relative path to environment.ts file] (optional relative path to write yaml file)\n`);
1620
process.exit(0);
1721
}
1822

@@ -24,14 +28,15 @@ if (!existsSync(envFullPath)) {
2428
}
2529

2630
try {
31+
// eslint-disable-next-line @typescript-eslint/no-require-imports
2732
const env = require(envFullPath).environment;
2833

2934
const config = dump(env);
3035
if (args[1]) {
3136
const ymlFullPath = join(process.cwd(), args[1]);
3237
writeFileSync(ymlFullPath, config);
3338
} else {
34-
console.log(config);
39+
console.info(config);
3540
}
3641
} catch (e) {
3742
console.error(e);

scripts/merge-i18n-files.ts

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1-
import { projectRoot} from '../webpack/helpers';
2-
const commander = require('commander');
3-
const fs = require('fs');
4-
const JSON5 = require('json5');
5-
const _cliProgress = require('cli-progress');
6-
const _ = require('lodash');
1+
import {
2+
existsSync,
3+
lstatSync,
4+
readdirSync,
5+
readFileSync,
6+
writeFileSync,
7+
} from 'node:fs';
78

8-
const program = new commander.Command();
9+
import {
10+
Presets,
11+
SingleBar,
12+
} from 'cli-progress';
13+
import { Command } from 'commander';
14+
import {
15+
parse,
16+
stringify,
17+
} from 'json5';
18+
19+
import { projectRoot } from '../webpack/helpers';
20+
21+
const program = new Command();
922
program.version('1.0.0', '-v, --version');
1023

1124
const LANGUAGE_FILES_LOCATION = 'src/assets/i18n';
@@ -46,26 +59,26 @@ function parseCliInput() {
4659
const destination = program.opts().outputDir;
4760

4861
if (destination && source) {
49-
if (!fs.existsSync(destination) || !fs.lstatSync(destination).isDirectory() ) {
62+
if (!existsSync(destination) || !lstatSync(destination).isDirectory() ) {
5063
console.error('Output does not exist or is not a directory.');
51-
console.log(program.outputHelp());
64+
console.info(program.outputHelp());
5265
process.exit(1);
5366
}
54-
if (!fs.existsSync(source) || !fs.lstatSync(source).isDirectory() ) {
67+
if (!existsSync(source) || !lstatSync(source).isDirectory() ) {
5568
console.error('Source does not exist or is not a directory.');
56-
console.log(program.outputHelp());
69+
console.info(program.outputHelp());
5770
process.exit(1);
5871
}
5972

60-
fs.readdirSync(projectRoot(source)).forEach(file => {
61-
if (fs.existsSync(destination + '/' + file) ) {
62-
console.log('Merging: ' + destination + '/' + file + ' with ' + source + '/' + file);
73+
readdirSync(projectRoot(source)).forEach(file => {
74+
if (existsSync(destination + '/' + file) ) {
75+
console.info('Merging: ' + destination + '/' + file + ' with ' + source + '/' + file);
6376
mergeFileWithSource(source + '/' + file, destination + '/' + file);
6477
}
6578
});
6679
} else {
6780
console.error('Source or Output parameter is missing.');
68-
console.log(program.outputHelp());
81+
console.info(program.outputHelp());
6982
process.exit(1);
7083
}
7184
}
@@ -79,24 +92,24 @@ function parseCliInput() {
7992
* @param pathToOutputFile Valid path to merge and write output
8093
*/
8194
function mergeFileWithSource(pathToSourceFile, pathToOutputFile) {
82-
const progressBar = new _cliProgress.SingleBar({}, _cliProgress.Presets.shades_classic);
95+
const progressBar = new SingleBar({}, Presets.shades_classic);
8396
progressBar.start(100, 0);
8497

85-
const sourceFile = fs.readFileSync(pathToSourceFile, 'utf8');
98+
const sourceFile = readFileSync(pathToSourceFile, 'utf8');
8699
progressBar.update(10);
87-
const outputFile = fs.readFileSync(pathToOutputFile, 'utf8');
100+
const outputFile = readFileSync(pathToOutputFile, 'utf8');
88101
progressBar.update(20);
89102

90-
const parsedSource = JSON5.parse(sourceFile);
103+
const parsedSource = parse(sourceFile);
91104
progressBar.update(30);
92-
const parsedOutput = JSON5.parse(outputFile);
105+
const parsedOutput = parse(outputFile);
93106
progressBar.update(40);
94107

95108
for (const key of Object.keys(parsedSource)) {
96109
parsedOutput[key] = parsedSource[key];
97110
}
98111
progressBar.update(80);
99-
fs.writeFileSync(pathToOutputFile,JSON5.stringify(parsedOutput,{ space:'\n ', quote: '"' }), { encoding:'utf8' });
112+
writeFileSync(pathToOutputFile,stringify(parsedOutput,{ space:'\n ', quote: '"' }), { encoding:'utf8' });
100113

101114
progressBar.update(100);
102115
progressBar.stop();

scripts/serve.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { spawn } from 'child_process';
1+
import { spawn } from 'node:child_process';
22

33
import { AppConfig } from '../src/config/app-config.interface';
44
import { buildAppConfig } from '../src/config/config.server';
@@ -11,5 +11,5 @@ const appConfig: AppConfig = buildAppConfig();
1111
*/
1212
spawn(
1313
`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`,
14-
{ stdio: 'inherit', shell: true }
14+
{ stdio: 'inherit', shell: true },
1515
);

0 commit comments

Comments
 (0)