-
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.
* Setup project * pre-commit hook & fix lint/prettier commands * changeset
- Loading branch information
1 parent
fd00b74
commit dc7c62d
Showing
63 changed files
with
11,387 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,8 @@ | ||
# Changesets | ||
|
||
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works | ||
with multi-package repos, or single-package repos to help you version and publish your code. You can | ||
find the full documentation for it [in our repository](https://github.com/changesets/changesets) | ||
|
||
We have a quick list of common questions to get you started engaging with this project in | ||
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) |
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,11 @@ | ||
{ | ||
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
"changelog": "@changesets/cli/changelog", | ||
"commit": false, | ||
"fixed": [], | ||
"linked": [], | ||
"access": "restricted", | ||
"baseBranch": "main", | ||
"updateInternalDependencies": "patch", | ||
"ignore": [] | ||
} |
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,5 @@ | ||
--- | ||
"@osrs-wiki/mediawiki-builder": minor | ||
--- | ||
|
||
Project setup |
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,29 @@ | ||
module.exports = { | ||
parser: "@typescript-eslint/parser", | ||
extends: [ | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:import/recommended", | ||
"prettier", | ||
], | ||
rules: { | ||
"import/namespace": "off", | ||
"import/no-unresolved": "off", | ||
"import/order": [ | ||
"warn", | ||
{ | ||
"alphabetize": { | ||
order: "asc", | ||
caseInsensitive: true, | ||
}, | ||
"groups": [ | ||
["builtin", "external"], | ||
"internal", | ||
["sibling", "parent", "index"], | ||
"object", | ||
], | ||
"newlines-between": "always", | ||
"pathGroupsExcludedImportTypes": ["builtin"], | ||
}, | ||
], | ||
}, | ||
}; |
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,27 @@ | ||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
lint_build_test: | ||
name: "Lint, Built, & Test" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out Git repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 18.x | ||
|
||
- name: Install dependencies | ||
run: yarn install --frozen-lockfile | ||
|
||
- name: Lint | ||
run: yarn lint | ||
|
||
- name: Build | ||
run: yarn build | ||
|
||
- name: Test | ||
run: yarn test |
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,28 @@ | ||
name: Pull Request | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
test_for_changeset: | ||
runs-on: ubuntu-latest | ||
if: github.head_ref != 'changeset-release/main' | ||
name: Test for presence of new Changeset files | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Get .changeset changes | ||
id: changeset-files | ||
uses: tj-actions/changed-files@v35 | ||
with: | ||
files: .changeset/*.md | ||
|
||
- name: Check for added files | ||
id: changeset-check-added | ||
run: | | ||
echo "Valid PRs must have a new changeset file." | ||
test -n "${{ steps.changeset-files.outputs.added_files }}" | ||
lint_build_test: | ||
name: "Lint, Built, & Test" | ||
uses: ./.github/workflows/action-lint-build-test.yml |
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,42 @@ | ||
name: Push Main | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
lint_build_test: | ||
name: "Lint, Built, & Test" | ||
uses: ./.github/workflows/action-lint-build-test.yml | ||
secrets: inherit | ||
|
||
changeset: | ||
name: "Changeset" | ||
needs: lint_build_test | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Use Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
always-auth: true | ||
cache: yarn | ||
node-version: 18 | ||
|
||
- name: Install yarn packages | ||
run: yarn install --frozen-lockfile | ||
|
||
- name: Create Release Pull Request or Release | ||
id: changeset | ||
uses: changesets/action@v1 | ||
with: | ||
publish: yarn release | ||
title: Version Release | ||
commit: Version Release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PUBLISH_PACKAGES }} |
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,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
yarn lint-staged |
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,3 @@ | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
} |
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,5 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
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,66 @@ | ||
{ | ||
"name": "@osrs-wiki/mediawiki-builder", | ||
"version": "1.0.0", | ||
"description": "A tool set for building MediaWiki content with TypeScript, specifically targeting the OSRS Wiki.", | ||
"author": "Allen Kinzalow <[email protected]>", | ||
"license": "GPL-3.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/osrs-wiki/mediawiki-builder.git" | ||
}, | ||
"scripts": { | ||
"build": "rm -rf ./dist && tsdx build --tsconfig tsconfig.build.json", | ||
"lint": "eslint src/**/*.ts", | ||
"lint:fix": "yarn lint --fix", | ||
"prettier": "prettier src/**/*.ts", | ||
"prettier:fix": "yarn prettier --write", | ||
"start": "tsdx watch --tsconfig tsconfig.build.json --verbose --noClean", | ||
"test": "jest", | ||
"prepublish": "yarn build", | ||
"changeset": "changeset", | ||
"release": "changeset publish", | ||
"version:canary": "changeset version --snapshot canary", | ||
"release:canary": "changeset publish --tag canary", | ||
"prepare": "husky install" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/osrs-wiki/mediawiki-builder/issues" | ||
}, | ||
"homepage": "https://github.com/osrs-wiki/mediawiki-builder#readme", | ||
"main": "dist/index.js", | ||
"module": "dist/mediawiki-builder.esm.js", | ||
"typings": "dist/index.d.ts", | ||
"files": [ | ||
"README.md", | ||
"dist" | ||
], | ||
"dependencies": { | ||
"tslib": "^2.6.2" | ||
}, | ||
"devDependencies": { | ||
"@babel/eslint-parser": "^7.21.3", | ||
"@changesets/changelog-github": "^0.5.0", | ||
"@changesets/cli": "^2.27.1", | ||
"@types/jest": "^28.1.7", | ||
"@typescript-eslint/eslint-plugin": "^5.59.1", | ||
"@typescript-eslint/parser": "^5.59.1", | ||
"eslint": "^8.39.0", | ||
"eslint-config-prettier": "^8.8.0", | ||
"eslint-plugin-flowtype": "^8.0.3", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-jsx-a11y": "^6.6.0", | ||
"husky": "^7.0.4", | ||
"jest": "^28.1.2", | ||
"lint-staged": "^12.4.0", | ||
"prettier": "^2.8.8", | ||
"ts-jest": "^29.1.2", | ||
"tsdx": "^0.14.1", | ||
"typescript": "^4.6.3" | ||
}, | ||
"lint-staged": { | ||
"src/**/*.{js,ts}": [ | ||
"yarn lint:fix", | ||
"yarn prettier:fix" | ||
] | ||
} | ||
} |
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,24 @@ | ||
module.exports = { | ||
arrowParens: "always", | ||
bracketSameLine: false, | ||
bracketSpacing: true, | ||
cursorOffset: -1, | ||
embeddedLanguageFormatting: "auto", | ||
endOfLine: "lf", | ||
htmlWhitespaceSensitivity: "css", | ||
insertPragma: false, | ||
jsxSingleQuote: false, | ||
pluginSearchDirs: [], | ||
plugins: [], | ||
printWidth: 80, | ||
proseWrap: "preserve", | ||
quoteProps: "consistent", | ||
rangeEnd: Infinity, | ||
rangeStart: 0, | ||
requirePragma: false, | ||
semi: true, | ||
singleQuote: false, | ||
tabWidth: 2, | ||
trailingComma: "es5", | ||
useTabs: false, | ||
}; |
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,45 @@ | ||
import MediaWikiContent from "./content"; | ||
import MediaWikiTransformer from "./transformer"; | ||
|
||
class MediaWikiBuilder { | ||
content: MediaWikiContent[]; | ||
transformers: MediaWikiTransformer[]; | ||
|
||
constructor() { | ||
this.content = []; | ||
this.transformers = []; | ||
} | ||
|
||
build() { | ||
this.transformers.forEach((transformer) => { | ||
this.content = transformer.transform(this.content); | ||
}); | ||
const final = | ||
this.content?.reduce( | ||
(value, content) => (content ? value + "" + content.build() : value), | ||
"" | ||
) ?? ""; | ||
return final; | ||
} | ||
|
||
addContent(content: MediaWikiContent): MediaWikiBuilder { | ||
if (content !== null && content !== undefined) { | ||
this.content.push(content); | ||
} | ||
return this; | ||
} | ||
|
||
addContents(contents: MediaWikiContent[]): MediaWikiBuilder { | ||
this.content = this.content.concat( | ||
contents.filter((content) => content !== undefined && content !== null) | ||
); | ||
return this; | ||
} | ||
|
||
addTransformer(transformer: MediaWikiTransformer): MediaWikiBuilder { | ||
this.transformers.push(transformer); | ||
return this; | ||
} | ||
} | ||
|
||
export default MediaWikiBuilder; |
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,25 @@ | ||
abstract class MediaWikiContent { | ||
children?: MediaWikiContent | MediaWikiContent[]; | ||
|
||
constructor(children?: MediaWikiContent | MediaWikiContent[]) { | ||
this.children = children; | ||
} | ||
|
||
abstract build(): string; | ||
|
||
buildChildren(): string { | ||
if (this.children && Array.isArray(this.children)) { | ||
return ( | ||
this.children?.reduce( | ||
(value, content) => (content ? value + "" + content.build() : value), | ||
"" | ||
) ?? "" | ||
); | ||
} else if (this.children && this.children instanceof MediaWikiContent) { | ||
return this.children.build(); | ||
} | ||
return ""; | ||
} | ||
} | ||
|
||
export default MediaWikiContent; |
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,8 @@ | ||
import MediaWikiBreak from "../break"; | ||
|
||
describe("MediaWikiBreak", () => { | ||
test("it should build correctly", () => { | ||
const result = new MediaWikiBreak(); | ||
expect(result.build()).toBe("\n"); | ||
}); | ||
}); |
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,8 @@ | ||
import MediaWikiComment from "../comment"; | ||
|
||
describe("MediaWikiComment", () => { | ||
test("it should build correctly", () => { | ||
const result = new MediaWikiComment("test"); | ||
expect(result.build()).toBe("<!-- test -->"); | ||
}); | ||
}); |
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,8 @@ | ||
import MediaWikiExternalLink from "../externalLink"; | ||
|
||
describe("MediaWikiExternalLink", () => { | ||
test("it should build correctly", () => { | ||
const result = new MediaWikiExternalLink("test", "https://test.com"); | ||
expect(result.build()).toBe("[https://test.com test]"); | ||
}); | ||
}); |
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,29 @@ | ||
import MediaWikiHeader from "../header"; | ||
import MediaWikiText from "../text"; | ||
|
||
describe("MediaWikiHeader", () => { | ||
test("it should build correctly with a string value", () => { | ||
const header = new MediaWikiHeader("Test", 2); | ||
expect(header.build()).toBe("==Test=="); | ||
}); | ||
|
||
test("it should build correctly with a non-array MediaWikiContent", () => { | ||
const header = new MediaWikiHeader( | ||
new MediaWikiText("Test", { italics: true }), | ||
2 | ||
); | ||
expect(header.build()).toBe("==''Test''=="); | ||
}); | ||
|
||
test("it should build correctly with an array of MediaWikiContent", () => { | ||
const header = new MediaWikiHeader( | ||
[ | ||
new MediaWikiText("Start "), | ||
new MediaWikiText("Test", { italics: true }), | ||
new MediaWikiText(" End"), | ||
], | ||
3 | ||
); | ||
expect(header.build()).toBe("===Start ''Test'' End==="); | ||
}); | ||
}); |
Oops, something went wrong.