Skip to content

Commit

Permalink
feat: add config input. #2
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Aug 19, 2024
1 parent daec4c5 commit 7ecef7d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Output Project Structure
- `path` Folder path. (default `./`)
- `depth` Scan the maximum depth reachable for the given path (default `5`)
- `exclude` Pass a regex string to exclude directories from printing
- `config` The path to the dree configuration file

## Outputs

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ inputs:
description: 'Pass a regex string to exclude directories from printing'
default: ''
required: false
config:
description: 'The path to the dree configuration file'
required: false
depth:
description: 'Scan the maximum depth reachable for the given path'
default: 5
Expand Down
6 changes: 5 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34895,8 +34895,12 @@ var __webpack_exports__ = {};

// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/regeneratorRuntime.js
var regeneratorRuntime = __webpack_require__(675);
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/objectSpread2.js
var objectSpread2 = __webpack_require__(9379);
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js
var asyncToGenerator = __webpack_require__(467);
// EXTERNAL MODULE: external "fs"
var external_fs_ = __webpack_require__(9896);
// EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js
var github = __webpack_require__(8340);
// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js
Expand Down Expand Up @@ -37937,7 +37941,7 @@ function _Te() {
}

;// CONCATENATED MODULE: ./src/index.ts
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);}))();
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);}))();
})();

module.exports = __webpack_exports__;
Expand Down
12 changes: 9 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as fs from 'fs';
import { context } from '@actions/github';
import { getInput, setOutput, setFailed, startGroup, info, endGroup } from '@actions/core';
import { parse, ParseOptions } from 'dree';
Expand All @@ -8,17 +9,22 @@ function convertToNumber(str: string): number {
}

;(async () => {
const folderPath = getInput('path') || ".";
const exclude = getInput('exclude');
const folderPath = getInput('path', { required: false }) || ".";
const exclude = getInput('exclude', { required: false });
const config = getInput('config', { required: false }) || undefined;
const depth: number = convertToNumber(getInput('depth') || "5");
const {owner, repo} = context.repo

const dtreeOptions: ParseOptions = { depth };
let dtreeOptions: ParseOptions = { depth };

try {
if (exclude) {
dtreeOptions.exclude = new RegExp(exclude);
}
if (config && fs.existsSync(config)) {
let conf = JSON.parse(fs.readFileSync(config, 'utf-8'));
dtreeOptions = { ...dtreeOptions, ...conf };
}
const dreeResult = parse(folderPath, dtreeOptions);
startGroup(`\x1b[32;1m ${owner}/${repo} \x1b[0m tree: `);
info(`${dreeResult}`);
Expand Down

0 comments on commit 7ecef7d

Please sign in to comment.