Skip to content

Commit 7f64d2c

Browse files
committed
refactor: initial typescript rewrite
1 parent 4970314 commit 7f64d2c

26 files changed

+578
-48
lines changed

examples/kitchen-sink/nuxt.config.js renamed to examples/kitchen-sink/nuxt.config.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
const { resolve } = require('path')
1+
import type { NuxtConfig } from '@nuxt/types'
2+
import nuxt7 from '../../src/module'
23

3-
module.exports = {
4-
rootDir: resolve(__dirname, '../..'),
5-
srcDir: __dirname,
6-
modules: [
7-
'@@/lib/module',
4+
export default <NuxtConfig> {
5+
buildModules: [
6+
nuxt7,
87
'@nuxtjs/pwa'
98
],
109
loadingIndicator: false,
1110
build: {
1211
extractCSS: true
1312
},
14-
generate: {
15-
dir: resolve(__dirname, 'dist')
16-
},
1713
manifest: {
1814
name: 'Nuxt7',
1915
description: 'Nuxt7 PWA Demo'

lib/utils.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
"name": "nuxt7",
33
"version": "4.0.2",
44
"license": "MIT",
5-
"main": "lib/module.js",
5+
"main": "dist/module.js",
66
"files": [
77
"lib"
88
],
99
"scripts": {
10+
"build": "siroc && mkdist --src src/runtime --dist dist/runtime",
1011
"dev": "yarn ks:dev",
1112
"ks:analyze": "nuxt build --analyze examples/kitchen-sink",
1213
"ks:build": "nuxt build examples/kitchen-sink",
@@ -23,13 +24,17 @@
2324
"framework7-icons": "^3.0.1",
2425
"framework7-vue": "^5.7.14",
2526
"less": "^4.1.0",
26-
"less-loader": "^6"
27+
"less-loader": "^6",
28+
"upath": "^2.0.1"
2729
},
2830
"devDependencies": {
31+
"@nuxt/types": "^2.14.12",
2932
"@nuxtjs/eslint-config": "latest",
3033
"@nuxtjs/pwa": "latest",
3134
"eslint": "latest",
35+
"mkdist": "^0.1.0",
3236
"nuxt-edge": "latest",
37+
"siroc": "^0.6.2",
3338
"standard-version": "latest",
3439
"surge": "latest"
3540
}

lib/build-config.js renamed to src/build-config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Source: https://github.com/framework7io/framework7/blob/master/scripts/build-config.js
22

3-
const config = {
3+
export const config = {
44
rtl: false,
55
components: [
66
// Appbar
@@ -146,4 +146,3 @@ const config = {
146146
}
147147
}
148148

149-
module.exports = config

lib/defaults.js renamed to src/defaults.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
const { themeColor, colors, themes, components } = require('./build-config')
1+
import { config } from './build-config'
22

3-
module.exports = {
3+
const { themeColor, colors, themes, components } = config
4+
5+
export const defaults = {
46
app: {
57
theme: 'auto'
68
},

lib/module.js renamed to src/module.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11

2-
const { resolvePath } = require('./utils')
3-
const templates = require('./templates')
4-
const getOptions = require('./options')
2+
import type { Module } from '@nuxt/types'
3+
import { resolveRuntimePath } from './utils'
4+
import { templates } from'./runtime/_templates'
5+
import { getOptions } from './options'
56

6-
module.exports = function nuxt7 (options) {
7+
export default <Module> function nuxt7 (options) {
78
this.nuxt.hook('build:before', () => {
89
prepareBuild.call(this, options)
910
})
@@ -54,15 +55,15 @@ function prepareBuild (_options) {
5455

5556
// Framework7 plugin
5657
this.addPlugin({
57-
src: resolvePath('templates/framework7/plugin.js'),
58+
src: resolveRuntimePath('framework7/plugin.js'),
5859
fileName: 'framework7/plugin.js',
5960
options
6061
})
6162

6263
// Copy all templates
6364
for (const template of templates) {
6465
this.addTemplate({
65-
src: resolvePath('templates/' + template),
66+
src: resolveRuntimePath(template),
6667
fileName: template,
6768
options
6869
})

lib/options.js renamed to src/options.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
const defu = require('defu')
2-
const { resolvePath } = require('./utils')
3-
const defaults = require('./defaults')
1+
import defu from 'defu'
2+
import { resolveRuntimePath } from './utils'
3+
import { defaults } from './defaults'
4+
import { normalize } from 'upath'
45

5-
module.exports = function getOptions (_options) {
6+
export function getOptions (_options) {
67
const options = defu({ ...this.options.framework7, ..._options }, defaults)
78

89
// History mode
@@ -23,11 +24,11 @@ module.exports = function getOptions (_options) {
2324

2425
// Icons
2526
if (options.f7Icons) {
26-
options.f7IconsSrc = require.resolve('framework7-icons/css/framework7-icons.css')
27+
options.f7IconsSrc = normalize(require.resolve('framework7-icons/css/framework7-icons.css'))
2728
}
2829

2930
if (options.mdIcons) {
30-
options.mdIconsSrc = resolvePath('fonts/material-icons.css').replace(/\\/g, '\\\\')
31+
options.mdIconsSrc = resolveRuntimePath('fonts/material-icons.css')
3132
}
3233

3334
return options
File renamed without changes.

lib/templates/index.js renamed to src/runtime/_templates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = [
1+
export const templates = [
22
// Framework 7
33
'framework7/routes.js',
44
'framework7/components.js',
File renamed without changes.

0 commit comments

Comments
 (0)