initial commit
This commit is contained in:
34
generator/index.js
Normal file
34
generator/index.js
Normal 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' })
|
||||
})
|
||||
}
|
||||
}
|
||||
16
generator/template/spago.dhall
Normal file
16
generator/template/spago.dhall
Normal 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" ]
|
||||
}
|
||||
21
generator/template/vue.config.js
Normal file
21
generator/template/vue.config.js
Normal 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'),
|
||||
],
|
||||
}))
|
||||
},
|
||||
}
|
||||
52
generator/templateExampleApp/src/App.purs
Normal file
52
generator/templateExampleApp/src/App.purs
Normal 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"
|
||||
31
generator/templateExampleApp/src/App.vue
Normal file
31
generator/templateExampleApp/src/App.vue
Normal 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>
|
||||
24
generator/templateExampleApp/src/views/PrivacyPolicy.purs
Normal file
24
generator/templateExampleApp/src/views/PrivacyPolicy.purs
Normal 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 }
|
||||
31
generator/templateExampleApp/src/views/PrivacyPolicy.vue
Normal file
31
generator/templateExampleApp/src/views/PrivacyPolicy.vue
Normal 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>
|
||||
Reference in New Issue
Block a user