Skip to content

Commit

Permalink
feat: add electron templates
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgao365 committed Jun 4, 2024
1 parent 80fc90f commit d930ce5
Show file tree
Hide file tree
Showing 44 changed files with 948 additions and 77 deletions.
72 changes: 37 additions & 35 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ const PKG_FIELDS = [
'optionalDependencies',
];

const PKG_SCRIPTS = [
'dev',
'dev:*',
'debug',
'start',
'build',
'build:*',
'release',
'clean',
'preview',
'test',
'lint',
'lint:eslint',
'lint:stylelint',
'lint:prettier',
];

async function getGitInfo(name: string) {
return run(`git config --get ${name}`, { trim: true });
}
Expand Down Expand Up @@ -291,24 +308,7 @@ function handleFinalPkg(pkg: PackageJson, appType: AppType, variant: FrameworkVa
return;
}
if (key === 'scripts') {
pkg[key] = sortObjectKeys(
pkg[key],
[
'dev',
'dev:*',
'debug',
'start',
'build',
'build:*',
'preview',
'test',
'lint',
'lint:eslint',
'lint:stylelint',
'lint:prettier',
],
['prepare'],
);
pkg[key] = sortObjectKeys(pkg[key], PKG_SCRIPTS, ['prepare']);
} else {
pkg[key] = sortObjectKeys(pkg[key]);
}
Expand Down Expand Up @@ -567,23 +567,25 @@ async function getUserVariant(appType: AppType, rootDir: string, template?: stri
} else if (appType === 'package') {
variant.workspaces = false;
} else {
gitUserUrl = await askList(
`Which git repository to publish to?`,
gitRepos
.map(repo => {
const url = getGitUserUrl(repo);
return {
name: url,
value: url,
};
})
.concat([
{
name: chalk.yellow('None'),
value: '',
},
]),
);
if (variant.git) {
gitUserUrl = await askList(
`Which git repository do you want to choose?`,
gitRepos
.map(repo => {
const url = getGitUserUrl(repo);
return {
name: url,
value: url,
};
})
.concat([
{
name: chalk.yellow('None'),
value: '',
},
]),
);
}
}

