Skip to content

Commit

Permalink
Merge branch 'master' into chore/update-homepage-link
Browse files Browse the repository at this point in the history
  • Loading branch information
lihbr authored Sep 10, 2020
2 parents cc79528 + 39d9dd5 commit e797492
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions spec/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ describe('prismic-nuxt module', () => {
});

it('should not warn to create ~/app/prismic/link-resolver.js if path exists', async () => {
fs.existsSync = jest.fn().mockReturnValueOnce(true);
fs.existsSync = jest.fn().mockReturnValueOnce(true).mockReturnValueOnce(true);
await prismicNuxt.call(context, { ...moduleOptions });
expect(logger.warn.mock.calls.length).toEqual(0);
expect(context.addTemplate.mock.calls[1][0].src).toEqual(path.join('/var/nuxt/app/prismic/link-resolver.js'));
});

it('should not create ~/app/prismic/html-serializer.js if path exists', async () => {
fs.existsSync = jest.fn().mockReturnValueOnce(true).mockReturnValueOnce(true);
fs.existsSync = jest.fn().mockReturnValueOnce(true).mockReturnValueOnce(true).mockReturnValueOnce(true);
await prismicNuxt.call(context, { ...moduleOptions });
expect(logger.warn.mock.calls.length).toEqual(0);
expect(context.addTemplate.mock.calls[2][0].src).toEqual(path.join('/var/nuxt/app/prismic/html-serializer.js'));
Expand Down
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ function install(moduleOptions) {
options.preview = '/preview';
}
const repo = options.endpoint.replace(/^https?:\/\//, '').replace(/(\.cdn)?\.prismic.+/, '');
const app = this.options.dir.app || 'app';

// Add in Prismic libraries to enable preview
if (options.preview) {
// Add /preview
const userPreviewPage = path.join(this.options.srcDir, app, 'prismic', 'pages', 'preview.vue');
const userPreviewPageExists = fs.existsSync(userPreviewPage);

this.addTemplate({
fileName: 'prismic/pages/preview.vue',
src: path.join(__dirname, 'templates/pages/preview.vue'),
src: userPreviewPageExists ? userPreviewPage : path.join(__dirname, 'templates/pages/preview.vue'),
});
this.extendRoutes((routes, resolve) => {
routes.unshift({
Expand Down Expand Up @@ -48,7 +52,6 @@ function install(moduleOptions) {
}

// Add templates & prismic plugin
const app = this.options.dir.app || 'app';
const userLinkResolver = path.join(this.options.srcDir, app, 'prismic', 'link-resolver.js');
const userLinkResolverExists = fs.existsSync(userLinkResolver);
const userHtmlSerializer = path.join(this.options.srcDir, app, 'prismic', 'html-serializer.js');
Expand Down

0 comments on commit e797492

Please sign in to comment.