npx https://gist.github.com/chokolademilch7/968e8b300720389230336ea375e59541 対象ディレクトリ 出力後の名前 出力するディレクトリ
引数なしだと currentDirectoryが入ります
第一引数? 対象のディレクトリ
第二引数? 出力後の名前(勝手に.code-workspaceという拡張子がつきます) ex. hoge -> hoge.code-workspace
第三引数? 出力するディレクトリ
{ | |
"name": "vscode-workspace", | |
"version": "1.0.0", | |
"bin": "./vscode-workspace.js", | |
"repository": { | |
"type": "git", | |
"url": "git+ssh://[email protected]/968e8b300720389230336ea375e59541.git" | |
}, | |
"keywords": [ | |
"vscode" | |
], | |
"author": "chokolademilch7", | |
"license": "ISC", | |
"bugs": { | |
"url": "https://gist.github.com/968e8b300720389230336ea375e59541" | |
}, | |
"homepage": "https://gist.github.com/968e8b300720389230336ea375e59541" | |
} |
#!/usr/bin/env node | |
const fs = require('fs'); | |
const path = require('path'); | |
class VscodeProjectCreator { | |
constructor({inputPath = '.', outputName = 'generated', outputPath = '.', opts}) { | |
this.inputPath = inputPath; | |
this.outputName = `${outputName}.code-workspace`; | |
this.outputPath = outputPath; | |
this.opts = {opts}; | |
this.__generatedInputPath = this.__generateRelativePath(this.inputPath); | |
this.__generatedOutputPath = this.__generateRelativePath(this.outputPath); | |
} | |
__generateRelativePath(dp) { | |
if (dp.includes('.')) { | |
return path.join(process.cwd(), dp); | |
} | |
return dp; | |
} | |
createWorkspace() { | |
const { outputName, __generatedInputPath, __generatedOutputPath } = this; | |
const pathData = fs.readdirSync(__generatedInputPath) | |
.filter(name => fs.statSync(path.join(__generatedInputPath, name)).isDirectory()) | |
.map(name => { | |
return { | |
name, | |
path: path.join(__generatedInputPath, name) | |
} | |
}) | |
const data = {}; | |
data.folders = pathData; | |
const outputData = JSON.stringify(data, null , "\t"); | |
fs.writeFileSync(path.join(__generatedOutputPath, outputName), outputData); | |
console.log(`ここに保存したよー ${__generatedOutputPath}`); | |
} | |
} | |
let target = {}; | |
target.inputPath = process.argv[2]; | |
target.outputName = process.argv[3] | |
target.outputPath = process.argv[4]; | |
target.opts = [...process.argv]; | |
const VscodeProject = new VscodeProjectCreator(target); | |
VscodeProject.createWorkspace(); |