From 1bc54dac2e9e02647231a08540c66004a7e87ace Mon Sep 17 00:00:00 2001 From: Nicolas R Date: Thu, 25 Apr 2024 15:51:50 +0100 Subject: [PATCH] pretty rule --- index.js | 248 +++++++++++++++++++++++++-------------------------- package.json | 3 +- 2 files changed, 126 insertions(+), 125 deletions(-) diff --git a/index.js b/index.js index 33e00ad..fcd5eb5 100644 --- a/index.js +++ b/index.js @@ -9,158 +9,158 @@ const os = require("os"); let PERL; async function install_cpm_location() { - let out = ""; + let out = ""; - const options = {}; - options.listeners = { - stdout: (data) => { - out += data.toString(); - }, - }; + const options = {}; + options.listeners = { + stdout: (data) => { + out += data.toString(); + }, + }; - let p = core.getInput("path"); - p.replace("\\", "\\\\"); - await exec.exec(PERL, ["-MConfig", "-e", `print "${p}"`], options); + let p = core.getInput("path"); + p.replace("\\", "\\\\"); + await exec.exec(PERL, ["-MConfig", "-e", `print "${p}"`], options); - return path.resolve(out); + return path.resolve(out); } async function install_cpm(install_to) { - const version = core.getInput("version"); - const url = `https://raw.githubusercontent.com/skaji/cpm/${version}/cpm`; + const version = core.getInput("version"); + const url = `https://raw.githubusercontent.com/skaji/cpm/${version}/cpm`; - core.info(`Get cpm from URL: ${url}`); + core.info(`Get cpm from URL: ${url}`); - const cpmScript = await tc.downloadTool(url); + const cpmScript = await tc.downloadTool(url); - core.info(`Install cpm to: ${install_to}`); + core.info(`Install cpm to: ${install_to}`); - const platform = os.platform(); + const platform = os.platform(); - if (platform == "win32") { - await io.cp(cpmScript, install_to); - } else { - await do_exec([ - PERL, - "-MFile::Copy=cp", - "-e", - `cp("${cpmScript}", "${install_to}"); chmod(0755, "${install_to}")`, - ]); - } + if (platform == "win32") { + await io.cp(cpmScript, install_to); + } else { + await do_exec([ + PERL, + "-MFile::Copy=cp", + "-e", + `cp("${cpmScript}", "${install_to}"); chmod(0755, "${install_to}")`, + ]); + } - return install_to; + return install_to; } async function which_perl() { - const perl = core.getInput("perl"); - if (perl == "perl") { - return await io.which("perl", true); - } - return perl; + const perl = core.getInput("perl"); + if (perl == "perl") { + return await io.which("perl", true); + } + return perl; } function is_true(b) { - if (b !== null && (b === true || b == "true" || b == "1" || b == "ok")) { - return true; - } + if (b !== null && (b === true || b == "true" || b == "1" || b == "ok")) { + return true; + } - return false; + return false; } async function do_exec(cmd) { - const sudo = is_true(core.getInput("sudo")); - const platform = os.platform(); - const bin = sudo && platform != "win32" ? "sudo" : cmd.shift(); + const sudo = is_true(core.getInput("sudo")); + const platform = os.platform(); + const bin = sudo && platform != "win32" ? "sudo" : cmd.shift(); - core.info(`do_exec: ${bin}`); + core.info(`do_exec: ${bin}`); - await exec.exec(bin, cmd); + await exec.exec(bin, cmd); } async function run() { - PERL = await which_perl(); - - const cpm_location = await install_cpm_location(); - - await install_cpm(cpm_location); - - // input arguments - const install = core.getInput("install"); - const cpanfile = core.getInput("cpanfile"); - const tests = core.getInput("tests"); - const dash_g = core.getInput("global"); - const args = core.getInput("args"); - const verbose = core.getInput("verbose"); - - const w_tests = is_true(tests) ? "--test" : "--no-test"; - let w_args = []; - - if (args !== null && args.length) { - w_args = args.split(/\s+/); - } - - /* base CMD_install command */ - let CMD_install = [ - PERL, - cpm_location, - "install", - "--show-build-log-on-failure", - w_tests, - ]; - - if (is_true(verbose)) { - CMD_install.push("-v"); - } - if (is_true(dash_g)) { - CMD_install.push("-g"); - } - if (w_args.length) { - CMD_install = CMD_install.concat(w_args); - } - - let has_run = false; - - /* install one ore more modules */ - if (install !== null && install.length) { - // install one or more modules - core.info(`install: ${install}!`); - const list = install.split("\n"); - - let cmd = [...CMD_install]; /* clone array */ - cmd = cmd.concat(list); - - has_run = true; - await do_exec(cmd); - } - - /* install from cpanfile */ - if (cpanfile !== null && cpanfile.length) { - // install one or more modules - core.info(`cpanfile: ${cpanfile}!`); - const cpanfile_full_path = path.resolve(cpanfile); - core.info(`cpanfile: ${cpanfile_full_path}! [resolved]`); - - let cmd = [...CMD_install]; - cmd.push("--cpanfile", cpanfile_full_path); - - has_run = true; - await do_exec(cmd); - } - - /* custom run with args */ - if ( has_run === false && w_args.length ) { - core.info(`custom run with args`); - let cmd = [...CMD_install]; - has_run = true; - await do_exec(cmd); - } + PERL = await which_perl(); + + const cpm_location = await install_cpm_location(); + + await install_cpm(cpm_location); + + // input arguments + const install = core.getInput("install"); + const cpanfile = core.getInput("cpanfile"); + const tests = core.getInput("tests"); + const dash_g = core.getInput("global"); + const args = core.getInput("args"); + const verbose = core.getInput("verbose"); + + const w_tests = is_true(tests) ? "--test" : "--no-test"; + let w_args = []; + + if (args !== null && args.length) { + w_args = args.split(/\s+/); + } + + /* base CMD_install command */ + let CMD_install = [ + PERL, + cpm_location, + "install", + "--show-build-log-on-failure", + w_tests, + ]; + + if (is_true(verbose)) { + CMD_install.push("-v"); + } + if (is_true(dash_g)) { + CMD_install.push("-g"); + } + if (w_args.length) { + CMD_install = CMD_install.concat(w_args); + } + + let has_run = false; + + /* install one ore more modules */ + if (install !== null && install.length) { + // install one or more modules + core.info(`install: ${install}!`); + const list = install.split("\n"); + + let cmd = [...CMD_install]; /* clone array */ + cmd = cmd.concat(list); + + has_run = true; + await do_exec(cmd); + } + + /* install from cpanfile */ + if (cpanfile !== null && cpanfile.length) { + // install one or more modules + core.info(`cpanfile: ${cpanfile}!`); + const cpanfile_full_path = path.resolve(cpanfile); + core.info(`cpanfile: ${cpanfile_full_path}! [resolved]`); + + let cmd = [...CMD_install]; + cmd.push("--cpanfile", cpanfile_full_path); + + has_run = true; + await do_exec(cmd); + } + + /* custom run with args */ + if (has_run === false && w_args.length) { + core.info(`custom run with args`); + let cmd = [...CMD_install]; + has_run = true; + await do_exec(cmd); + } } // Call run (async () => { - try { - await run(); - } catch (error) { - core.setFailed(error.message); - } -})(); + try { + await run(); + } catch (error) { + core.setFailed(error.message); + } +})(); \ No newline at end of file diff --git a/package.json b/package.json index faf1318..b6fed2b 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "lint": "eslint index.js", "test": "echo \"Error: no test specified\" && exit 1", - "build": "ncc build index.js" + "build": "ncc build index.js", + "pretty": "js-beautify -r index.js" }, "repository": { "type": "git",