Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Commit

Permalink
feat(TypeScript): Generate TS declarations & export theme names
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-ketch committed Aug 30, 2019
1 parent 817d2c8 commit be71bd0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"main": "./dist/index.js",
"scripts": {
"dev": "parcel ./src/demo/index.html --open",
"build": "parcel build ./src/**/*.css ./src/**/*.ts",
"build": "parcel build ./src/**/*.css ./src/**/*.ts && tsc --emitDeclarationOnly",
"watch": "parcel watch ./src/**/*.css ./src/**/*.ts",
"pages": "parcel build ./src/demo/index.html -d pages --public-url .",
"semantic-release": "semantic-release"
Expand All @@ -33,6 +33,7 @@
"@abide-community/parcel-plugin-clean-out-dir": "^1.0.0",
"@babel/core": "^7.5.5",
"@stencila/dev-config": "^1.1.2",
"@types/prismjs": "^1.16.0",
"autoprefixer": "^9.6.1",
"normalize.css": "^8.0.1",
"parcel-bundler": "^1.12.3",
Expand Down
26 changes: 22 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
export const themes = {
eLife: 'themes/eLife',
nature: 'themes/nature',
plos: 'themes/plos',
stencila: 'themes/stencila'
elife: 'eLife' as const,
nature: 'nature' as const,
plos: 'plos' as const,
stencila: 'stencila' as const
}

type Themes = typeof themes
export type ThemeNames = Themes[keyof Themes]

export const themePath = 'dist/themes'

const themeNameGuard = (s: string): s is keyof Themes =>
s.toLowerCase() in themes

/**
* Given a string, will attempt to return a matching Thema theme, falling back to Stencila in case none is found
* @param {string} name Name of the theme to look for
*/
export const getTheme = (name?: string): ThemeNames => {
return name !== undefined && themeNameGuard(name)
? themes[name]
: themes.stencila
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"include": ["src"],
"exclude": ["node_modules"],
"compilerOptions": {
"outDir": "dist",
"lib": ["dom", "es2017"]
}
}

0 comments on commit be71bd0

Please sign in to comment.