-
-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add template for typescript (#1319)
- Loading branch information
1 parent
371a068
commit cece7da
Showing
11 changed files
with
197 additions
and
6 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
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ dist | |
node_modules | ||
*.d.ts | ||
packages/*/*/index.ts | ||
tmpl |
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
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
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
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,21 @@ | ||
{ | ||
"name": "@electron-forge/template-typescript", | ||
"version": "6.0.0-beta.46", | ||
"description": "Typescript template for Electron Forge, gets you started with TypeScript really quickly", | ||
"repository": "https://github.com/electron-userland/electron-forge", | ||
"author": "Shelley Vohr <shelley.vohr@gmail.com>", | ||
"license": "MIT", | ||
"main": "dist/TypeScriptTemplate.js", | ||
"typings": "dist/TypeScriptTemplate.d.ts", | ||
"scripts": { | ||
"test": "echo No Tests" | ||
}, | ||
"engines": { | ||
"node": ">= 8.0" | ||
}, | ||
"dependencies": { | ||
"@electron-forge/async-ora": "6.0.0-beta.46", | ||
"@electron-forge/shared-types": "6.0.0-beta.46", | ||
"fs-extra": "^8.1.0" | ||
} | ||
} |
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,46 @@ | ||
import { ForgeTemplate } from '@electron-forge/shared-types'; | ||
import { asyncOra } from '@electron-forge/async-ora'; | ||
|
||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
|
||
const copyTemplateFile = async (destDir: string, basename: string) => { | ||
const templateDir = path.resolve(__dirname, '..', 'tmpl'); | ||
await fs.copy(path.join(templateDir, basename), path.resolve(destDir, basename)); | ||
}; | ||
|
||
class TypeScriptTemplate implements ForgeTemplate { | ||
public devDependencies = [ | ||
'typescript@^3.7.0', | ||
'tslint@^5.20.0', | ||
]; | ||
|
||
public initializeTemplate = async (directory: string) => { | ||
await asyncOra('Setting up Forge configuration', async () => { | ||
const packageJSONPath = path.resolve(directory, 'package.json'); | ||
const packageJSON = await fs.readJson(packageJSONPath); | ||
|
||
// Configure scripts for TS template | ||
packageJSON.scripts.lint = 'tslint -c tslint.json -p tsconfig.json'; | ||
packageJSON.scripts.start = 'tsc && electron-forge start -p dist'; | ||
|
||
await fs.writeJson(packageJSONPath, packageJSON, { spaces: 2 }); | ||
}); | ||
|
||
await asyncOra('Setting up TypeScript configuration', async () => { | ||
const filePath = (fileName: string) => path.join(directory, 'src', fileName); | ||
|
||
// Copy tsconfig with a small set of presets | ||
await copyTemplateFile(directory, 'tsconfig.json'); | ||
|
||
// Copy tslint config with recommended settings | ||
await copyTemplateFile(directory, 'tslint.json'); | ||
|
||
// Remove index.js and replace with index.ts | ||
await fs.remove(filePath('index.js')); | ||
await copyTemplateFile(path.join(directory, 'src'), 'index.ts'); | ||
}); | ||
} | ||
} | ||
|
||
export default new TypeScriptTemplate(); |
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,58 @@ | ||
import { app, BrowserWindow } from 'electron'; | ||
import * as path from 'path'; | ||
|
||
// Handle creating/removing shortcuts on Windows when installing/uninstalling. | ||
if (require('electron-squirrel-startup')) { // eslint-disable-line global-require | ||
app.quit(); | ||
} | ||
|
||
// Keep a global reference of the window object, if you don't, the window will | ||
// be closed automatically when the JavaScript object is garbage collected. | ||
let mainWindow: Electron.BrowserWindow; | ||
|
||
const createWindow = () => { | ||
// Create the browser window. | ||
mainWindow = new BrowserWindow({ | ||
width: 800, | ||
height: 600, | ||
}); | ||
|
||
// and load the index.html of the app. | ||
mainWindow.loadFile(path.join(__dirname, "../src/index.html")); | ||
|
||
// Open the DevTools. | ||
mainWindow.webContents.openDevTools(); | ||
|
||
// Emitted when the window is closed. | ||
mainWindow.on('closed', () => { | ||
// Dereference the window object, usually you would store windows | ||
// in an array if your app supports multi windows, this is the time | ||
// when you should delete the corresponding element. | ||
mainWindow = null; | ||
}); | ||
}; | ||
|
||
// This method will be called when Electron has finished | ||
// initialization and is ready to create browser windows. | ||
// Some APIs can only be used after this event occurs. | ||
app.on('ready', createWindow); | ||
|
||
// Quit when all windows are closed. | ||
app.on('window-all-closed', () => { | ||
// On OS X it is common for applications and their menu bar | ||
// to stay active until the user quits explicitly with Cmd + Q | ||
if (process.platform !== 'darwin') { | ||
app.quit(); | ||
} | ||
}); | ||
|
||
app.on('activate', () => { | ||
// On OS X it's common to re-create a window in the app when the | ||
// dock icon is clicked and there are no other windows open. | ||
if (mainWindow === null) { | ||
createWindow(); | ||
} | ||
}); | ||
|
||
// In this file you can include the rest of your app's specific main process | ||
// code. You can also put them in separate files and import them here. |
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,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"module": "commonjs", | ||
"noImplicitAny": true, | ||
"sourceMap": true, | ||
"baseUrl": ".", | ||
"outDir": "dist", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"paths": { | ||
"*": ["node_modules/*"] | ||
} | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
] | ||
} |
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,9 @@ | ||
{ | ||
"defaultSeverity": "error", | ||
"extends": [ | ||
"tslint:latest" | ||
], | ||
"jsRules": {}, | ||
"rules": {}, | ||
"rulesDirectory": [] | ||
} |
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