-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
2320088
commit 866cdee
Showing
3 changed files
with
152 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const fs = require( 'fs/promises' ); | ||
const path = require( 'path' ); | ||
|
||
/** | ||
* Generates `util` and `mw/util` indices. | ||
*/ | ||
( async () => { | ||
|
||
/** | ||
* | ||
* @param subpath | ||
*/ | ||
async function genIndex( subpath ) { | ||
const utilPath = path.join( process.cwd(), 'src', subpath ); | ||
const modules = []; | ||
const hasNoDefault = []; | ||
|
||
const dir = ( await fs.opendir( utilPath ) ); | ||
for await ( const fse of dir ) { | ||
const moduleName = fse.name.replace( /\.ts$/, '' ); | ||
|
||
if ( fse.isFile() && fse.name !== 'index.ts' ) { | ||
modules.push( moduleName ); | ||
if ( | ||
!( await fs.readFile( path.join( utilPath, fse.name ) ) ) | ||
.toString( 'utf8' ) | ||
.includes( 'export default' ) | ||
) { | ||
hasNoDefault.push( moduleName ); | ||
} | ||
} | ||
} | ||
|
||
await fs.writeFile( | ||
path.join( utilPath, 'index.ts' ), | ||
modules | ||
.map( v => `import ${ | ||
hasNoDefault.includes( v ) ? `* as ${v}` : v | ||
} from './${v}';` ) | ||
.join( '\n' ) + | ||
'\n' + | ||
'export default {\n' + | ||
modules | ||
.map( ( v, i ) => `\t${v}: ${v}` + ( i === modules.length - 1 ? '' : ',' ) ) | ||
.join( '\n' ) + '\n' + | ||
'};\n' | ||
); | ||
} | ||
|
||
try { | ||
await genIndex( 'util' ); | ||
} catch ( e ) { | ||
console.error( 'Failed to generate indices for src/util.', e ); | ||
} | ||
|
||
try { | ||
await genIndex( 'wiki/util' ); | ||
} catch ( e ) { | ||
console.error( 'Failed to generate indices for src/wiki/util.', e ); | ||
} | ||
|
||
} )(); |
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,40 @@ | ||
import * as blockExit from './blockExit'; | ||
import classMix from './classMix'; | ||
import cleanParams from './cleanParams'; | ||
import cloneRegex from './cloneRegex'; | ||
import copyToClipboard from './copyToClipboard'; | ||
import equalTitle from './equalTitle'; | ||
import fromObjectEntries from './fromObjectEntries'; | ||
import generateId from './generateId'; | ||
import getObjectValues from './getObjectValues'; | ||
import last from './last'; | ||
import matchAll from './matchAll'; | ||
import moveToStart from './moveToStart'; | ||
import pickSequence from './pickSequence'; | ||
import removeElement from './removeElement'; | ||
import Requester from './Requester'; | ||
import sleep from './sleep'; | ||
import swapElements from './swapElements'; | ||
import unwrapWidget from './unwrapWidget'; | ||
import yesNo from './yesNo'; | ||
export default { | ||
blockExit: blockExit, | ||
classMix: classMix, | ||
cleanParams: cleanParams, | ||
cloneRegex: cloneRegex, | ||
copyToClipboard: copyToClipboard, | ||
equalTitle: equalTitle, | ||
fromObjectEntries: fromObjectEntries, | ||
generateId: generateId, | ||
getObjectValues: getObjectValues, | ||
last: last, | ||
matchAll: matchAll, | ||
moveToStart: moveToStart, | ||
pickSequence: pickSequence, | ||
removeElement: removeElement, | ||
Requester: Requester, | ||
sleep: sleep, | ||
swapElements: swapElements, | ||
unwrapWidget: unwrapWidget, | ||
yesNo: yesNo | ||
}; |
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,50 @@ | ||
import anchorToTitle from './anchorToTitle'; | ||
import decorateEditSummary from './decorateEditSummary'; | ||
import delink from './delink'; | ||
import errorToOO from './errorToOO'; | ||
import getNativeRange from './getNativeRange'; | ||
import getPageContent from './getPageContent'; | ||
import getPageTitle from './getPageTitle'; | ||
import getRevisionContent from './getRevisionContent'; | ||
import getRevisionDiffURL from './getRevisionDiffURL'; | ||
import getRevisionURL from './getRevisionURL'; | ||
import getSectionHTML from './getSectionHTML'; | ||
import getSectionId from './getSectionId'; | ||
import guessAuthor from './guessAuthor'; | ||
import msgEval from './msgEval'; | ||
import normalizeTitle from './normalizeTitle'; | ||
import nsId from './nsId'; | ||
import openWindow from './openWindow'; | ||
import performHacks from './performHacks'; | ||
import purge from './purge'; | ||
import renderWikitext from './renderWikitext'; | ||
import sectionHeadingId from './sectionHeadingId'; | ||
import sectionHeadingN from './sectionHeadingN'; | ||
import sectionHeadingName from './sectionHeadingName'; | ||
import toRedirectsObject from './toRedirectsObject'; | ||
export default { | ||
anchorToTitle: anchorToTitle, | ||
decorateEditSummary: decorateEditSummary, | ||
delink: delink, | ||
errorToOO: errorToOO, | ||
getNativeRange: getNativeRange, | ||
getPageContent: getPageContent, | ||
getPageTitle: getPageTitle, | ||
getRevisionContent: getRevisionContent, | ||
getRevisionDiffURL: getRevisionDiffURL, | ||
getRevisionURL: getRevisionURL, | ||
getSectionHTML: getSectionHTML, | ||
getSectionId: getSectionId, | ||
guessAuthor: guessAuthor, | ||
msgEval: msgEval, | ||
normalizeTitle: normalizeTitle, | ||
nsId: nsId, | ||
openWindow: openWindow, | ||
performHacks: performHacks, | ||
purge: purge, | ||
renderWikitext: renderWikitext, | ||
sectionHeadingId: sectionHeadingId, | ||
sectionHeadingN: sectionHeadingN, | ||
sectionHeadingName: sectionHeadingName, | ||
toRedirectsObject: toRedirectsObject | ||
}; |