Skip to content

Commit 3bb0dd3

Browse files
committed
pretty rule
1 parent ffe4d9f commit 3bb0dd3

File tree

2 files changed

+126
-125
lines changed

2 files changed

+126
-125
lines changed

index.js

+124-124
Original file line numberDiff line numberDiff line change
@@ -9,158 +9,158 @@ const os = require("os");
99
let PERL;
1010

1111
async function install_cpm_location() {
12-
let out = "";
12+
let out = "";
1313

14-
const options = {};
15-
options.listeners = {
16-
stdout: (data) => {
17-
out += data.toString();
18-
},
19-
};
14+
const options = {};
15+
options.listeners = {
16+
stdout: (data) => {
17+
out += data.toString();
18+
},
19+
};
2020

21-
let p = core.getInput("path");
22-
p.replace("\\", "\\\\");
23-
await exec.exec(PERL, ["-MConfig", "-e", `print "${p}"`], options);
21+
let p = core.getInput("path");
22+
p.replace("\\", "\\\\");
23+
await exec.exec(PERL, ["-MConfig", "-e", `print "${p}"`], options);
2424

25-
return path.resolve(out);
25+
return path.resolve(out);
2626
}
2727

2828
async function install_cpm(install_to) {
29-
const version = core.getInput("version");
30-
const url = `https://raw.githubusercontent.com/skaji/cpm/${version}/cpm`;
29+
const version = core.getInput("version");
30+
const url = `https://raw.githubusercontent.com/skaji/cpm/${version}/cpm`;
3131

32-
core.info(`Get cpm from URL: ${url}`);
32+
core.info(`Get cpm from URL: ${url}`);
3333

34-
const cpmScript = await tc.downloadTool(url);
34+
const cpmScript = await tc.downloadTool(url);
3535

36-
core.info(`Install cpm to: ${install_to}`);
36+
core.info(`Install cpm to: ${install_to}`);
3737

38-
const platform = os.platform();
38+
const platform = os.platform();
3939

40-
if (platform == "win32") {
41-
await io.cp(cpmScript, install_to);
42-
} else {
43-
await do_exec([
44-
PERL,
45-
"-MFile::Copy=cp",
46-
"-e",
47-
`cp("${cpmScript}", "${install_to}"); chmod(0755, "${install_to}")`,
48-
]);
49-
}
40+
if (platform == "win32") {
41+
await io.cp(cpmScript, install_to);
42+
} else {
43+
await do_exec([
44+
PERL,
45+
"-MFile::Copy=cp",
46+
"-e",
47+
`cp("${cpmScript}", "${install_to}"); chmod(0755, "${install_to}")`,
48+
]);
49+
}
5050

51-
return install_to;
51+
return install_to;
5252
}
5353

5454
async function which_perl() {
55-
const perl = core.getInput("perl");
56-
if (perl == "perl") {
57-
return await io.which("perl", true);
58-
}
59-
return perl;
55+
const perl = core.getInput("perl");
56+
if (perl == "perl") {
57+
return await io.which("perl", true);
58+
}
59+
return perl;
6060
}
6161

6262
function is_true(b) {
63-
if (b !== null && (b === true || b == "true" || b == "1" || b == "ok")) {
64-
return true;
65-
}
63+
if (b !== null && (b === true || b == "true" || b == "1" || b == "ok")) {
64+
return true;
65+
}
6666

67-
return false;
67+
return false;
6868
}
6969

7070
async function do_exec(cmd) {
71-
const sudo = is_true(core.getInput("sudo"));
72-
const platform = os.platform();
73-
const bin = sudo && platform != "win32" ? "sudo" : cmd.shift();
71+
const sudo = is_true(core.getInput("sudo"));
72+
const platform = os.platform();
73+
const bin = sudo && platform != "win32" ? "sudo" : cmd.shift();
7474

75-
core.info(`do_exec: ${bin}`);
75+
core.info(`do_exec: ${bin}`);
7676

77-
await exec.exec(bin, cmd);
77+
await exec.exec(bin, cmd);
7878
}
7979

