-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tedjmzhang
committed
Jun 3, 2024
1 parent
c657ecf
commit ccb5b19
Showing
9 changed files
with
59 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#!/usr/bin/env node | ||
const { program } = require('commander'); | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# inquirer | ||
|
||
命令行交互库 | ||
命令行交互库, 统一所有交互,然后再后面的then作为返回值处理 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env node | ||
|
||
let { program } = require("commander"); | ||
let { readFileSync, readdirSync, writeFileSync } = require("fs"); | ||
let path = require('path'); | ||
|
||
program.command('prebuild').description('发布之前执行的hook') | ||
.action(() => { | ||
appendJSToMD(__dirname) | ||
}) | ||
|
||
|
||
function appendJSToMD(dirPath) { | ||
console.log(__dirname) | ||
let currentDirName = path.basename(dirPath) | ||
let dirInfoList = readdirSync(dirPath, { withFileTypes: true }); | ||
// 该文件夹下面有index.js 或者dirname.js 同时该文件下面有index.md | ||
let files = dirInfoList.filter(item => item.isFile()); | ||
let dirs = dirInfoList.filter(item => item.isDirectory()); | ||
let origin = null, destination = null; | ||
files.forEach(item => { | ||
if (['index.md', `${currentDirName}.md`].includes(item.name)) { | ||
destination = item | ||
return; | ||
} | ||
if (['index.js', `${currentDirName}.js`, 'index.mjs', `${currentDirName}.mjs`].includes(item.name)) { | ||
origin = item; | ||
return; | ||
} | ||
}) | ||
|
||
if (origin && destination) { | ||
let originText = readFileSync(path.resolve(dirPath, origin.name)); | ||
writeFileSync(path.resolve(dirPath, "index-source.md"), ` | ||
\`\`\` | ||
${originText} | ||
\`\`\` | ||
`) | ||
} | ||
|
||
dirs.forEach(item => { | ||
appendJSToMD(path.resolve(dirPath, item.name)) | ||
}) | ||
|
||
|
||
|
||
console.log('dir', dirInfoList); | ||
} | ||
|
||
|
||
appendJSToMD(__dirname); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.