The code imports necessary functions from the importer module and defines an asynchronous importSheet function that retrieves information from a Google Sheet, including templates, properties, and resources. The function exports the importSheet function as a module, making it available for use in other scripts.
npm run import -- "sheet marketing import"var importer = require('../Core');
var getSheet = importer.import("get sheet purchases");
var getTemplates = importer.import("templates google sheet");
var wrapTemplate = importer.import("output google sheet template");
var getTemplateProperties = importer.import("google sheet template properties");
var collectTemplateResources = importer.import("collect google sheet resources");
var getTemplateByUrl = importer.import("convert sheet helper functions");
async function importSheet(link, domain) {
var properties = {}, templates, key
var match = await getSheet(link, domain)
console.log(match)
domain = domain || match.bucket
templates = await getTemplates(match.sheet)
key = getTemplateByUrl(templates, '/')
await getTemplateProperties(key, properties, templates)
var page = await wrapTemplate('', key, properties[key], properties)
var resources = (await collectTemplateResources(key, page, properties, templates, domain))
.filter((cur, i, arr) => arr.indexOf(cur) == i)
.filter(r => !r.includes(':') && r.includes('.'))
return resources
}
module.exports = importSheet;
const { getSheet, getTemplates, wrapTemplate, getTemplateProperties, collectTemplateResources, getTemplateByUrl } =
require('../Core').import({
'get sheet purchases': async () => ({ sheet: '', bucket: '' }),
templates: 'google sheet',
'output google sheet template': async () => ({}),
'google sheet template properties': async () => ({}),
'collect google sheet resources': async () => ({}),
'convert sheet helper functions': async () => ({}),
});
async function importSheet(link, domain = '') {
if (!link) {
throw new Error('Link is required');
}
const { sheet, bucket } = await getSheet(link, domain);
domain = domain || bucket;
const templates = await getTemplates(sheet);
const key = getTemplateByUrl(templates, '/');
if (!key) {
throw new Error('Template not found');
}
await getTemplateProperties(key, {}, templates);
const page = await wrapTemplate('', key, {}, {});
const resources = await collectTemplateResources(key, page, {}, templates, domain);
const uniqueResources = [...new Set(resources.map(String))];
const filteredResources = uniqueResources.filter((resource) => {
if (!resource.includes(':')) {
return resource.includes('.');
}
return false;
});
return filteredResources;
}
module.exports = importSheet;var importer = require('../Core');: Imports the importer from the ../Core module.importer.import() functions are used to import specific functions from the importer module:
getSheetgetTemplateswrapTemplategetTemplatePropertiescollectTemplateResourcesgetTemplateByUrlimportSheet Functionasync function importSheet(link, domain) {... }: An asynchronous function that takes two parameters: link and domain.var properties = {}, templates, key: Initializes three variables: properties (an object), templates, and key.var match = await getSheet(link, domain): Calls the getSheet function with link and domain as arguments and stores the result in match.domain = domain || match.bucket: Sets domain to the provided value if it's truthy, otherwise sets it to match.bucket.templates = await getTemplates(match.sheet): Calls the getTemplates function with match.sheet as an argument and stores the result in templates.key = getTemplateByUrl(templates, '/'): Calls the getTemplateByUrl function with templates and '/' as arguments and stores the result in key.await getTemplateProperties(key, properties, templates): Calls the getTemplateProperties function with key, properties, and templates as arguments.var page = await wrapTemplate('', key, properties[key], properties): Calls the wrapTemplate function with an empty string, key, properties[key], and properties as arguments and stores the result in page.var resources = (await collectTemplateResources(key, page, properties, templates, domain))...: Calls the collectTemplateResources function with various arguments and stores the result in resources. The result is then filtered to remove duplicates and resources with certain conditions.module.exports = importSheet;: Exports the importSheet function as a module.