Skip to content

Commit

Permalink
Merge pull request #217 from drashland/issue-#182-create-app-script
Browse files Browse the repository at this point in the history
Issue #182 create app script
  • Loading branch information
crookse authored May 25, 2020
2 parents a34e401 + 865a4b3 commit d003998
Show file tree
Hide file tree
Showing 21 changed files with 714 additions and 1 deletion.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

## Table of Contents
- [Quick Start](#quick-start)
- [Create Drash App](#create-drash-app)
- [Documentation](#documentation)
- [Features](#features)
- [Why use Drash?](#why-use-drash)
Expand Down Expand Up @@ -65,6 +66,26 @@ $ curl localhost:1447
Hello World! deno + Drash is cool!
```

## Create Drash App

Drash provides a basic tool to help you quickly create a Drash skeleton, with everything working out of the box, ready for you to build something great with.

This tool does not require you to install any Drash scripts or modules. It will create the skeleton of your choice (an API, a full web app, or a full web app with Vue) inside your current working directory.

To get started with the Create Drash App tool, see the following commands:

```
$ mkdir my-drash-project
$ cd my-drash-project
$ deno run --allow-run --allow-read --allow-write https://deno.land/x/[email protected]/create_app.ts [OPTIONS]
```

Display the options with `--help`:

```
$ deno run --allow-run https://deno.land/x/[email protected]/create_app.ts --help
```

## Documentation

[Full Documentation](https://drash.land/docs)
Expand Down
21 changes: 21 additions & 0 deletions console/create_app/app_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Drash } from "./deps.ts"
import HomeResource from "./resources/home_resource.ts";

const server = new Drash.Http.Server({
directory: Deno.realPathSync("./"),
response_output: "application/json",
logger: new Drash.CoreLoggers.ConsoleLogger({
enabled: false,
level: "debug",
}),
resources: [
HomeResource,
],
});

await server.run({
hostname: "localhost",
port: 1667,
});

console.log(`Server listening: http://${server.hostname}:${server.port}`);
23 changes: 23 additions & 0 deletions console/create_app/app_web_app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Drash } from "./deps.ts"
import HomeResource from "./resources/home_resource.ts";

const server = new Drash.Http.Server({
directory: Deno.realPathSync("./"),
response_output: "text/html",
logger: new Drash.CoreLoggers.ConsoleLogger({
enabled: false,
level: "debug",
}),
resources: [
HomeResource,
],
static_paths: ["/public"],
views_path: "./public/views",
});

await server.run({
hostname: "localhost",
port: 1667,
});

console.log(`Server listening: http://${server.hostname}:${server.port}`);
1 change: 1 addition & 0 deletions console/create_app/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {}
2 changes: 2 additions & 0 deletions console/create_app/deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { Drash } from "https://deno.land/x/[email protected]/mod.ts"
export { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
26 changes: 26 additions & 0 deletions console/create_app/package_vue.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "",
"version": "1.0.0",
"description": "",
"scripts": {
"buildVue": "node_modules/.bin/webpack-cli --config webpack.config.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-core": "^7.0.0-bridge.0",
"core-js": "^3.6.4"
},
"devDependencies": {
"babel-loader": "^8.0.6",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10",
"vue-loader": "^15.9.2",
"html-webpack-plugin": "^4.3.0",
"vue-template-compiler": "^2.6.11",
"@babel/core": "^7.9.6",
"css-loader": "^3.5.3",
"vue": "^2.6.11",
"vue-style-loader": "^4.1.2"
}
}
6 changes: 6 additions & 0 deletions console/create_app/public/css/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
main {
margin: auto;
}
h1 {
color: #282828;
}
Empty file.
16 changes: 16 additions & 0 deletions console/create_app/public/views/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="/public/js/index.js"></script>
<link rel="stylesheet" href="/public/css/index.css">
<title>Drash - Create App</title>
</head>
<body>
<main>
<h1>Welcome</h1>
<p>Welcome to your new application, start building something great with Drash!</p>
</main>
</body>
</html>
14 changes: 14 additions & 0 deletions console/create_app/public/views/index_vue.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Drash - Create App</title>
</head>
<body>
<main>
<div id="app"></div>
<script src="/public/js/app.js"></script>
</main>
</body>
</html>
25 changes: 25 additions & 0 deletions console/create_app/resources/home_resource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Drash } from "../deps.ts";

export default class HomeResource extends Drash.Http.Resource {
static paths = ["/"];

public GET() {
this.response.body = this.response.render('/index.html');
return this.response;
}

public POST() {
this.response.body = JSON.stringify({ message: "Not implemented" })
return this.response;
}

public DELETE() {
this.response.body = JSON.stringify({ message: "Not implemented" })
return this.response;
}

public PUT() {
this.response.body = JSON.stringify({ message: "Not implemented" })
return this.response;
}
}
25 changes: 25 additions & 0 deletions console/create_app/resources/home_resource_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Drash } from "../deps.ts";

export default class HomeResource extends Drash.Http.Resource {
static paths = ["/"];

public GET() {
this.response.body = JSON.stringify({ success: true, message: 'GET request received.' });
return this.response;
}

public POST() {
this.response.body = JSON.stringify({ message: "Not implemented" })
return this.response;
}

public DELETE() {
this.response.body = JSON.stringify({ message: "Not implemented" })
return this.response;
}

public PUT() {
this.response.body = JSON.stringify({ message: "Not implemented" })
return this.response;
}
}
17 changes: 17 additions & 0 deletions console/create_app/tests/resources/home_resource_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Drash } from '../../deps.ts'
import { assertEquals } from "../../deps.ts"
import HomeResource from '../../resources/home_resource.ts';

Deno.test({
name: 'HomeResource - GET /',
async fn(): Promise<void> {
const server = new Drash.Http.Server({
address: "localhost:1557",
resources: [HomeResource]
});
await server.run()
const response = await fetch('http://localhost:1557')
assertEquals(response.status, 200)
server.close()
})
});
7 changes: 7 additions & 0 deletions console/create_app/vue/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Vue from 'vue';
import App from './App.vue';

new Vue({
el: '#app',
render: h => h(App),
});
31 changes: 31 additions & 0 deletions console/create_app/vue/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<template>
<div id="app">
<h1>Welcome</h1>
<p>Welcome to your new application, start building something great with Drash!</p>
</div>
</template>

<script>
export default {
data() {
return {
};
},
};
</script>

<style lang="scss">
#app {
max-width: 400px;
margin: 0 auto;
line-height: 1.4;
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: blue;
}
h1 {
text-align: center;
}
</style>
44 changes: 44 additions & 0 deletions console/create_app/webpack_vue.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { VueLoaderPlugin } = require('vue-loader')
module.exports = {
entry: {
app: './vue/app.js'
},
output: {
filename: "[name].js",
path: __dirname + '/public/js/'
},
module: {
rules: [
{
test: /\.vue$/,
use: [
{
loader: 'vue-loader'
}
]
},
{
test: /\.js$/,
use: [
{
loader: 'babel-loader'
}
]
},
{
test: /\.(css|sass|scss)$/,
use: ["vue-style-loader", "css-loader"]
},
]
},
resolve: {
extensions: ['.vue', '.js']
},
plugins: [
new HtmlWebpackPlugin({
template: './public/views/index.html',
}),
new VueLoaderPlugin(),
]
}
2 changes: 2 additions & 0 deletions console/tests
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@

cd -
deno test tests/test.ts --config tsconfig.json --allow-net

deno test tests/create_app_test.ts --allow-read --allow-write --allow-run
)
Loading

0 comments on commit d003998

Please sign in to comment.