| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- /**
- * fun 结点:create-folder(脚本名 create-forder 为历史拼写)
- * inVars[0] 或字段 path:目录路径(相对当前流程目录或绝对路径)
- * 使用 fs.mkdirSync(..., { recursive: true })
- */
- const path = require('path')
- const fs = require('fs')
- function buildAbsolutePath (p, folderPath) {
- if (p == null || p === '') return null
- const s = typeof p === 'string' ? p.trim() : String(p).trim()
- if (!s) return null
- if (path.isAbsolute(s) || /^[A-Za-z]:/.test(s)) return path.normalize(s)
- return folderPath ? path.join(folderPath, s) : path.resolve(s)
- }
- /**
- * @param {{ path?: string, dirPath?: string, folderPath?: string }} input
- */
- async function executeCreateFolder ({ path: p, dirPath, folderPath }) {
- const rel = p != null && String(p).trim() !== '' ? p : dirPath
- if (rel == null || String(rel).trim() === '') {
- return { success: false, error: 'create-folder 缺少 path(inVars[0] 或字段 path)' }
- }
- const abs = buildAbsolutePath(String(rel).trim(), folderPath)
- if (!abs) return { success: false, error: 'create-folder 路径无效' }
- try {
- fs.mkdirSync(abs, { recursive: true })
- } catch (e) {
- return { success: false, error: e && e.message ? e.message : String(e) }
- }
- return {
- success: true,
- path: abs,
- value: abs,
- result: abs,
- }
- }
- module.exports = { executeCreateFolder }
|