UNPKG

radashi-helper

Version:
97 lines (78 loc) 4.67 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _chunkDNQVKCXJcjs = require('./chunk-DNQVKCXJ.cjs'); var _chunkIWXG7YVCcjs = require('./chunk-IWXG7YVC.cjs'); var _chunk4WZBZWYDcjs = require('./chunk-4WZBZWYD.cjs'); var _chunkZP624W2Acjs = require('./chunk-ZP624W2A.cjs'); var _chunkST3J6QTNcjs = require('./chunk-ST3J6QTN.cjs'); var _chunk5R2KEZLQcjs = require('./chunk-5R2KEZLQ.cjs'); // src/fn-remove.ts var _fs = require('fs'); var _promises = require('fs/promises'); var _promises2 = _interopRequireDefault(_promises); var _path = require('path'); async function removeFunction(options = {}) { const env = _nullishCoalesce(options.env, () => ( _chunkZP624W2Acjs.getEnv.call(void 0, options.dir))); let oldFuncPath = options.funcPath; if (!oldFuncPath) { const pathsInside = await _chunkDNQVKCXJcjs.findSources.call(void 0, env, ["src", "overrides"]); _chunkZP624W2Acjs.debug.call(void 0, "pathsInside:", pathsInside); const { src: sourceFuncs = [], overrides: overrideFuncs = [] } = _chunk5R2KEZLQcjs.objectify.call(void 0, Object.entries(pathsInside), ([type]) => type, ([type, sourcePaths]) => { const sourceRoot = _path.join.call(void 0, type === "src" ? env.root : env.overrideDir, "src" ); return _optionalChain([sourcePaths, 'optionalAccess', _ => _.map, 'call', _2 => _2( (sourcePath) => _path.relative.call(void 0, sourceRoot, sourcePath).replace(/\.ts$/, "") )]); } ); _chunkZP624W2Acjs.debug.call(void 0, "sourceFuncs:", sourceFuncs); _chunkZP624W2Acjs.debug.call(void 0, "overrideFuncs:", overrideFuncs); const selectedFunc = await _chunk4WZBZWYDcjs.prompt.call(void 0, { type: "autocomplete", name: "selectedFunc", message: "Select a function to remove:", choices: [...sourceFuncs, ...overrideFuncs].sort().map((funcPath) => ({ title: funcPath, value: funcPath })) }); if (!selectedFunc) { throw new (0, _chunkST3J6QTNcjs.EarlyExitError)("No function selected. Exiting..."); } oldFuncPath = selectedFunc; } const checkFile = (folderPrefix2) => _fs.existsSync.call(void 0, _path.join.call(void 0, folderPrefix2, oldFuncPath + ".ts")); const folderPrefix = checkFile(_path.join.call(void 0, env.root, "src")) ? env.root : checkFile(_path.join.call(void 0, env.overrideDir, "src")) ? env.overrideDir : null; if (!folderPrefix) { throw new (0, _chunkST3J6QTNcjs.RadashiError)( `Function ${oldFuncPath} was not found in ${env.root}/src or the overrides folder` ); } const [oldGroup, oldFuncName] = oldFuncPath.split("/"); for (const folder of _chunkIWXG7YVCcjs.projectFolders) { const prevPath = _path.join.call(void 0, folderPrefix, folder.name, oldGroup, oldFuncName + folder.extension ); if (!_fs.existsSync.call(void 0, prevPath)) { continue; } _chunkST3J6QTNcjs.log.call(void 0, `Removing ${_chunkIWXG7YVCcjs.cwdRelative.call(void 0, prevPath)}`); await _promises.rm.call(void 0, prevPath); const prevDir = _path.dirname.call(void 0, prevPath); if ((await _promises.readdir.call(void 0, prevDir)).length === 0) { _chunkST3J6QTNcjs.log.call(void 0, `Removing empty directory: ${_chunkIWXG7YVCcjs.cwdRelative.call(void 0, prevDir)}`); await _promises2.default.rm(prevDir, { recursive: true }); } } if (env.radashiDir) { const { default: build } = await Promise.resolve().then(() => _interopRequireWildcard(require("./build-D32K7VSY.cjs"))); await build({ env }); } } exports.removeFunction = removeFunction;