mirror of
https://github.com/insin/control-panel-for-twitter.git
synced 2025-06-19 07:05:32 -04:00

- All page script settings are now stored in a single settings object - All other top-level config is for extension-internal settings - Renamed old settings which were marked with comments in types.d.ts Background script - Open welcome (new installs) or updated (v4 → v5) page post-install - Migrate v4 user settings to new v5 format on update Page script: - Removed userscript pragma - Renamed page script config variable to 'settings' Scripts: - Moved utility and script API functions to lib.js - Updated copy script to copy all *.mv*.* files in the root dir - Added a clean script and command to remove files which correspond to a *.mv*.* file
61 lines
1.4 KiB
JavaScript
61 lines
1.4 KiB
JavaScript
const fs = require('fs')
|
|
|
|
/**
|
|
* @param {{dryRun?: boolean}} [options]
|
|
*/
|
|
function clean(options = {}) {
|
|
let {dryRun = false} = options
|
|
let mvFileRegExp = /\.mv[23]\./
|
|
|
|
for (let file of fs.readdirSync('.', {withFileTypes: true})) {
|
|
if (file.isDirectory() || !mvFileRegExp.test(file.name)) continue
|
|
|
|
let copiedFile = file.name.replace(mvFileRegExp, '.')
|
|
if (fs.existsSync(copiedFile)) {
|
|
if (dryRun) {
|
|
console.log(`rm ${copiedFile}`)
|
|
} else {
|
|
fs.rmSync(copiedFile)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param {import('./types').ManifestVersion} manifestVersion
|
|
* @param {{dryRun?: boolean}} [options]
|
|
*/
|
|
function copy(manifestVersion, options = {}) {
|
|
let {dryRun = false} = options
|
|
let mvFileRegExp = new RegExp(`\\.mv${manifestVersion}\\.`)
|
|
|
|
for (let file of fs.readdirSync('.', {withFileTypes: true})) {
|
|
if (file.isDirectory() || !mvFileRegExp.test(file.name)) continue
|
|
|
|
let copyTo = file.name.replace(mvFileRegExp, '.')
|
|
if (dryRun) {
|
|
console.log(`copy ${file.name} → ${copyTo}`)
|
|
} else {
|
|
fs.copyFileSync(file.name, copyTo)
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param {Record<string, any>} locale
|
|
*/
|
|
function sortProperties(locale) {
|
|
let entries = Object.entries(locale)
|
|
entries.sort(([a], [b]) => {
|
|
if (a < b) return -1
|
|
if (a > b) return 1
|
|
return 0
|
|
})
|
|
return Object.fromEntries(entries)
|
|
}
|
|
|
|
module.exports = {
|
|
clean,
|
|
copy,
|
|
sortProperties,
|
|
} |