Skip to content

Commit 7ecef7d

Browse files
committed
feat: add config input. #2
1 parent daec4c5 commit 7ecef7d

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Output Project Structure
5454
- `path` Folder path. (default `./`)
5555
- `depth` Scan the maximum depth reachable for the given path (default `5`)
5656
- `exclude` Pass a regex string to exclude directories from printing
57+
- `config` The path to the dree configuration file
5758

5859
## Outputs
5960

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ inputs:
1414
description: 'Pass a regex string to exclude directories from printing'
1515
default: ''
1616
required: false
17+
config:
18+
description: 'The path to the dree configuration file'
19+
required: false
1720
depth:
1821
description: 'Scan the maximum depth reachable for the given path'
1922
default: 5

dist/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34895,8 +34895,12 @@ var __webpack_exports__ = {};
3489534895

3489634896
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/regeneratorRuntime.js
3489734897
var regeneratorRuntime = __webpack_require__(675);
34898+
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/objectSpread2.js
34899+
var objectSpread2 = __webpack_require__(9379);
3489834900
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js
3489934901
var asyncToGenerator = __webpack_require__(467);
34902+
// EXTERNAL MODULE: external "fs"
34903+
var external_fs_ = __webpack_require__(9896);
3490034904
// EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js
3490134905
var github = __webpack_require__(8340);
3490234906
// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js
@@ -37937,7 +37941,7 @@ function _Te() {
3793737941
}
3793837942

3793937943
;// CONCATENATED MODULE: ./src/index.ts
37940-
function convertToNumber(str){var num=+str;return isNaN(num)?5:num;};(0,asyncToGenerator/* default */.A)(/*#__PURE__*/(0,regeneratorRuntime/* default */.A)().mark(function _callee(){var folderPath,exclude,depth,_context$repo,owner,repo,dtreeOptions,dreeResult;return (0,regeneratorRuntime/* default */.A)().wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:folderPath=(0,core.getInput)('path')||".";exclude=(0,core.getInput)('exclude');depth=convertToNumber((0,core.getInput)('depth')||"5");_context$repo=github.context.repo,owner=_context$repo.owner,repo=_context$repo.repo;dtreeOptions={depth:depth};try{if(exclude){dtreeOptions.exclude=new RegExp(exclude);}dreeResult=Se(folderPath,dtreeOptions);(0,core.startGroup)("\x1B[32;1m ".concat(owner,"/").concat(repo," \x1B[0m tree: "));(0,core.info)("".concat(dreeResult));(0,core.endGroup)();(0,core.setOutput)('content',dreeResult);}catch(error){(0,core.setFailed)(error);}case 6:case"end":return _context.stop();}},_callee);}))();
37944+
function convertToNumber(str){var num=+str;return isNaN(num)?5:num;};(0,asyncToGenerator/* default */.A)(/*#__PURE__*/(0,regeneratorRuntime/* default */.A)().mark(function _callee(){var folderPath,exclude,config,depth,_context$repo,owner,repo,dtreeOptions,conf,dreeResult;return (0,regeneratorRuntime/* default */.A)().wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:folderPath=(0,core.getInput)('path',{required:false})||".";exclude=(0,core.getInput)('exclude',{required:false});config=(0,core.getInput)('config',{required:false})||undefined;depth=convertToNumber((0,core.getInput)('depth')||"5");_context$repo=github.context.repo,owner=_context$repo.owner,repo=_context$repo.repo;dtreeOptions={depth:depth};try{if(exclude){dtreeOptions.exclude=new RegExp(exclude);}if(config&&external_fs_.existsSync(config)){conf=JSON.parse(external_fs_.readFileSync(config,'utf-8'));dtreeOptions=(0,objectSpread2/* default */.A)((0,objectSpread2/* default */.A)({},dtreeOptions),conf);}dreeResult=Se(folderPath,dtreeOptions);(0,core.startGroup)("\x1B[32;1m ".concat(owner,"/").concat(repo," \x1B[0m tree: "));(0,core.info)("".concat(dreeResult));(0,core.endGroup)();(0,core.setOutput)('content',dreeResult);}catch(error){(0,core.setFailed)(error);}case 7:case"end":return _context.stop();}},_callee);}))();
3794137945
})();
3794237946

3794337947
module.exports = __webpack_exports__;

src/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as fs from 'fs';
12
import { context } from '@actions/github';
23
import { getInput, setOutput, setFailed, startGroup, info, endGroup } from '@actions/core';
34
import { parse, ParseOptions } from 'dree';
@@ -8,17 +9,22 @@ function convertToNumber(str: string): number {
89
}
910

1011
;(async () => {
11-
const folderPath = getInput('path') || ".";
12-
const exclude = getInput('exclude');
12+
const folderPath = getInput('path', { required: false }) || ".";
13+
const exclude = getInput('exclude', { required: false });
14+
const config = getInput('config', { required: false }) || undefined;
1315
const depth: number = convertToNumber(getInput('depth') || "5");
1416
const {owner, repo} = context.repo
1517

16-
const dtreeOptions: ParseOptions = { depth };
18+
let dtreeOptions: ParseOptions = { depth };
1719

1820
try {
1921
if (exclude) {
2022
dtreeOptions.exclude = new RegExp(exclude);
2123
}
24+
if (config && fs.existsSync(config)) {
25+
let conf = JSON.parse(fs.readFileSync(config, 'utf-8'));
26+
dtreeOptions = { ...dtreeOptions, ...conf };
27+
}
2228
const dreeResult = parse(folderPath, dtreeOptions);
2329
startGroup(`\x1b[32;1m ${owner}/${repo} \x1b[0m tree: `);
2430
info(`${dreeResult}`);

0 commit comments

Comments
 (0)