Initial commit

This commit is contained in:
Marcelo
2025-11-20 15:27:34 -06:00
commit cc72c9fc5d
3221 changed files with 737477 additions and 0 deletions

39
node_modules/magicli/tests/main.test.js generated vendored Normal file
View File

@@ -0,0 +1,39 @@
'use strict';
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const { exec } = require('child_process');
const testsPath = path.resolve(__dirname, './test-modules');
const tests = fs.readdirSync(testsPath);
tests.forEach(test => {
describe(test, function() {
const modulePath = path.resolve(testsPath, test);
const packageJson = require(path.resolve(modulePath, 'package.json'));
const moduleCliPath = path.resolve(modulePath, packageJson.bin);
const specs = require(path.resolve(modulePath, 'specs.js'));
specs.forEach(spec => {
const { input, output, description, stdin } = spec;
it(description || input, function() {
return execCli(moduleCliPath, input, stdin).then(result => assert.equal(result, output));
});
});
});
});
function execCli(moduleCliPath, args, stdin = '') {
return new Promise((resolve, reject) => {
const cmd = `${stdin} node ${moduleCliPath} ${args}`;
exec(cmd, (err, stdout, stderr) => {
if (err || stderr) {
return reject(err || stderr);
}
resolve(stdout.replace(/ +$/gm, '').replace(/\n$/, ''));
}).stdin.end();
});
}

View File

@@ -0,0 +1,5 @@
#!/usr/bin/env node
'use strict';
require('../../../../')();

View File

@@ -0,0 +1,3 @@
`use strict`;
module.exports = (p1, p2) => `${p1} ${p2}`;

View File

@@ -0,0 +1,8 @@
{
"name": "function-simple-concat",
"version": "1.0.0",
"private": true,
"description": "Test function-simple-concat",
"main": "lib/index.js",
"bin": "bin/cli.js"
}

View File

@@ -0,0 +1,30 @@
'use strict';
const tests = [{
description: 'Version --version',
input: '--version',
output: `1.0.0`
}, {
description: 'Help --help',
input: '--help',
output: `
Description:
Test function-simple-concat
Usage:
$ function-simple-concat [options]
Options:
--p1
--p2
`
}, {
description: '--p1=P1 --p2=P2',
input: '--p1=P1 --p2=2',
output: 'P1 2'
}];
module.exports = tests;

View File

@@ -0,0 +1,38 @@
#!/usr/bin/env node
'use strict';
require('../../../../')({
commands: {
'a-b-c-d-e-f': {
options: [{
name: 'f1',
required: true
}],
pipe: {
after: JSON.stringify
}
},
'general-test-module': {
pipe: {
stdin: (stdinValue, args) => {
args.param2 = stdinValue;
return args;
},
after: JSON.stringify
}
}
},
validateRequiredParameters: true,
enumerability: 'all',
help: {
option: 'modulehelp',
stripAnsi: true
},
version: {
option: 'moduleversion'
},
pipe: {
after: result => `${result}\n=========`
}
});

View File

@@ -0,0 +1,33 @@
'use strict';
const main = function(param1, param2) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(`o/ ${param1} ${param2}`);
}, 1500);
});
};
main.methodA = function(paramA1, paramA2) {
return `${paramA1}=${paramA2}`;
};
main.methodB = function() {
return `${paramB1}-${paramB2}`;
};
Object.defineProperty(main, 'methodNonEnumerable', {
value: function(paramC1, paramC2) {
return `${paramC1}-${paramC2}`;
}
});
main.a = {
b: (b1, b2) => `main.a.b: ${b1} ${b2}`
};
main.a.b.c = (c1, c2) => `main.a.b.c: ${c1} ${c2}`;
main.a.b.c['d-e'] = {};
main.a.b.c['d-e'].f = ({f1}, [[f2 = 'F2Default']] = [[]]) => ({ f1, f2 });
module.exports = main;

View File

@@ -0,0 +1,8 @@
{
"name": "general-test-module",
"version": "0.0.1",
"private": true,
"description": "general-test-module description",
"main": "./lib/index.js",
"bin": "./bin/cli.js"
}

View File

@@ -0,0 +1,104 @@
'use strict';
const tests = [{
description: 'Version with different option --moduleversion',
input: '--moduleversion',
output: `0.0.1`
}, {
description: 'Help with different option --modulehelp + help.stripAnsi = true + non-enumerable method',
input: '--modulehelp',
output: `
Description:
general-test-module description
Usage:
$ general-test-module [options]
$ general-test-module [command]
Options:
--param1
--param2
Commands:
methodA
methodB
methodNonEnumerable
a-b
a-b-c
a-b-c-d-e-f
`
},{
description: 'Async + STDIN',
stdin: 'echo "PARAM2" | ',
input: '--param1=111',
output: `"o/ 111 PARAM2"
=========`
}, {
description: 'Method non-enumerable --modulehelp',
input: 'methodNonEnumerable --modulehelp',
output: `
Usage:
$ general-test-module methodNonEnumerable [options]
Options:
--paramC1
--paramC2
`
}, {
description: 'Method non-enumerable call',
input: 'methodNonEnumerable --paramC1=val1 --paramC2=val2',
output: `val1-val2
=========`
}, {
description: 'Nested method with no required options',
input: 'a-b-c --modulehelp',
output: `
Usage:
$ general-test-module a-b-c [options]
Options:
--c1
--c2
`
}, {
description: 'Nested method with required options',
input: 'a-b-c-d-e-f --modulehelp',
output: `
Usage:
$ general-test-module a-b-c-d-e-f <options>
Options:
--f1 Required
--f2
`
}, {
description: 'Nested method without one required options',
input: 'a-b-c-d-e-f --f2=2',
output: `
Usage:
$ general-test-module a-b-c-d-e-f <options>
Options:
--f1 Required
--f2
`
}, {
description: 'Nested method passing only the required option',
input: 'a-b-c-d-e-f --f1=2',
output: `{"f1":2,"f2":"F2Default"}
=========`
}];
module.exports = tests;

View File

@@ -0,0 +1,5 @@
#!/usr/bin/env node
'use strict';
require('../../../../')();

View File

@@ -0,0 +1,9 @@
`use strict`;
module.exports = {
methodA: function(param1, param2) {
return `${param1}-${param2}`;
},
methodB: (param1, param2) => `${param1-param2}`
}

View File

@@ -0,0 +1,8 @@
{
"name": "object-flat",
"version": "0.0.0",
"private": true,
"description": "Test object-flat",
"main": "./lib/index.js",
"bin": "./bin/cli.js"
}

View File

@@ -0,0 +1,60 @@
'use strict';
const tests = [{
description: 'Version --version',
input: '--version',
output: `0.0.0`
},{
description: 'Help --help',
input: '--help',
output: `
Description:
Test object-flat
Usage:
$ object-flat <command>
Commands:
methodA
methodB
`
}, {
description: 'methodA --help',
input: 'methodA --help',
output: `
Usage:
$ object-flat methodA [options]
Options:
--param1
--param2
`
}, {
description: 'methodB --help',
input: 'methodB --help',
output: `
Usage:
$ object-flat methodB [options]
Options:
--param1
--param2
`
}, {
description: 'methodA --param2="Z" --param1="K"',
input: 'methodA --param2="Z" --param1="K"',
output: `K-Z`
}, {
description: 'methodB --param1=3 --param2=2',
input: 'methodB --param1=3 --param2=2',
output: `1`
}];
module.exports = tests;