diff --git a/.changeset/famous-ants-agree.md b/.changeset/famous-ants-agree.md new file mode 100644 index 0000000..19c45a6 --- /dev/null +++ b/.changeset/famous-ants-agree.md @@ -0,0 +1,5 @@ +--- +"terminal-keeper": patch +--- + +fix: allow to import the array commands diff --git a/package-lock.json b/package-lock.json index c323598..3db03ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "terminal-keeper", - "version": "1.1.40", + "version": "1.1.48", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "terminal-keeper", - "version": "1.1.40", + "version": "1.1.48", "license": "MIT", "dependencies": { "@sgarciac/bombadil": "^2.3.0", diff --git a/src/commands/importAsync.ts b/src/commands/importAsync.ts index 2ea1957..cf267a6 100644 --- a/src/commands/importAsync.ts +++ b/src/commands/importAsync.ts @@ -51,7 +51,10 @@ const getGlobFiles = (fileType: ImportFileType): Array | undefined => { } }; -const getCommands = async (fileType: ImportFileType, filePath: string): Promise | undefined> => { +const getCommands = async ( + fileType: ImportFileType, + filePath: string +): Promise | undefined> => { switch (fileType) { case 'npm': return extractJsonScriptCommands(filePath); @@ -200,12 +203,8 @@ export const importAsync = async (fileType: ImportFileType): Promise => { // Parse to terminal item from scripts const cwd = path.dirname(selectedFilePath); - const terminalItems = Object.entries(scripts).map(([key, value]) => { - const item: TerminalItem = { - name: key, - cwd, - commands: [value] - }; + const terminalItems = Object.entries(scripts).map(([name, commands]) => { + const item: TerminalItem = { name, cwd, commands }; return item; }); diff --git a/src/commands/modules/antParse.ts b/src/commands/modules/antParse.ts index e978797..05ae5b0 100644 --- a/src/commands/modules/antParse.ts +++ b/src/commands/modules/antParse.ts @@ -14,8 +14,8 @@ const getCommand = (): string => { return ant; }; -const buildCommands = async (contents: string): Promise> => { - const scripts: Record = {}; +const buildCommands = async (contents: string): Promise> => { + const scripts: Record = {}; const cmd = getCommand(); const text = await parseStringPromise(contents); if (text && text.project && text.project.target) { @@ -23,14 +23,15 @@ const buildCommands = async (contents: string): Promise> const targets = text.project.target; for (const tgt of targets) { if (tgt.$ && tgt.$.name) { - scripts[defaultTask === tgt.$.name ? tgt.$.name + ' - Default' : tgt.$.name] = `${cmd} ${tgt.$.name}`; + const name = defaultTask === tgt.$.name ? tgt.$.name + ' - Default' : tgt.$.name; + scripts[name] = [`${cmd} ${tgt.$.name}`]; } } } return scripts; }; -export const extractAntCommands = async (filePath: string): Promise | undefined> => { +export const extractAntCommands = async (filePath: string): Promise | undefined> => { const content = await getFileContent(filePath); return await buildCommands(content); }; diff --git a/src/commands/modules/gradleParse.ts b/src/commands/modules/gradleParse.ts index 7667d23..9ca12f9 100644 --- a/src/commands/modules/gradleParse.ts +++ b/src/commands/modules/gradleParse.ts @@ -13,8 +13,8 @@ const getCommand = (): string => { return gradle; }; -const buildCommands = (contents: string): Record => { - const scripts: Record = {}; +const buildCommands = (contents: string): Record => { + const scripts: Record = {}; const cmd = getCommand(); let idx = 0; let eol = contents.indexOf('\n', 0); @@ -31,7 +31,7 @@ const buildCommands = (contents: string): Record => { if (idx2 !== -1) { const tgtName = line.substring(idx1, idx2).trim(); if (tgtName) { - scripts[tgtName] = `${cmd} ${tgtName}`; + scripts[tgtName] = [`${cmd} ${tgtName}`]; } } } @@ -42,7 +42,7 @@ const buildCommands = (contents: string): Record => { return scripts; }; -export const extractGradleCommands = async (filePath: string): Promise | undefined> => { +export const extractGradleCommands = async (filePath: string): Promise | undefined> => { const content = await getFileContent(filePath); return buildCommands(content); }; diff --git a/src/commands/modules/gruntParse.ts b/src/commands/modules/gruntParse.ts index 8272d0f..a42b273 100644 --- a/src/commands/modules/gruntParse.ts +++ b/src/commands/modules/gruntParse.ts @@ -9,8 +9,8 @@ const getCommand = (): string => { return 'npm grunt'; }; -const buildCommands = (contents: string): Record => { - const scripts: Record = {}; +const buildCommands = (contents: string): Record => { + const scripts: Record = {}; const cmd = getCommand(); let idx = 0; let eol = contents.indexOf('\n', 0); @@ -47,7 +47,7 @@ const buildCommands = (contents: string): Record => { if (idx2 !== -1) { const tgtName = line.substring(idx1, idx2).trim(); if (tgtName) { - scripts[tgtName] = `${cmd} ${tgtName}`; + scripts[tgtName] = [`${cmd} ${tgtName}`]; } } } @@ -59,7 +59,7 @@ const buildCommands = (contents: string): Record => { return scripts; }; -export const extractGruntCommands = async (filePath: string): Promise | undefined> => { +export const extractGruntCommands = async (filePath: string): Promise | undefined> => { const content = await getFileContent(filePath); return buildCommands(content); }; diff --git a/src/commands/modules/gulpParse.ts b/src/commands/modules/gulpParse.ts index dde0d4c..0002361 100644 --- a/src/commands/modules/gulpParse.ts +++ b/src/commands/modules/gulpParse.ts @@ -13,7 +13,7 @@ const parseGulpExport = (line: string) => { let idx1: number, idx2: number; let tgtName: string | undefined; - if (line.toLowerCase().trimLeft().startsWith('exports.')) { + if (line.toLowerCase().trimStart().startsWith('exports.')) { idx1 = line.indexOf('.') + 1; idx2 = line.indexOf(' ', idx1); /* istanbul ignore if */ @@ -24,7 +24,7 @@ const parseGulpExport = (line: string) => { if (idx1 !== -1) { tgtName = line.substring(idx1, idx2).trim(); } - } else if (line.toLowerCase().trimLeft().startsWith('exports[')) { + } else if (line.toLowerCase().trimStart().startsWith('exports[')) { /* istanbul ignore else */ idx1 = line.indexOf('[') + 2; // skip past [ and '/" idx2 = line.indexOf(']', idx1) - 1; // move up to "/' @@ -80,8 +80,8 @@ const parseGulpTask = (line: string, contents: string, eol: number) => { return tgtName; }; -const buildCommands = (contents: string): Record => { - const scripts: Record = {}; +const buildCommands = (contents: string): Record => { + const scripts: Record = {}; const cmd = getCommand(); let idx = 0; let eol = contents.indexOf('\n', 0); @@ -96,7 +96,7 @@ const buildCommands = (contents: string): Record => { tgtName = parseGulpTask(line, contents, eol); } if (tgtName) { - scripts[tgtName] = `${cmd} ${tgtName}`; + scripts[tgtName] = [`${cmd} ${tgtName}`]; } } idx = eol + 1; @@ -105,7 +105,7 @@ const buildCommands = (contents: string): Record => { return scripts; }; -export const extractGulpCommands = async (filePath: string): Promise | undefined> => { +export const extractGulpCommands = async (filePath: string): Promise | undefined> => { const content = await getFileContent(filePath); return buildCommands(content); }; diff --git a/src/commands/modules/jsonScriptParse.ts b/src/commands/modules/jsonScriptParse.ts index d16f209..648942d 100644 --- a/src/commands/modules/jsonScriptParse.ts +++ b/src/commands/modules/jsonScriptParse.ts @@ -4,13 +4,16 @@ const getFileContent = async (filePath: string): Promise => { return await fs.readFileAsync(filePath); }; -const buildCommands = (contents: string): Record => { +const buildCommands = (contents: string): Record => { + const scripts: Record = {}; const packageJson = JSON.parse(contents); - const { scripts } = packageJson || {}; + Object.entries(packageJson?.scripts ?? {}).forEach(([name, command]) => { + scripts[name] = Array.isArray(command) ? command : [command]; + }); return scripts; }; -export const extractJsonScriptCommands = async (filePath: string): Promise | undefined> => { +export const extractJsonScriptCommands = async (filePath: string): Promise | undefined> => { const content = await getFileContent(filePath); return buildCommands(content); }; diff --git a/src/commands/modules/makeParse.ts b/src/commands/modules/makeParse.ts index f7611e2..065c19e 100644 --- a/src/commands/modules/makeParse.ts +++ b/src/commands/modules/makeParse.ts @@ -49,8 +49,8 @@ const getCommand = (): string => { return make; }; -const buildCommands = (contents: string): Record => { - const scripts: Record = {}; +const buildCommands = (contents: string): Record => { + const scripts: Record = {}; const cmd = getCommand(); let match; while ((match = ruleTargetExp.exec(contents))) { @@ -59,13 +59,13 @@ const buildCommands = (contents: string): Record => { continue; } if (isNormalTarget(tgtName)) { - scripts[tgtName] = `${cmd} ${tgtName}`; + scripts[tgtName] = [`${cmd} ${tgtName}`]; } } return scripts; }; -export const extractMakeCommands = async (filePath: string): Promise | undefined> => { +export const extractMakeCommands = async (filePath: string): Promise | undefined> => { const content = await getFileContent(filePath); return buildCommands(content); }; diff --git a/src/commands/modules/pipenvParse.ts b/src/commands/modules/pipenvParse.ts index 5a08454..2353088 100644 --- a/src/commands/modules/pipenvParse.ts +++ b/src/commands/modules/pipenvParse.ts @@ -12,18 +12,18 @@ const getCommand = (): string => { return gradle; }; -const buildCommands = (contents: string): Record => { - const scripts: Record = {}; +const buildCommands = (contents: string): Record => { + const scripts: Record = {}; const cmd = getCommand(); const pipfile = new TomlReader(); pipfile.readToml(contents); Object.entries(pipfile.result?.scripts ?? {}).forEach(([scriptName, _scriptCmd]) => { - scripts[scriptName] = `${cmd} ${scriptName}`; + scripts[scriptName] = [`${cmd} ${scriptName}`]; }); return scripts; }; -export const extractPipenvCommands = async (filePath: string): Promise | undefined> => { +export const extractPipenvCommands = async (filePath: string): Promise | undefined> => { const content = await getFileContent(filePath); return buildCommands(content); };