Skip to content
This repository has been archived by the owner on Dec 9, 2023. It is now read-only.

Commit

Permalink
Fix #10
Browse files Browse the repository at this point in the history
  • Loading branch information
cheap-glitch committed Mar 12, 2020
1 parent 1b44d5a commit a84fd3c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ const fs = require('fs');
const { validateOptions } = require('./src/validation');
const { generateSitemaps } = require('./src/sitemap');

module.exports = async function(api, options)
module.exports = async function(api, vueCliOptions)
{
const options = vueCliOptions ? (vueCliOptions.pluginOptions ? (vueCliOptions.pluginOptions.sitemap || null) : null) : null;

/**
* Add a new command to generate the sitemap
*/
Expand All @@ -42,15 +44,24 @@ module.exports = async function(api, options)
},
async function(args)
{
const cliOptions = { ...options.pluginOptions.sitemap };
if (!options)
{
console.error("Please add in 'vue.config.js' the minimum configuration required for the plugin to work (see https://github.com/cheap-glitch/vue-cli-plugin-sitemap#setup)");
return;
}

// Use the config as the default for the options
const cliOptions = { ...options };
if (args.pretty || args.p)
cliOptions.pretty = true;

await writeSitemap(cliOptions, args['output-dir'] || args.o || options.pluginOptions.sitemap.outputDir || '.');
await writeSitemap(cliOptions, args['output-dir'] || args['o'] || options.outputDir || '.');
}
);

// Do nothing during the build if the config isn't set up
if (!options) return;

/**
* Modify the 'build' command to generate the sitemap automatically
*/
Expand All @@ -61,9 +72,9 @@ module.exports = async function(api, options)
await buildFn(...args);

// Don't generate the sitemap if not in production and the option 'productionOnly' is set
if (options.pluginOptions.sitemap.productionOnly && process.env.NODE_ENV !== 'production') return;
if (options.productionOnly && process.env.NODE_ENV !== 'production') return;

await writeSitemap(options.pluginOptions.sitemap, options.pluginOptions.sitemap.outputDir || options.outputDir || 'dist');
await writeSitemap(options, options.outputDir || vueCliOptions.outputDir || 'dist');
};
}

Expand Down

0 comments on commit a84fd3c

Please sign in to comment.