solid-vue-cli 0.1.0 ā 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/addons/chartist.js +53 -0
- package/addons/decimal.js +44 -0
- package/addons/drizzle.js +60 -0
- package/addons/exceljs.js +45 -0
- package/addons/index.js +10 -0
- package/addons/pdf-lib.js +56 -0
- package/package.json +6 -3
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { execSync } from 'node:child_process'
|
|
4
|
+
import chalk from 'chalk'
|
|
5
|
+
|
|
6
|
+
export default function installChartist(cwd) {
|
|
7
|
+
console.log(chalk.blue.bold('\nš Installing Chartist...'))
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
execSync('npm install chartist', { stdio: 'inherit', cwd })
|
|
11
|
+
} catch (err) {
|
|
12
|
+
console.error(chalk.red.bold('\nā Failed to install Chartist:'))
|
|
13
|
+
console.error(chalk.red(err.message))
|
|
14
|
+
return
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const componentsDir = path.join(cwd, 'src', 'components')
|
|
18
|
+
if (!fs.existsSync(componentsDir)) fs.mkdirSync(componentsDir, { recursive: true })
|
|
19
|
+
|
|
20
|
+
fs.writeFileSync(path.join(componentsDir, 'LineChart.vue'), `<script setup lang="ts">
|
|
21
|
+
import { ref, onMounted, onUnmounted, watch } from 'vue'
|
|
22
|
+
import { LineChart } from 'chartist'
|
|
23
|
+
import 'chartist/dist/index.css'
|
|
24
|
+
|
|
25
|
+
const props = defineProps<{
|
|
26
|
+
labels: string[]
|
|
27
|
+
series: number[][]
|
|
28
|
+
}>()
|
|
29
|
+
|
|
30
|
+
const chartEl = ref<HTMLElement | null>(null)
|
|
31
|
+
let chart: LineChart | null = null
|
|
32
|
+
|
|
33
|
+
function render() {
|
|
34
|
+
if (!chartEl.value) return
|
|
35
|
+
chart?.detach()
|
|
36
|
+
chart = new LineChart(chartEl.value, { labels: props.labels, series: props.series })
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
onMounted(render)
|
|
40
|
+
watch(() => [props.labels, props.series], render, { deep: true })
|
|
41
|
+
onUnmounted(() => chart?.detach())
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<template>
|
|
45
|
+
<div ref="chartEl" class="ct-chart"></div>
|
|
46
|
+
</template>
|
|
47
|
+
`)
|
|
48
|
+
|
|
49
|
+
console.log(chalk.green.bold('\nā
Chartist installed successfully!'))
|
|
50
|
+
console.log(chalk.white('š” Chartist haven\'t official Vue Binding ā Wrapper component is ready:'))
|
|
51
|
+
console.log(chalk.cyan(' import LineChart from "../components/LineChart.vue"'))
|
|
52
|
+
console.log(chalk.cyan(' <LineChart :labels="[\'Sun\',\'Mon\']" :series="[[10,20]]" />'))
|
|
53
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { execSync } from 'node:child_process'
|
|
4
|
+
import chalk from 'chalk'
|
|
5
|
+
|
|
6
|
+
export default function installDecimal(cwd) {
|
|
7
|
+
console.log(chalk.blue.bold('\nš Installing Decimal.js...'))
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
execSync('npm install decimal.js', { stdio: 'inherit', cwd })
|
|
11
|
+
} catch (err) {
|
|
12
|
+
console.error(chalk.red.bold('\nā Failed to install Decimal.js:'))
|
|
13
|
+
console.error(chalk.red(err.message))
|
|
14
|
+
return
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const libDir = path.join(cwd, 'src', 'lib')
|
|
18
|
+
if (!fs.existsSync(libDir)) fs.mkdirSync(libDir, { recursive: true })
|
|
19
|
+
|
|
20
|
+
fs.writeFileSync(path.join(libDir, 'money.ts'), `import Decimal from 'decimal.js'
|
|
21
|
+
|
|
22
|
+
export function multiply(a: number | string, b: number | string): string {
|
|
23
|
+
return new Decimal(a).times(b).toString()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function add(a: number | string, b: number | string): string {
|
|
27
|
+
return new Decimal(a).plus(b).toString()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function subtract(a: number | string, b: number | string): string {
|
|
31
|
+
return new Decimal(a).minus(b).toString()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function formatIDR(value: number | string): string {
|
|
35
|
+
const num = new Decimal(value).toNumber()
|
|
36
|
+
return 'Rp' + num.toLocaleString('id-ID', { maximumFractionDigits: 2 })
|
|
37
|
+
}
|
|
38
|
+
`)
|
|
39
|
+
|
|
40
|
+
console.log(chalk.green.bold('\nā
Decimal.js installed successfully!'))
|
|
41
|
+
console.log(chalk.white('š” Helper is ready in src/lib/money.ts:'))
|
|
42
|
+
console.log(chalk.cyan(' import { multiply, formatIDR } from "../lib/money"'))
|
|
43
|
+
console.log(chalk.cyan(' formatIDR(multiply(qty, hargaPerKg))'))
|
|
44
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { execSync } from 'node:child_process'
|
|
4
|
+
import chalk from 'chalk'
|
|
5
|
+
|
|
6
|
+
export default function installDrizzle(cwd) {
|
|
7
|
+
console.log(chalk.blue.bold('\nš Installing Drizzle ORM (SQLite dialect)...'))
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
execSync('npm install drizzle-orm better-sqlite3', { stdio: 'inherit', cwd })
|
|
11
|
+
execSync('npm install -D drizzle-kit @types/better-sqlite3', { stdio: 'inherit', cwd })
|
|
12
|
+
} catch (err) {
|
|
13
|
+
console.error(chalk.red.bold('\nā Failed to install Drizzle packages:'))
|
|
14
|
+
console.error(chalk.red(err.message))
|
|
15
|
+
return
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const dbDir = path.join(cwd, 'src', 'server', 'db')
|
|
19
|
+
if (!fs.existsSync(dbDir)) fs.mkdirSync(dbDir, { recursive: true })
|
|
20
|
+
|
|
21
|
+
fs.writeFileSync(path.join(dbDir, 'schema.ts'), `import { sqliteTable, integer, text } from 'drizzle-orm/sqlite-core'
|
|
22
|
+
|
|
23
|
+
// Example table schema. Configure your own tables here. See https://orm.drizzle.team/docs/quickstart for more info.
|
|
24
|
+
export const items = sqliteTable('items', {
|
|
25
|
+
id: integer('id').primaryKey({ autoIncrement: true }),
|
|
26
|
+
name: text('name').notNull(),
|
|
27
|
+
createdAt: text('created_at').notNull().default(new Date().toISOString()),
|
|
28
|
+
})
|
|
29
|
+
`)
|
|
30
|
+
|
|
31
|
+
fs.writeFileSync(path.join(dbDir, 'client.ts'), `import { drizzle } from 'drizzle-orm/better-sqlite3'
|
|
32
|
+
import Database from 'better-sqlite3'
|
|
33
|
+
import * as schema from './schema'
|
|
34
|
+
|
|
35
|
+
// Local Development: SQLite database connection using better-sqlite3. This is suitable for local development and testing,
|
|
36
|
+
// Change the dialect to 'd1/drizzle-orm' and update the connection method when deploying to Cloudflare D1. schema.ts file should remain the same,
|
|
37
|
+
// only the connection method changes when deploying to D1.
|
|
38
|
+
const sqlite = new Database('local.db')
|
|
39
|
+
export const db = drizzle(sqlite, { schema })
|
|
40
|
+
`)
|
|
41
|
+
|
|
42
|
+
fs.writeFileSync(path.join(cwd, 'drizzle.config.ts'), `import { defineConfig } from 'drizzle-kit'
|
|
43
|
+
|
|
44
|
+
export default defineConfig({
|
|
45
|
+
schema: './src/server/db/schema.ts',
|
|
46
|
+
out: './drizzle',
|
|
47
|
+
dialect: 'sqlite',
|
|
48
|
+
dbCredentials: {
|
|
49
|
+
url: './local.db',
|
|
50
|
+
},
|
|
51
|
+
})
|
|
52
|
+
`)
|
|
53
|
+
|
|
54
|
+
console.log(chalk.green.bold('\nā
Drizzle ORM installed successfully!'))
|
|
55
|
+
console.log(chalk.white('š” Next steps:'))
|
|
56
|
+
console.log(chalk.cyan(' 1. Edit src/server/db/schema.ts to define your tables'))
|
|
57
|
+
console.log(chalk.cyan(' 2. Run npx drizzle-kit push (to create tables in local.db)'))
|
|
58
|
+
console.log(chalk.cyan(' 3. import { db } from "../db/client" in your API handlers at src/server/api/*.ts'))
|
|
59
|
+
console.log(chalk.yellow(' ā ļø When deploying to Cloudflare D1, change client.ts to use drizzle-orm/d1'))
|
|
60
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { execSync } from 'node:child_process'
|
|
4
|
+
import chalk from 'chalk'
|
|
5
|
+
|
|
6
|
+
export default function installExcelJs(cwd) {
|
|
7
|
+
console.log(chalk.blue.bold('\nš Installing ExcelJS...'))
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
execSync('npm install exceljs', { stdio: 'inherit', cwd })
|
|
11
|
+
} catch (err) {
|
|
12
|
+
console.error(chalk.red.bold('\nā Failed to install ExcelJS:'))
|
|
13
|
+
console.error(chalk.red(err.message))
|
|
14
|
+
return
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const libDir = path.join(cwd, 'src', 'lib')
|
|
18
|
+
if (!fs.existsSync(libDir)) fs.mkdirSync(libDir, { recursive: true })
|
|
19
|
+
|
|
20
|
+
fs.writeFileSync(path.join(libDir, 'excel.ts'), `import ExcelJS from 'exceljs'
|
|
21
|
+
|
|
22
|
+
export async function exportToExcel(rows: Record<string, unknown>[], filename: string) {
|
|
23
|
+
const workbook = new ExcelJS.Workbook()
|
|
24
|
+
const sheet = workbook.addWorksheet('Sheet1')
|
|
25
|
+
|
|
26
|
+
if (rows.length > 0) {
|
|
27
|
+
sheet.columns = Object.keys(rows[0]).map((key) => ({ header: key, key, width: 18 }))
|
|
28
|
+
sheet.addRows(rows)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const buffer = await workbook.xlsx.writeBuffer()
|
|
32
|
+
const blob = new Blob([buffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })
|
|
33
|
+
const url = URL.createObjectURL(blob)
|
|
34
|
+
const a = document.createElement('a')
|
|
35
|
+
a.href = url
|
|
36
|
+
a.download = filename
|
|
37
|
+
a.click()
|
|
38
|
+
URL.revokeObjectURL(url)
|
|
39
|
+
}
|
|
40
|
+
`)
|
|
41
|
+
|
|
42
|
+
console.log(chalk.green.bold('\nā
ExcelJS installed successfully!'))
|
|
43
|
+
console.log(chalk.white('š” Usage:'))
|
|
44
|
+
console.log(chalk.cyan(' await exportToExcel(data, "reports.xlsx")'))
|
|
45
|
+
}
|
package/addons/index.js
CHANGED
|
@@ -9,6 +9,11 @@ import ofetch from './ofetch.js'
|
|
|
9
9
|
import i18n from './i18n.js'
|
|
10
10
|
import lint from './lint.js'
|
|
11
11
|
import auth from './auth.js'
|
|
12
|
+
import drizzle from './drizzle.js'
|
|
13
|
+
import decimal from './decimal.js'
|
|
14
|
+
import chartist from './chartist.js'
|
|
15
|
+
import pdfLib from './pdf-lib.js'
|
|
16
|
+
import exceljs from './exceljs.js'
|
|
12
17
|
|
|
13
18
|
export const addons = {
|
|
14
19
|
tailwind,
|
|
@@ -22,4 +27,9 @@ export const addons = {
|
|
|
22
27
|
i18n,
|
|
23
28
|
lint,
|
|
24
29
|
auth,
|
|
30
|
+
drizzle,
|
|
31
|
+
decimal,
|
|
32
|
+
chartist,
|
|
33
|
+
'pdf-lib': pdfLib,
|
|
34
|
+
exceljs,
|
|
25
35
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { execSync } from 'node:child_process'
|
|
4
|
+
import chalk from 'chalk'
|
|
5
|
+
|
|
6
|
+
export default function installPdfLib(cwd) {
|
|
7
|
+
console.log(chalk.blue.bold('\nš Installing pdf-lib...'))
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
execSync('npm install pdf-lib', { stdio: 'inherit', cwd })
|
|
11
|
+
} catch (err) {
|
|
12
|
+
console.error(chalk.red.bold('\nā Failed to install pdf-lib:'))
|
|
13
|
+
console.error(chalk.red(err.message))
|
|
14
|
+
return
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const libDir = path.join(cwd, 'src', 'lib')
|
|
18
|
+
if (!fs.existsSync(libDir)) fs.mkdirSync(libDir, { recursive: true })
|
|
19
|
+
|
|
20
|
+
fs.writeFileSync(path.join(libDir, 'pdf.ts'), `import { PDFDocument, StandardFonts, rgb } from 'pdf-lib'
|
|
21
|
+
|
|
22
|
+
export async function generateSimplePdf(title: string, lines: string[]): Promise<Uint8Array> {
|
|
23
|
+
const pdfDoc = await PDFDocument.create()
|
|
24
|
+
const page = pdfDoc.addPage([595, 842])
|
|
25
|
+
const font = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
|
26
|
+
const boldFont = await pdfDoc.embedFont(StandardFonts.HelveticaBold)
|
|
27
|
+
|
|
28
|
+
page.drawText(title, { x: 50, y: 780, size: 18, font: boldFont, color: rgb(0, 0, 0) })
|
|
29
|
+
lines.forEach((line, i) => {
|
|
30
|
+
page.drawText(line, { x: 50, y: 740 - i * 20, size: 11, font })
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
return pdfDoc.save()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function downloadPdf(bytes: Uint8Array, filename: string) {
|
|
37
|
+
const blob = new Blob([bytes], { type: 'application/pdf' })
|
|
38
|
+
const url = URL.createObjectURL(blob)
|
|
39
|
+
const a = document.createElement('a')
|
|
40
|
+
a.href = url
|
|
41
|
+
a.download = filename
|
|
42
|
+
a.click()
|
|
43
|
+
URL.revokeObjectURL(url)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function buildWhatsAppShareLink(phone: string, message: string): string {
|
|
47
|
+
return \`https://wa.me/\${phone}?text=\${encodeURIComponent(message)}\`
|
|
48
|
+
}
|
|
49
|
+
`)
|
|
50
|
+
|
|
51
|
+
console.log(chalk.green.bold('\nā
pdf-lib installed successfully!'))
|
|
52
|
+
console.log(chalk.white('š” Usage:'))
|
|
53
|
+
console.log(chalk.cyan(' const bytes = await generateSimplePdf("Nota", ["coconut: 10kg"])'))
|
|
54
|
+
console.log(chalk.cyan(' downloadPdf(bytes, "invoice.pdf")'))
|
|
55
|
+
console.log(chalk.gray(' Send via WhatsApp: window.open(buildWhatsAppShareLink(number, message))'))
|
|
56
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solid-vue-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"files": [
|
|
5
|
+
"files": [
|
|
6
|
+
"bin",
|
|
7
|
+
"addons"
|
|
8
|
+
],
|
|
6
9
|
"bin": {
|
|
7
10
|
"solid-vue": "./bin/cli.js"
|
|
8
11
|
},
|
|
9
12
|
"dependencies": {
|
|
10
13
|
"chalk": "^6.0.0"
|
|
11
14
|
}
|
|
12
|
-
}
|
|
15
|
+
}
|