multilang 1.2.1 → 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.
- package/bin/multilang-run.js +26 -9
- package/bin/multilang.js +7 -0
- package/package.json +5 -5
package/bin/multilang-run.js
CHANGED
|
@@ -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
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 && !
|
|
56
|
+
if( (""==program.args && !options.input) ){
|
|
52
57
|
program.help();
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
var params = {};
|
|
56
|
-
params.input =
|
|
57
|
-
params.output =
|
|
58
|
-
params.check =
|
|
59
|
-
params.silent =
|
|
60
|
-
params.langs =
|
|
61
|
-
params.directory =
|
|
62
|
-
params.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
|
@@ -411,6 +411,10 @@ multilang.stripComments = function stripComments(doc) {
|
|
|
411
411
|
return o.join('');
|
|
412
412
|
};
|
|
413
413
|
|
|
414
|
+
multilang.adjustEol=function adjustEol(content, eol){
|
|
415
|
+
return content.replace(/\r?\n/g, eol);
|
|
416
|
+
};
|
|
417
|
+
|
|
414
418
|
multilang.changeNamedDoc=function changeNamedDoc(documentName, documentText, lang){
|
|
415
419
|
var content = multilang.changeDoc(documentText, lang);
|
|
416
420
|
if(multilang.stripCommentsFlag || (documentName === 'README.md' && multilang.stripCommentsFlag !== false)) {
|
|
@@ -464,6 +468,9 @@ multilang.main=function main(parameters){
|
|
|
464
468
|
chanout.write("Generating '"+oFile.lang+"', writing to '"+oFile.file+"'...\n");
|
|
465
469
|
}
|
|
466
470
|
var changedContent=multilang.changeNamedDoc(Path.basename(oFile.file), readContent, oFile.lang);
|
|
471
|
+
if(parameters.eol) {
|
|
472
|
+
changedContent = multilang.adjustEol(changedContent, parameters.eol);
|
|
473
|
+
}
|
|
467
474
|
return fs.writeFile(oFile.file, changedContent).then(function(){
|
|
468
475
|
if(parameters.verbose) {
|
|
469
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.
|
|
4
|
+
"version": "1.2.2",
|
|
5
5
|
"author": "Codenautas <codenautas@googlegroups.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "https://github.com/codenautas/multilang",
|
|
@@ -25,15 +25,15 @@
|
|
|
25
25
|
"uuid": ">=14.0.0"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"commander": "^
|
|
29
|
-
"js-yaml": "^4.
|
|
28
|
+
"commander": "^15.0.0",
|
|
29
|
+
"js-yaml": "^4.2.0",
|
|
30
30
|
"strip-bom-string": "^1.0.0",
|
|
31
|
-
"best-globals": "^2.
|
|
31
|
+
"best-globals": "^2.2.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"expect.js": "^0.3.1",
|
|
35
35
|
"nyc": "^18.0.0",
|
|
36
|
-
"mocha": "^11.7.
|
|
36
|
+
"mocha": "^11.7.6",
|
|
37
37
|
"expect-called": "^0.4.0"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|