Last active
September 15, 2023 03:57
-
-
Save icai/2e4720592b530aff4aac4cccdcfa14fc to your computer and use it in GitHub Desktop.
miniprogram pages csv with title
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
// out put current directory tree | |
const fs = require('fs') | |
const path = require('path') | |
function outPageTitle() { | |
const appjson = fs.readFileSync('./app.json', 'utf8') | |
const appjsonObj = JSON.parse(appjson) | |
const pages = appjsonObj.pages.concat( | |
...appjsonObj.subPackages.map((item) => { | |
return item.pages.map((page) => { | |
return item.root + '/' + page | |
}) | |
}) | |
) | |
pages.forEach((pagePath) => { | |
const content = fs.readFileSync(pagePath + '.json', 'utf8') | |
const json = JSON.parse(content) | |
// output defaultTitle | |
const defaultTitle = json.defaultTitle || '' | |
console.log(pagePath + ',' + defaultTitle) | |
}) | |
} | |
// out put the file path which the root directory include `pages` | |
function tree(dir, prefix = '', subfix, rootInclude = 'pages') { | |
const files = fs.readdirSync(dir) | |
files.forEach((file, index) => { | |
// if file path include `pages`, then output the file path | |
let firstDir = file.split('/')[0] | |
let rootIncludes = rootInclude.split('|') | |
if (dir == '.' && !rootIncludes.some((item) => firstDir.indexOf(item) > -1)) { | |
return | |
} | |
const filePath = path.join(dir, file) | |
const stats = fs.statSync(filePath) | |
if (stats.isDirectory()) { | |
console.log(prefix + '├── ' + file) | |
return tree(filePath, prefix + '│ ', subfix) | |
} | |
if (stats.isFile()) { | |
if (filePath.endsWith(subfix)) { | |
console.log(prefix + '├── ' + file.replace(subfix, '')) | |
} | |
} | |
}) | |
} | |
// outPageTitle() | |
// tree('.', '', '.axml', 'pages|xxxxx') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment