multilang 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,10 +2,11 @@
2
2
 
3
3
  "use strict";
4
4
 
5
- var program = require('commander');
5
+ var program = require('commander').program;
6
6
  var multilang = require('./multilang');
7
- var fs = require('fs-promise');
7
+ var fs = require('fs/promises');
8
8
  var path = require('path');
9
+ var os = require('os');
9
10
 
10
11
  function realPath(inFile) {
11
12
  return Promise.resolve().then(function() {
@@ -28,6 +29,7 @@ function langs(val) {
28
29
  program
29
30
  .version(require('../package').version)
30
31
  .usage('[options] input.md')
32
+ .argument('[input.md]', 'Name of the input file')
31
33
  .option('-i, --input [input.md]', 'Name of the input file')
32
34
  .option('-l, --lang [lang1]', 'Language to generate', langs)
33
35
  .option('-o, --output [name]', 'Name of the output file. Requires --langs!')
@@ -36,9 +38,12 @@ program
36
38
  .option('-s, --silent', 'Do not output anything')
37
39
  .option('--strip-comments', 'Remove HTML comments from output')
38
40
  .option('--no-strip-comments', 'Do not remove HTML comments from output')
41
+ .option('--eol <type>', 'End of line for the output files: LF or CRLF (default: the OS end of line)')
39
42
  .option('-v, --verbose', 'Output all progress informations')
40
43
  .parse(process.argv);
41
44
 
45
+ var options = program.opts();
46
+
42
47
 
43
48
  function isLongOptionSet(ame) {
44
49
  var a=program.rawArgs;
@@ -48,18 +53,30 @@ function isLongOptionSet(ame) {
48
53
  return false;
49
54
  }
50
55
 
51
- if( (""==program.args && !program.input) ){
56
+ if( (""==program.args && !options.input) ){
52
57
  program.help();
53
58
  }
54
59
 
55
60
  var params = {};
56
- params.input = program.input ? program.input : program.args[0];
57
- params.output = program.output;
58
- params.check = program.check;
59
- params.silent = program.silent;
60
- params.langs = program.lang;
61
- params.directory = program.directory;
62
- params.verbose = program.verbose;
61
+ params.input = options.input ? options.input : program.args[0];
62
+ params.output = options.output;
63
+ params.check = options.check;
64
+ params.silent = options.silent;
65
+ params.langs = options.lang;
66
+ params.directory = options.directory;
67
+ params.verbose = options.verbose;
68
+
69
+ var eolByName = {LF:'\n', CRLF:'\r\n'};
70
+ if(options.eol) {
71
+ var eolName = String(options.eol).toUpperCase();
72
+ if(! (eolName in eolByName)) {
73
+ process.stderr.write("ERROR: invalid --eol value '"+options.eol+"', expected LF or CRLF\n");
74
+ program.help();
75
+ }
76
+ params.eol = eolByName[eolName];
77
+ } else {
78
+ params.eol = os.EOL;
79
+ }
63
80
 
64
81
  if(isLongOptionSet('--no-strip-comments')) {
65
82
  params.stripComments = false;
package/bin/multilang.js CHANGED
@@ -4,7 +4,8 @@
4
4
  var multilang={};
5
5
 
6
6
  var yaml = require('js-yaml');
7
- var fs = require('fs-promise');
7
+ var fs = require('fs/promises');
8
+ var fsSync = require('fs');
8
9
  var stripBom = require('strip-bom-string');
9
10
  var Path = require('path');
10
11
  var changing = require('best-globals').changing;
@@ -167,7 +168,7 @@ multilang.parseLang=function parseLang(lang){
167
168
  var langDir = Path.dirname(Path.resolve(module.filename));
168
169
  langDir = langDir.substr(0, langDir.length-4); // erase '/bin'
169
170
  var langFile = Path.normalize(langDir+'/langs/lang-'+lang+'.yaml');
170
- theLang=yaml.load(stripBom(fs.readFileSync(langFile, 'utf8')));
171
+ theLang=yaml.load(stripBom(fsSync.readFileSync(langFile, 'utf8')));
171
172
  }
172
173
  return changing(this.langs[this.defLang], theLang);
173
174
  };
@@ -410,6 +411,10 @@ multilang.stripComments = function stripComments(doc) {
410
411
  return o.join('');
411
412
  };
412
413
 
414
+ multilang.adjustEol=function adjustEol(content, eol){
415
+ return content.replace(/\r?\n/g, eol);
416
+ };
417
+
413
418
  multilang.changeNamedDoc=function changeNamedDoc(documentName, documentText, lang){
414
419
  var content = multilang.changeDoc(documentText, lang);
415
420
  if(multilang.stripCommentsFlag || (documentName === 'README.md' && multilang.stripCommentsFlag !== false)) {
@@ -463,6 +468,9 @@ multilang.main=function main(parameters){
463
468
  chanout.write("Generating '"+oFile.lang+"', writing to '"+oFile.file+"'...\n");
464
469
  }
465
470
  var changedContent=multilang.changeNamedDoc(Path.basename(oFile.file), readContent, oFile.lang);
471
+ if(parameters.eol) {
472
+ changedContent = multilang.adjustEol(changedContent, parameters.eol);
473
+ }
466
474
  return fs.writeFile(oFile.file, changedContent).then(function(){
467
475
  if(parameters.verbose) {
468
476
  chanout.write("Generated '"+oFile.lang+"', file '"+oFile.file+"'.\n");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "multilang",
3
3
  "description": "Tools for multilanguage and Markdown multilang",
4
- "version": "1.2.0",
4
+ "version": "1.2.2",
5
5
  "author": "Codenautas <codenautas@googlegroups.com>",
6
6
  "license": "MIT",
7
7
  "repository": "https://github.com/codenautas/multilang",
@@ -19,26 +19,30 @@
19
19
  "multilang": "./bin/multilang-run.js"
20
20
  },
21
21
  "main": "./bin/multilang.js",
22
+ "overrides": {
23
+ "diff": ">=8.0.2",
24
+ "serialize-javascript": ">=7.0.0",
25
+ "uuid": ">=14.0.0"
26
+ },
22
27
  "dependencies": {
23
- "commander": "9.4.0",
24
- "fs-promise": "~2.0.3",
25
- "js-yaml": "4.1.0",
26
- "strip-bom-string": "~1.0.0",
27
- "best-globals": "~1.0.3"
28
+ "commander": "^15.0.0",
29
+ "js-yaml": "^4.2.0",
30
+ "strip-bom-string": "^1.0.0",
31
+ "best-globals": "^2.2.0"
28
32
  },
29
33
  "devDependencies": {
30
- "expect.js": "~0.3.1",
31
- "istanbul": "~0.4.5",
32
- "mocha": "~10.0.0",
33
- "expect-called": "~0.4.0"
34
+ "expect.js": "^0.3.1",
35
+ "nyc": "^18.0.0",
36
+ "mocha": "^11.7.6",
37
+ "expect-called": "^0.4.0"
34
38
  },
35
39
  "engines": {
36
- "node": ">= 6"
40
+ "node": ">= 22"
37
41
  },
38
42
  "scripts": {
39
43
  "test": "mocha --reporter spec --bail --check-leaks test/",
40
- "test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/",
41
- "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
44
+ "test-ci": "nyc --reporter=lcov mocha --reporter spec --check-leaks test/",
45
+ "test-cov": "nyc mocha --reporter dot --check-leaks test/",
42
46
  "qac": "qa-control . -v",
43
47
  "all": "npm test && npm run test-cov && npm run qac",
44
48
  "start": "node example/server.js"