Skip to content

Commit 3b5dd28

Browse files
authored
feat: refactor plugins, new browser plugins (#2)
1 parent 41727a5 commit 3b5dd28

File tree

24 files changed

+328
-60
lines changed

24 files changed

+328
-60
lines changed

examples/wordpress/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"react": "^16.8.2",
99
"react-dom": "^16.8.2",
1010
"smooth-backend-wordpress": "latest",
11+
"smooth-plugin-head-meta": "latest",
1112
"smooth-core": "latest"
1213
}
1314
}

examples/wordpress/smooth.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import path from 'path'
22

33
module.exports = {
44
plugins: [
5+
{ resolve: 'smooth-plugin-head-meta' },
56
{
6-
resolve: require.resolve('smooth-backend-wordpress'),
7+
resolve: 'smooth-backend-wordpress',
78
options: {
89
basePath: path.join(__dirname, 'wordpress'),
910
baseUrl: 'http://localhost:8000',

examples/wordpress/src/pages/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import { Link } from 'smooth-core/router'
66
export const contentFragment = gql`
77
fragment PageProps on Page {
88
title
9-
date
10-
dateTime
119
book {
1210
metadata {
1311
slug

packages/smooth-backend-wordpress/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "smooth-backend-wordpress",
33
"description": "Wordpress backend for Smooth.js.",
44
"version": "0.1.1-alpha.18",
5-
"main": "lib/index.js",
65
"repository": "https://github.com/smooth-code/smooth.js/tree/master/packages/smooth-backend-wordpress",
76
"author": "Greg Bergé <berge.greg@gmail.com>",
87
"publishConfig": {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./lib/smooth-node')

packages/smooth-backend-wordpress/src/cpt/index.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('#onBuild', () => {
1212

1313
it('should generate config', async () => {
1414
const plugin = {
15-
hooks: { onBuild },
15+
node: { onBuild },
1616
options: {
1717
basePath: '/tmp',
1818
},

packages/smooth-core/src/api/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { callApi } from '../plugin'
1+
import { callApi } from '../plugin/node'
22

33
export function createAPIClient({ config, lang }) {
44
const defaultOptions = { lang }

packages/smooth-core/src/build/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import path from 'path'
12
import webpack from 'webpack'
23
import { applyAsyncHook } from '../plugin'
34
import {
@@ -9,6 +10,30 @@ import { createCache } from './cache'
910
import { Watcher, watchFs } from './watcher'
1011
import webpackMiddleware from './webpackMiddleware'
1112

13+
function getPluginFileContent(config) {
14+
const imports = []
15+
const names = []
16+
config.plugins
17+
.filter(plugin => plugin.browser)
18+
.forEach((plugin, index) => {
19+
const name = `plugin${index}`
20+
imports.push(
21+
`import * as plugin${index} from '${path.join(
22+
plugin.resolve,
23+
'smooth-browser',
24+
)}';`,
25+
)
26+
names.push(name)
27+
})
28+
29+
return `${imports.join('\n')}\nexport default [${names.join(',')}];`
30+
}
31+
32+
export async function buildBrowserPlugins({ config }) {
33+
const cache = createCache({ config })
34+
await cache.writeCacheFile('browser-plugins.js', getPluginFileContent(config))
35+
}
36+
1237
export async function buildSchemaDefinition({ config }) {
1338
const schemaDefinition = await createSchemaDefinition({ config })
1439
const schema = makeExecutableSchema(schemaDefinition)

packages/smooth-core/src/cli/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import createLogger from 'progress-estimator'
55
import { getConfig } from '../config'
66
import { start } from '../server'
77
import {
8+
buildBrowserPlugins,
89
watchSchema,
910
buildSchema,
1011
watchWebpack,
@@ -60,6 +61,7 @@ async function devCommand() {
6061
clearConsole()
6162
console.log('> smooth.js 👨‍🚀')
6263
const config = await getConfig({ dev: true })
64+
await logger(buildBrowserPlugins({ config }), 'Build plugins')
6365
watch({ config })
6466
}
6567

0 commit comments

Comments
 (0)