-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added $map suffix for object arrays
- Loading branch information
1 parent
72cc945
commit 179fa1a
Showing
11 changed files
with
160 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ plugins: | |
- spassr: | ||
port: 3400 | ||
ssr: true | ||
- postcss: | ||
- mdsvex: | ||
- postcss: | ||
- vite: | ||
- debugger: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,31 @@ | ||
/// <reference path="../../../typedef.js" /> | ||
|
||
import { mdsvex } from 'mdsvex' | ||
const extension = ['.md', '.svx', '.svelte'] | ||
|
||
/** @type {RoxiPlugin} */ | ||
module.exports.default = { | ||
name: 'mdsvex', | ||
hooks: [ | ||
{ | ||
event: 'start', | ||
action: app => app.config.mdsvex = {}, //provide an mdsvex object for developers to modify | ||
}, | ||
{ | ||
event: 'before:bundle', | ||
action: (app, params) => { | ||
const extension = params.extension || .md | ||
|
||
//provide an mdsvex object for developers to modify | ||
const conf = { extension, ...params } | ||
|
||
|
||
app.merge({ | ||
config: { | ||
mdsvex: conf, | ||
svelte: { | ||
preprocess: [ | ||
mdsvex({ | ||
extension: '.md', | ||
...app.config.mdsvex, | ||
...params | ||
}) | ||
], | ||
extensions: params.extension | ||
|| app.config.mdsvex.extension | ||
|| extension | ||
preprocess: { mdsvex: conf }, | ||
preprocess$map: { mdsvex }, | ||
extensions: [extension] | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const { keysAsFunctionsRecursive } = require(".."); | ||
|
||
const fn = async val => ({ ...val, touched: true }) | ||
const getBaseObj = () => ({ | ||
aPlugin: { | ||
string: 'abc', | ||
number: 123, | ||
obj: { foo: 'bar' }, | ||
target$map: { fn }, | ||
target: { | ||
fn: { isTarget: true, touched: false } | ||
} | ||
} | ||
}) | ||
|
||
it('converts objects to arrays', async () => { | ||
const config = getBaseObj() | ||
const result = await keysAsFunctionsRecursive(config) | ||
|
||
expect(result).toEqual({ | ||
aPlugin: { | ||
string: 'abc', | ||
number: 123, | ||
obj: { foo: 'bar' }, | ||
target: [ | ||
{ | ||
"isTarget": true, | ||
"touched": true, | ||
}, | ||
] | ||
} | ||
}) | ||
}) | ||
|
||
it('processes children first', async () => { | ||
const config = getBaseObj() | ||
config.aPlugin.target.fn.child = { fn: { isTarget: true, touched: false } } | ||
config.aPlugin.target.fn.child$map = { fn } | ||
|
||
|
||
const result = await keysAsFunctionsRecursive(config) | ||
|
||
expect(result).toEqual({ | ||
aPlugin: { | ||
string: 'abc', | ||
number: 123, | ||
obj: { foo: 'bar' }, | ||
target: [ | ||
{ | ||
isTarget: true, | ||
touched: true, | ||
child: [{ | ||
isTarget: true, | ||
touched: true, | ||
}] | ||
}, | ||
] | ||
} | ||
}) | ||
}) |