initial commit

This commit is contained in:
weiss
2020-03-25 16:36:52 +01:00
parent 204e15f3c4
commit a9b452be04
20 changed files with 530 additions and 1 deletions

34
generator/index.js Normal file
View File

@@ -0,0 +1,34 @@
module.exports = (api, options) => {
api.render('./templateExampleApp')
if(options.createVueConfigJs.toLowerCase() === 'y') {
api.render('./template')
}
api.extendPackage({
dependencies: {
'@vue/composition-api': '^0.5.0'
},
devDependencies: {
"purs-loader": "^3.7.1"
}
})
api.injectImports(api.entryFile, `import VueCompositionApi from '@vue/composition-api'`)
module.exports.hooks = (api) => {
api.afterInvoke(() => {
const { EOL } = require('os')
const fs = require('fs')
const contentMain = fs.readFileSync(api.resolve(api.entryFile), { encoding: 'utf-8' })
const lines = contentMain.split(/\r?\n/g).reverse()
if (lines.findIndex(line => line.match(/Vue\.use.*VueCompositionApi.*/)) !== -1) return
const renderIndex = lines.findIndex(line => line.match(/import/))
lines[renderIndex-1] += `${EOL}Vue.use(VueCompositionApi);${EOL}`
lines.reverse()
fs.writeFileSync(api.entryFile, lines.join(EOL), { encoding: 'utf-8' })
})
}
}

View File

@@ -0,0 +1,16 @@
{-
Welcome to a Spago project!
You can edit this file as you like.
-}
{ name = "my-project"
, dependencies =
[ "arrays"
, "console"
, "effect"
, "psci-support"
, "record-extra"
, "typelevel-prelude"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs", "node_modules/vue-cli-plugin-pure-vue/src/**/*.purs", "test/**/*.purs" ]
}

View File

@@ -0,0 +1,21 @@
const path = require('path');
module.exports = {
chainWebpack: config => {
// Purescript Loader
config.module
.rule('purescript')
.test(/\.purs$/)
.use('purs-loader')
.loader('purs-loader')
.tap(() => ({
// bundle: true,
// spago: true,
src: [
path.join('src', '**', '*.purs'),
path.join('node_modules', 'vue-cli-plugin-pure-vue', 'src', '**', '*.purs'),
path.join('.spago', '**', 'src', '**', '*.purs'),
],
}))
},
}

View File

@@ -0,0 +1,52 @@
module App where
import Prelude
import Effect (Effect)
import Effect.Unsafe (unsafePerformEffect)
import Effect.Vue.Ref as Ref
import Effect.Vue.Hooks as Hooks
import Effect.Class.Console (logShow)
import Data.Array (snoc)
type Product = { id :: Int, title :: String, price :: Number }
createProduct :: Array Product -> Int -> String -> Number -> Array Product
createProduct products id title price = snoc products { id, title, price }
execCreateProduct :: Ref.Ref (Array Product) -> String -> Number -> Effect Unit
execCreateProduct products title price = do
p <- Ref.read products
let p' = createProduct p 42 title (23.666)
Ref.write p' products
incRelease :: Ref.Ref Int -> Effect Unit
incRelease release = Ref.modify_ (\x -> x + 1) release
compTest :: Ref.Ref Int -> Effect Int
compTest release = do
r <- Ref.read release
pure (r + 1)
type Props = {}
setup :: forall a. Props -> Effect a
setup props = unsafePerformEffect do
products :: Ref.Ref (Array Product) <- Ref.new []
showUserInfo <- Ref.new false
release <- Ref.new 9
computedTest <- Ref.computed $ compTest release
Hooks.onMounted mounted
Ref.vReturn { products
, showUserInfo
, release
, computedTest
, incRelease: (incRelease release)
, addProduct: (execCreateProduct products)
}
mounted :: Effect Unit
mounted = do
logShow "estasetase"

View File

@@ -0,0 +1,31 @@
<template>
<div>
<button
target="_blank"
@click="incRelease(); addProduct('mytit')(32)();"
/>
<span class="mr-2">Latest Release {{ release }}</span>
ctest - {{ computedTest }} -
<privacy-policy
:release="42"
></privacy-policy>
<!--router-view
:release="release"
></router-view-->
{{ products }}
</div>
</template>
<script>
import { setup } from '@/App.purs'
import PrivacyPolicy from './views/PrivacyPolicy'
export default {
name: 'App',
components: {
PrivacyPolicy,
},
setup
};
</script>

View File

@@ -0,0 +1,24 @@
module PrivacyPolicy where
import Prelude
import Effect (Effect)
import Effect.Unsafe (unsafePerformEffect)
import Effect.Vue.Ref as Ref
import Record.Extra as Record
import Data.Array as Arr
import Type.Row (RProxy(..))
type Props = ( release :: Int )
-- this to lib
-- type RecordProps = Record.Record Props
props = Record.keys (RProxy :: RProxy Props)
privacyPolicy :: String -> String
privacyPolicy policyRaw = policyRaw
buildSetup :: forall a. String -> _ -> Effect a
buildSetup policyRaw props = unsafePerformEffect do
dialog <- Ref.new true
Ref.vReturn { dialog, privacyPolicy: privacyPolicy policyRaw }

View File

@@ -0,0 +1,31 @@
<template>
<v-container>
<v-layout>
<v-card>
<v-card-title
class="headline grey lighten-2"
primary-title
>
Privacy Policy r {{ release }}
</v-card-title>
<v-card-text v-html="privacyPolicy()">
</v-card-text>
</v-card>
</v-layout>
</v-container>
</template>
<script>
import { buildSetup, props } from '@/views/PrivacyPolicy.purs'
export default {
name: 'PrivacyPolicy',
props,
setup: buildSetup('myprvipolicy'),
}
</script>
<style>
</style>