Skip to content

Commit c580338

Browse files
sanket143nklaymanjbolda
authored
feat(cli): add create-tauri-app (#1106)
* feat(cta): initial commit * feat(cta): define project structure * feat(cta): add create function and vanilla template * feat(cli): remove redundant line * fix(create-tauri-app): remove unused dep * chore(create-tauri-app/package): upgrade tauri * feat(create-tauri-app): use yarn if installed * chore: add minimist to parse args * feat(create-tauri-app): add recipe structure * feat(create-tauri-app): organize recipe * feat: removes installDependencies * remove notes * add change file Co-authored-by: Noah Klayman <noahklayman@gmail.com> Co-authored-by: Jacob Bolda <me@jacobbolda.com>
1 parent 4ec20a4 commit c580338

10 files changed

Lines changed: 236 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-tauri-app": minor
3+
---
4+
5+
Add vanilla javascript option to `create-tauri-app` through templating.

cli/create-tauri-app/.gitignore

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Build output
2+
/dist
3+
/api
4+
5+
6+
# Logs
7+
logs
8+
*.log
9+
npm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# node-waf configuration
29+
.lock-wscript
30+
31+
# Compiled binary addons (http://nodejs.org/api/addons.html)
32+
build/Release
33+
34+
# Dependency directories
35+
node_modules/
36+
jspm_packages/
37+
38+
# Typescript v1 declaration files
39+
typings/
40+
41+
# Optional npm cache directory
42+
.npm
43+
44+
# Optional eslint cache
45+
.eslintcache
46+
47+
# Optional REPL history
48+
.node_repl_history
49+
50+
# Output of 'npm pack'
51+
*.tgz
52+
53+
# Yarn Integrity file
54+
.yarn-integrity
55+
56+
# dotenv environment variables file
57+
.env
58+
59+
/.vs
60+
.DS_Store
61+
.Thumbs.db
62+
*.sublime*
63+
.idea/
64+
debug.log
65+
package-lock.json
66+
.vscode/settings.json

cli/create-tauri-app/bin/create-tauri-app.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,42 @@ async function runInit(argv, config = {}) {
207207
}
208208

209209
module.exports = main;
210+
211+
/* will merge these later
212+
213+
const parseArgs = require('minimist')
214+
const argv = parseArgs(process.argv.slice(2));
215+
216+
/**
217+
* @description This is the bootstrapper that in turn calls subsequent
218+
* Tauri Commands
219+
*
220+
* @param {Object} argv
221+
*
222+
const tauri = (args) => {
223+
const tauri = async (args) => {
224+
if (args["h"] || args["help"]) {
225+
require("./help.js")();
226+
return false // do this for node consumers and tests
227+
}
228+
229+
if(args["v"] || args["version"]){
230+
console.log(require("../package.json").version)
231+
return false // do this for node consumers and tests
232+
}
233+
234+
if(args["_"].length === 1){
235+
await require("./create.js")(args)
236+
}
237+
else if(args["_"].length > 1){
238+
console.log("ERR: Too many arguments.")
239+
} else {
240+
require("./help.js")();
241+
return false // do this for node consumers and tests
242+
}
243+
}
244+
245+
tauri(argv).catch(err => {
246+
console.log(err)
247+
})
248+
*/

cli/create-tauri-app/bin/create.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const recipes = require("../src/recipes");
2+
3+
module.exports = async (args) => {
4+
await recipes(args);
5+
}

cli/create-tauri-app/bin/help.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = () => {
2+
console.log(`create-tauri-app v0.1.0
3+
4+
Usage
5+
$ yarn create tauri-app <app-name> # npm create-tauri-app <app-name>
6+
Options
7+
-v, --version displays the Tauri CLI version
8+
--recipe <recipe-name> add that framework boilderplate (react|vue|svelte|none) (defaults to none)
9+
-f, --force force on non-empty directory
10+
-h, --help displays this message
11+
`);
12+
}

cli/create-tauri-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
},
1616
"homepage": "https://github.com/tauri-apps/tauri#readme",
1717
"dependencies": {
18+
"execa": "^5.0.0",
1819
"minimist": "^1.2.5",
1920
"scaffe": "^0.1.5",
2021
"tauri": "^0.14.0"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
4+
const applyRecipe = async (args) => {
5+
if(args["recipe"]){
6+
const filename = `./${args["recipe"]}.js`;
7+
const filepath = path.join(__dirname, filename);
8+
9+
if(fs.existsSync(filepath)){
10+
return require(filename)(args);
11+
} else {
12+
console.log("No such recipe for Tauri.");
13+
process.exit(1);
14+
15+
return false;
16+
}
17+
} else {
18+
console.log("Using default `vanilla` recipe.")
19+
20+
return await require("./vanilla")(args);;
21+
}
22+
}
23+
24+
module.exports = async (args) => {
25+
const { output } = await applyRecipe(args)
26+
console.log(output)
27+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const path = require("path");
2+
const scaffe = require("scaffe");
3+
const init = require("tauri/dist/api/init");
4+
const { version } = require("tauri/package.json");
5+
6+
module.exports = (args) => {
7+
return new Promise((resolve, reject) => {
8+
const appName = args["_"][0];
9+
const templateDir = path.join(__dirname, "../templates/vanilla");
10+
const variables = {
11+
name: appName,
12+
tauri_version: version
13+
}
14+
15+
scaffe.generate(templateDir, appName, variables, async (err) => {
16+
if(err){
17+
reject(err);
18+
}
19+
20+
init({
21+
directory: appName,
22+
force: args.f || null,
23+
logging: args.l || null,
24+
tauriPath: args.t || null,
25+
appName: appName || args.A || null,
26+
customConfig: {
27+
tauri: {
28+
window: {
29+
title: appName,
30+
},
31+
},
32+
build: {
33+
devPath: "../dist",
34+
distDir: "../dist",
35+
},
36+
},
37+
});
38+
39+
resolve({
40+
output: `
41+
change directory:
42+
$ cd ${appName}
43+
44+
install dependencies:
45+
$ yarn # npm install
46+
47+
run the app:
48+
$ yarn tauri dev # npm run tauri dev
49+
`,
50+
});
51+
})
52+
})
53+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "<%= name %>",
3+
"scripts": {
4+
"tauri": "tauri"
5+
},
6+
"dependencies": {
7+
"tauri": "<%= tauri_version %>"
8+
}
9+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<style>
3+
html, body {
4+
margin: 0;
5+
padding: 0;
6+
width: 100%;
7+
height: 100%;
8+
}
9+
10+
body {
11+
display: flex;
12+
align-items: center;
13+
justify-content: center;
14+
}
15+
</style>
16+
<body>
17+
<h1><%= name %></h1>
18+
</body>
19+
</html>

0 commit comments

Comments
 (0)