Skip to content

Commit

Permalink
feat: add changelog repl. generate changelog online almose done.
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Nov 24, 2020
1 parent 8b5f7fb commit c7127b1
Show file tree
Hide file tree
Showing 21 changed files with 3,135 additions and 25 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
bin
dist
coverage.out
release.md
release.md
node_modules
22 changes: 2 additions & 20 deletions 4_generator/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import (
"encoding/json"
"fmt"
"html/template"
"io/ioutil"
"net/url"
"os"
"path"
"strings"

transformer "github.com/axetroy/changelog/3_transformer"
Expand All @@ -17,7 +14,7 @@ import (
giturls "github.com/whilp/git-urls"
)

func Generate(g *client.GitClient, contexts []*transformer.TemplateContext, format string, preset string, templateFile string) ([]byte, error) {
func Generate(g *client.GitClient, contexts []*transformer.TemplateContext, format string, preset string, templateStr string) ([]byte, error) {
remote, err := g.GetRemote()

if err != nil {
Expand Down Expand Up @@ -66,26 +63,11 @@ func Generate(g *client.GitClient, contexts []*transformer.TemplateContext, form
case "md":
var output []byte

var templateStr string

cwd, err := os.Getwd()

if err != nil {
return nil, errors.WithStack(err)
}

if templateFile != "" {
if !path.IsAbs(templateFile) {
templateFile = path.Join(cwd, templateFile)
}
fileBytes, err := ioutil.ReadFile(templateFile)

if err != nil {
return nil, errors.WithStack(err)
}

templateStr = string(fileBytes)
} else {
if templateStr == "" {
switch preset {
case "default":
templateStr = DEFAULT_TEMPLATE
Expand Down
7 changes: 4 additions & 3 deletions cmd/changelog-remote/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/pkg/errors"
)

func generate(remote string, version string) ([]byte, error) {
func generate(remote string, version string, templateStr string) ([]byte, error) {
repo, err := git.CloneContext(context.Background(), memory.NewStorage(), nil, &git.CloneOptions{
URL: remote,
Progress: os.Stderr,
Expand Down Expand Up @@ -50,7 +50,7 @@ func generate(remote string, version string) ([]byte, error) {
return nil, errors.WithStack(err)
}

output, err := generator.Generate(c, ctxs, "md", "default", "")
output, err := generator.Generate(c, ctxs, "md", "default", templateStr)

if err != nil {
return nil, errors.WithStack(err)
Expand All @@ -75,10 +75,11 @@ func handler(w http.ResponseWriter, r *http.Request) {
username := query.Get("username")
repo := query.Get("repo")
version := query.Get("version")
template := query.Get("template")

url := fmt.Sprintf("https://github.com/%s/%s", username, repo)

changelog, err := generate(url, version)
changelog, err := generate(url, version, template)

if err != nil {
b := []byte(fmt.Sprintf("%+v\n", err))
Expand Down
19 changes: 18 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"path"

parser "github.com/axetroy/changelog/1_parser"
extractor "github.com/axetroy/changelog/2_extractor"
Expand Down Expand Up @@ -148,7 +150,22 @@ func run() error {
return errors.WithStack(err)
}

output, err := generator.Generate(client, ctxs, format, preset, templateFile)
var templateStr string

if templateFile != "" {
if !path.IsAbs(templateFile) {
templateFile = path.Join(cwd, templateFile)
}
fileBytes, err := ioutil.ReadFile(templateFile)

if err != nil {
return errors.WithStack(err)
}

templateStr = string(fileBytes)
}

output, err := generator.Generate(client, ctxs, format, preset, templateStr)

if err != nil {
return errors.WithStack(err)
Expand Down
1 change: 1 addition & 0 deletions repl/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_API_HOST=http://localhost:8080
1 change: 1 addition & 0 deletions repl/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_API_HOST=https://whatchanged.herokuapp.com
4 changes: 4 additions & 0 deletions repl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.DS_Store
dist
*.local
13 changes: 13 additions & 0 deletions repl/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Changelog REPL</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
21 changes: 21 additions & 0 deletions repl/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "changelog-repl",
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build"
},
"dependencies": {
"ant-design-vue": "^2.0.0-rc.1",
"marked": "^1.2.5",
"vue": "^3.x"
},
"devDependencies": {
"@types/marked": "^1.2.0",
"@vue/compiler-sfc": "^3.0.2",
"import-http": "^0.3.1",
"rollup-plugin-esm-import-to-url": "^2.1.0",
"sass": "^1.29.0",
"vite": "^1.0.0-rc.9"
}
}
Binary file added repl/public/favicon.ico
Binary file not shown.
122 changes: 122 additions & 0 deletions repl/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<template>
<div>
<div class="toolbar">
<a-form
layout="inline"
:model="form"
@submit="onSubmit"
@submit.native.prevent
>
<a-form-item label="Username">
<a-input v-model:value="form.username"> </a-input>
</a-form-item>
<a-form-item label="Repo">
<a-input v-model:value="form.repo"> </a-input>
</a-form-item>
<a-form-item label="Version">
<a-input v-model:value="form.version"> </a-input>
</a-form-item>
<a-form-item>
<a-button type="primary" html-type="submit" :loading="loading">
Generate
</a-button>
</a-form-item>
</a-form>
</div>
<div class="container">
<div class="left">
<div style="display: flex; height: 100%; padding-left: 10px">
<CodeMirror
class="my-editor2"
:content.sync="template"
@update:content="template = $event"
:readonly="true"
/>
</div>
</div>
<div class="right">
<Render :content="content"></Render>
</div>
</div>
</div>
</template>

<script>
import { defineComponent } from "vue";
import Render from "./components/Render.vue";
import CodeMirror from "./components/CodeMirror.vue";
import TEMPLATE_DEFAULT from "./template/default";
export default defineComponent({
name: "App",
components: {
Render,
CodeMirror,
},
data() {
return {
loading: false,
template: TEMPLATE_DEFAULT,
content: "",
form: {
username: "axetroy",
repo: "vscode-deno",
version: "HEAD~",
},
};
},
methods: {
onSubmit() {
const template = encodeURIComponent(this.template);
this.loading = true;
fetch(
`${import.meta.env.VITE_API_HOST}/?username=${
this.form.username || ""
}&repo=${this.form.repo || ""}&version=${
this.form.version || ""
}&template=${template || ""}`
)
.then((res) => {
return res.text();
})
.then((markdown) => {
this.content = markdown;
})
.finally(() => {
this.loading = false;
});
},
},
});
</script>
<style lang="scss" scoped>
$height: 60px;
.toolbar {
height: $height;
background: yellow;
display: flex;
align-items: center;
padding: 0 10px;
}
.container {
display: flex;
height: calc(100vh - #{$height});
width: 100vw;
.left {
// background-color: green;
flex: 1;
overflow: scroll;
border-right: 1px solid #e2e2;
}
.right {
// background-color: red;
flex: 1;
overflow: hidden;
}
}
</style>
Binary file added repl/src/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c7127b1

Please sign in to comment.