8080
async function run() {
81-
PERL = await which_perl();
82-
83-
const cpm_location = await install_cpm_location();
84-
85-
await install_cpm(cpm_location);
86-
87-
// input arguments
88-
const install = core.getInput("install");
89-
const cpanfile = core.getInput("cpanfile");
90-
const tests = core.getInput("tests");
91-
const dash_g = core.getInput("global");
92-
const args = core.getInput("args");
93-
const verbose = core.getInput("verbose");
94-
95-
const w_tests = is_true(tests) ? "--test" : "--no-test";
96-
let w_args = [];
97-
98-
if (args !== null && args.length) {
99-
w_args = args.split(/\s+/);
100-
}
101-
102-
/* base CMD_install command */
103-
let CMD_install = [
104-
PERL,
105-
cpm_location,
106-
"install",
107-
"--show-build-log-on-failure",
108-
w_tests,
109-
];
110-
111-
if (is_true(verbose)) {
112-
CMD_install.push("-v");
113-
}
114-
if (is_true(dash_g)) {
115-
CMD_install.push("-g");
116-
}
117-
if (w_args.length) {
118-
CMD_install = CMD_install.concat(w_args);
119-
}
120-
121-
let has_run = false;
122-
123-
/* install one ore more modules */
124-
if (install !== null && install.length) {
125-
// install one or more modules
126-
core.info(`install: ${install}!`);
127-
const list = install.split("\n");
128-
129-
let cmd = [...CMD_install]; /* clone array */
130-
cmd = cmd.concat(list);
131-
132-
has_run = true;
133-
await do_exec(cmd);
134-
}
135-
136-
/* install from cpanfile */
137-
if (cpanfile !== null && cpanfile.length) {
138-
// install one or more modules
139-
core.info(`cpanfile: ${cpanfile}!`);
140-
const cpanfile_full_path = path.resolve(cpanfile);
141-
core.info(`cpanfile: ${cpanfile_full_path}! [resolved]`);
142-
143-
let cmd = [...CMD_install];
144-
cmd.push("--cpanfile", cpanfile_full_path);
145-
146-
has_run = true;
147-
await do_exec(cmd);
148-
}
149-
150-
/* custom run with args */
151-
if ( has_run === false && w_args.length ) {
152-
core.info(`custom run with args`);
153-
let cmd = [...CMD_install];
154-
has_run = true;
155-
await do_exec(cmd);
156-
}
81+
PERL = await which_perl();
82+
83+
const cpm_location = await install_cpm_location();
84+
85+
await install_cpm(cpm_location);
86+
87+
// input arguments
88+
const install = core.getInput("install");
89+
const cpanfile = core.getInput("cpanfile");
90+
const tests = core.getInput("tests");
91+
const dash_g = core.getInput("global");
92+
const args = core.getInput("args");
93+
const verbose = core.getInput("verbose");
94+
95+
const w_tests = is_true(tests) ? "--test" : "--no-test";
96+
let w_args = [];
97+
98+
if (args !== null && args.length) {
99+
w_args = args.split(/\s+/);
100+
}
101+
102+
/* base CMD_install command */
103+
let CMD_install = [
104+
PERL,
105+
cpm_location,
106+
"install",
107+
"--show-build-log-on-failure",
108+
w_tests,
109+
];
110+
111+
if (is_true(verbose)) {
112+
CMD_install.push("-v");
113+
}
114+
if (is_true(dash_g)) {
115+
CMD_install.push("-g");
116+
}
117+
if (w_args.length) {
118+
CMD_install = CMD_install.concat(w_args);
119+
}
120+
121+
let has_run = false;
122+
123+
/* install one ore more modules */
124+
if (install !== null && install.length) {
125+
// install one or more modules
126+
core.info(`install: ${install}!`);
127+
const list = install.split("\n");
128+
129+
let cmd = [...CMD_install]; /* clone array */
130+
cmd = cmd.concat(list);
131+
132+
has_run = true;
133+
await do_exec(cmd);
134+
}
135+
136+
/* install from cpanfile */
137+
if (cpanfile !== null && cpanfile.length) {
138+
// install one or more modules
139+
core.info(`cpanfile: ${cpanfile}!`);
140+
const cpanfile_full_path = path.resolve(cpanfile);
141+
core.info(`cpanfile: ${cpanfile_full_path}! [resolved]`);
142+
143+
let cmd = [...CMD_install];
144+
cmd.push("--cpanfile", cpanfile_full_path);
145+
146+
has_run = true;
147+
await do_exec(cmd);
148+
}
149+
150+
/* custom run with args */
151+
if (has_run === false && w_args.length) {
152+
core.info(`custom run with args`);
153+
let cmd = [...CMD_install];
154+
has_run = true;
155+
await do_exec(cmd);
156+
}
157157
}
158158

159159
// Call run
160160
(async () => {
161-
try {
162-
await run();
163-
} catch (error) {
164-
core.setFailed(error.message);
165-
}
166-
})();
161+
try {
162+
await run();
163+
} catch (error) {
164+
core.setFailed(error.message);
165+
}
166+
})();

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"scripts": {
77
"lint": "eslint index.js",
88
"test": "echo \"Error: no test specified\" && exit 1",
9-
"build": "ncc build index.js"
9+
"build": "ncc build index.js",
10+
"pretty": "js-beautify -r index.js"
1011
},
1112
"repository": {
1213
"type": "git",

0 commit comments

Comments
 (0)