if (variant.devDependencies === 2) {
Expand Down
2 changes: 1 addition & 1 deletion src/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function saveOrUpdateGitRepoPrompt(git?: GitRepo): Promise<GitRepo> {
{
type: 'text',
name: 'owner',
message: `${git?.owner ? 'Edit' : 'Add '} git repository owner:`,
message: `${git?.owner ? 'Edit' : 'Add'} git repository owner:`,
default: git?.owner || defaultGitRepo.owner,
},
]);
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,6 @@ export type FrameworkVariant = {
workspaces?: boolean;
test?: boolean;
devDependencies?: 0 | 1 | 2;
git?: 0 | 1 | 2;
userOptions: UserOptions;
};
17 changes: 0 additions & 17 deletions templates/base/electron/electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,6 @@ function createWindow() {

app.whenReady().then(async () => {
createWindow();

if (isDev) {
const { installExtension, REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS } = await import(
'@tomjs/electron-devtools-installer'
);

installExtension([REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS])
.then(exts => {
console.log(
'Added Extension: ',
exts.map(s => s.name),
);
})
.catch(() => {
console.log('Failed to install extensions');
});
}
});

app.on('window-all-closed', () => {
Expand Down
26 changes: 25 additions & 1 deletion templates/base/electron/package.json
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
{}
{
"type": "module",
"engines": {
"node": ">=18"
},
"main": "dist/main/index.mjs",
"scripts": {
"dev": "vite",
"debug": "cross-env VITE_ELECTRON_DEBUG=1 npm run dev",
"build": "npm run clean && vite build",
"release": "cross-env VITE_ELECTRON_BUILDER=1 npm run build",
"clean": "rimraf ./dist",
"lint:eslint": "eslint \"{src,electron}/**/*.{ts,tsx}\" *.{js,cjs,mjs,ts} --fix --cache"
},
"dependencies": {
"@tomjs/electron-devtools-installer": "^2.2.1"
},
"devDependencies": {
"@tomjs/vite-plugin-electron": "^1.9.0",
"electron": "^30.0.9",
"electron-builder": "^24.13.3",
"vite": "^5.2.12",
"vite-plugin-electron-renderer": "^0.14.5"
}
}
7 changes: 7 additions & 0 deletions templates/base/electron/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "@tomjs/tsconfig/node.json",
"compilerOptions": {
"composite": true
},
"include": ["electron", "package.json", "vite.config.ts"]
}
3 changes: 1 addition & 2 deletions templates/base/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"build": "tsc && vite build",
"preview": "vite preview",
"lint": "run-s lint:eslint lint:stylelint lint:prettier",
"lint:eslint": "eslint \"src/**/*.{ts,tsx}\" *.{js,cjs,mjs,ts} --fix --cache",
"lint:stylelint": "stylelint \"src/**/*.{css,less,scss,html}\" *.html --fix --cache"
"lint:eslint": "eslint \"src/**/*.{ts,tsx}\" *.{js,cjs,mjs,ts} --fix --cache"
},
"dependencies": {
"react": "^18.3.1",
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions templates/base/style/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"scripts": {
"lint": "run-s lint:eslint lint:stylelint lint:prettier",
"lint:stylelint": "stylelint \"src/**/*.{css,less,scss,html}\" *.html --fix --cache"
},
"devDependencies": {
Expand Down
10 changes: 0 additions & 10 deletions templates/base/vscode/tsconfig.json

This file was deleted.

3 changes: 1 addition & 2 deletions templates/base/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
"preview": "vite preview",
"lint": "run-s lint:eslint lint:stylelint lint:prettier",
"lint:eslint": "eslint \"src/**/*.{ts,tsx,vue}\" *.{js,cjs,mjs,ts} --fix --cache",
"lint:stylelint": "stylelint \"src/**/*.{css,less,scss,html,vue}\" *.html --fix --cache"
},
"dependencies": {
"vue": "^3.4.27"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.0.4",
"@vitejs/plugin-vue": "^5.0.5",
"vite": "^5.2.12",
"vue-tsc": "^2.0.19"
}
Expand Down
File renamed without changes.
File renamed without changes.
19 changes: 12 additions & 7 deletions templates/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@
"display": "Node Base",
"templates": ["base/node"],
"devDependencies": 2,
"test": true
"test": true,
"git": 2
},
{
"name": "node-cli",
"display": "Node CLI",
"templates": ["base/node"],
"devDependencies": 1,
"test": true
"test": true,
"git": 2
},
{
"name": "node-cli-legacy",
"display": "Node CLI (Legacy)",
"templates": ["base/node"],
"devDependencies": 1,
"test": true
"test": true,
"git": 2
},
{
"name": "node-vite-plugin",
Expand All @@ -33,14 +36,16 @@
"examples": ["vue", "react"],
"devDependencies": 1,
"types": ["project", "package"],
"test": true
"test": true,
"git": 2
},
{
"name": "node-workspaces",
"display": "Node Workspace",
"templates": ["base/node"],
"workspaces": true,
"test": true
"test": true,
"git": 2
}
]
},
Expand All @@ -67,12 +72,12 @@
{
"name": "electron-vue",
"display": "Vue",
"templates": ["base/vue", "base/electron"]
"templates": ["base/style", "base/vue", "base/electron"]
},
{
"name": "electron-react",
"display": "React",
"templates": ["base/react", "base/electron"]
"templates": ["base/style", "base/react", "base/electron"]
}
]
},
Expand Down
3 changes: 3 additions & 0 deletions templates/electron-react/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# electron-react

vite + electron + react
Loading

0 comments on commit d930ce5

Please sign in to comment.