Created
November 15, 2018 23:18
-
-
Save lagenorhynque/59f674229220425effb6dd731c12e37c to your computer and use it in GitHub Desktop.
A simple Clojure script to generate Vue.js (TypeScript) component files.
This file contains hidden or 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
{:deps {selmer {:mvn/version "1.12.3"}} | |
:paths ["scripts"]} |
This file contains hidden or 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
(ns generate-component | |
(:require [clojure.java.io :as io] | |
[selmer.parser :as selmer])) | |
(def destination-dirs | |
{"component" "src/components" | |
"c" "src/components" | |
"view" "src/views" | |
"v" "src/views"}) | |
(def template-files | |
{"templates/Component.html" "{{ component-name }}.html" | |
"templates/Component.ts" "{{ component-name }}.ts" | |
"templates/index.vue" "index.vue"}) | |
(defn -main [type component-name] | |
(if-let [destination-dir (get destination-dirs type)] | |
(let [new-dir (str destination-dir \/ component-name)] | |
(if (.exists (io/file new-dir)) | |
(println "The specified name is already used:" new-dir) | |
(doseq [[template fname] template-files] | |
(let [ctx {:component-name component-name} | |
file (str destination-dir \/ component-name \/ (selmer/render fname ctx))] | |
(io/make-parents file) | |
(spit file (selmer/render-file template ctx)) | |
(println "Generated:" file))))) | |
(println "The first argument must be one of the following:" (keys destination-dirs)))) |
This file contains hidden or 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
(empty file) |
This file contains hidden or 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
import { Component, Vue } from 'vue-property-decorator'; | |
@Component | |
export default class {{ component-name }} extends Vue {} |
This file contains hidden or 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
<template src="./{{ component-name }}.html"></template> | |
<script lang="ts" src="./{{ component-name }}.ts"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment