Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

myst-templates

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

myst-templates - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

33

dist/cjs/download.js

@@ -57,22 +57,30 @@ "use strict";

const TEMPLATE_REGEX = /^[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+$/;
const FULL_TEMPLATE_REGEX = /^(site|tex|docx)\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+$/;
function normalizeTemplateName(opts) {
var _a;
const { template } = opts;
const kind = (_a = opts.kind) !== null && _a !== void 0 ? _a : myst_common_1.TemplateKind.tex;
if (!template) {
const kind = opts.kind;
if (!template && kind) {
return DEFAULT_TEMPLATES[kind];
}
if (template.match(PARTIAL_TEMPLATE_REGEX)) {
if ((template === null || template === void 0 ? void 0 : template.match(PARTIAL_TEMPLATE_REGEX)) && kind) {
return `${kind}/myst/${template}`;
}
if (template.match(TEMPLATE_REGEX)) {
if ((template === null || template === void 0 ? void 0 : template.match(TEMPLATE_REGEX)) && kind) {
return `${kind}/${template}`;
}
return undefined;
if (template === null || template === void 0 ? void 0 : template.match(FULL_TEMPLATE_REGEX)) {
return template;
}
if (!template || !kind)
throw new Error('You must specify a template kind, for example, "--tex"');
return template;
}
function templatesUrl(session) {
return `${session.API_URL}/templates`;
}
function listingUrl(session, kind) {
return `${session.API_URL}/templates/${kind !== null && kind !== void 0 ? kind : myst_common_1.TemplateKind.tex}`;
return `${templatesUrl(session)}/${kind !== null && kind !== void 0 ? kind : myst_common_1.TemplateKind.tex}`;
}
function defaultUrl(session, template) {
return `${session.API_URL}/templates/${template}`;
return `${templatesUrl(session)}/${template}`;
}

@@ -179,3 +187,3 @@ function defaultPath(template, hash, opts) {

const { templateUrl } = opts;
session.log.info(`🐕 Fetching template metadata from ${templateUrl}`);
session.log.info(`🔍 Querying template metadata from ${templateUrl}`);
const resLink = yield (0, node_fetch_1.default)(templateUrl);

@@ -235,5 +243,5 @@ if (!resLink.ok) {

return __awaiter(this, void 0, void 0, function* () {
const url = listingUrl(session);
session.log.debug('Fetching template listing information');
const url = templatesUrl(session);
const templateUrl = `${url}/${normalizeTemplateName({ template: name, kind })}`;
session.log.debug(`Fetching template listing information from ${templateUrl}`);
const resLink = yield (0, node_fetch_1.default)(templateUrl);

@@ -249,2 +257,5 @@ if (!resLink.ok) {

return __awaiter(this, void 0, void 0, function* () {
if (Array.isArray(kind)) {
return (yield Promise.all(kind.map((k) => listPublicTemplates(session, k)))).flat();
}
const url = listingUrl(session, kind);

@@ -251,0 +262,0 @@ session.log.debug('Fetching template listing information');

@@ -124,6 +124,12 @@ "use strict";

else {
yield (0, download_1.downloadTemplate)(this.session, {
templatePath: this.templatePath,
templateUrl: this.templateUrl,
});
try {
yield (0, download_1.downloadTemplate)(this.session, {
templatePath: this.templatePath,
templateUrl: this.templateUrl,
});
}
catch (error) {
this.session.log.debug(`\n\n${error === null || error === void 0 ? void 0 : error.stack}\n\n`);
throw new Error(`${error.message}\n\nTo list valid templates, try the command "myst templates list"`);
}
}

@@ -130,0 +136,0 @@ });

@@ -28,22 +28,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

const TEMPLATE_REGEX = /^[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+$/;
const FULL_TEMPLATE_REGEX = /^(site|tex|docx)\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+$/;
function normalizeTemplateName(opts) {
var _a;
const { template } = opts;
const kind = (_a = opts.kind) !== null && _a !== void 0 ? _a : TemplateKind.tex;
if (!template) {
const kind = opts.kind;
if (!template && kind) {
return DEFAULT_TEMPLATES[kind];
}
if (template.match(PARTIAL_TEMPLATE_REGEX)) {
if ((template === null || template === void 0 ? void 0 : template.match(PARTIAL_TEMPLATE_REGEX)) && kind) {
return `${kind}/myst/${template}`;
}
if (template.match(TEMPLATE_REGEX)) {
if ((template === null || template === void 0 ? void 0 : template.match(TEMPLATE_REGEX)) && kind) {
return `${kind}/${template}`;
}
return undefined;
if (template === null || template === void 0 ? void 0 : template.match(FULL_TEMPLATE_REGEX)) {
return template;
}
if (!template || !kind)
throw new Error('You must specify a template kind, for example, "--tex"');
return template;
}
function templatesUrl(session) {
return `${session.API_URL}/templates`;
}
function listingUrl(session, kind) {
return `${session.API_URL}/templates/${kind !== null && kind !== void 0 ? kind : TemplateKind.tex}`;
return `${templatesUrl(session)}/${kind !== null && kind !== void 0 ? kind : TemplateKind.tex}`;
}
function defaultUrl(session, template) {
return `${session.API_URL}/templates/${template}`;
return `${templatesUrl(session)}/${template}`;
}

@@ -148,3 +156,3 @@ function defaultPath(template, hash, opts) {

const { templateUrl } = opts;
session.log.info(`🐕 Fetching template metadata from ${templateUrl}`);
session.log.info(`🔍 Querying template metadata from ${templateUrl}`);
const resLink = yield fetch(templateUrl);

@@ -201,5 +209,5 @@ if (!resLink.ok) {

return __awaiter(this, void 0, void 0, function* () {
const url = listingUrl(session);
session.log.debug('Fetching template listing information');
const url = templatesUrl(session);
const templateUrl = `${url}/${normalizeTemplateName({ template: name, kind })}`;
session.log.debug(`Fetching template listing information from ${templateUrl}`);
const resLink = yield fetch(templateUrl);

@@ -214,2 +222,5 @@ if (!resLink.ok) {

return __awaiter(this, void 0, void 0, function* () {
if (Array.isArray(kind)) {
return (yield Promise.all(kind.map((k) => listPublicTemplates(session, k)))).flat();
}
const url = listingUrl(session, kind);

@@ -216,0 +227,0 @@ session.log.debug('Fetching template listing information');

@@ -119,6 +119,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

else {
yield downloadTemplate(this.session, {
templatePath: this.templatePath,
templateUrl: this.templateUrl,
});
try {
yield downloadTemplate(this.session, {
templatePath: this.templatePath,
templateUrl: this.templateUrl,
});
}
catch (error) {
this.session.log.debug(`\n\n${error === null || error === void 0 ? void 0 : error.stack}\n\n`);
throw new Error(`${error.message}\n\nTo list valid templates, try the command "myst templates list"`);
}
}

@@ -125,0 +131,0 @@ });

@@ -31,3 +31,3 @@ import { TemplateKind } from 'myst-common';

export declare function fetchPublicTemplate(session: ISession, name: string, kind?: TemplateKind): Promise<TemplateYmlResponse>;
export declare function listPublicTemplates(session: ISession, kind?: TemplateKind): Promise<TemplateYmlListResponse['items']>;
export declare function listPublicTemplates(session: ISession, kind?: TemplateKind | TemplateKind[]): Promise<TemplateYmlListResponse['items']>;
//# sourceMappingURL=download.d.ts.map
{
"name": "myst-templates",
"version": "0.1.3",
"description": "API types and scripts for downloading MyST Tempaltes",
"version": "0.1.4",
"description": "API types and scripts for downloading MyST Templates",
"author": "Rowan Cockett <rowan@curvenote.com>",

@@ -49,7 +49,6 @@ "homepage": "https://github.com/executablebooks/mystjs/tree/main/packages/myst-templates",

"commander": "^8.3.0",
"crypto": "^1.0.1",
"js-yaml": "^4.1.0",
"myst-cli-utils": "^0.0.9",
"myst-cli-utils": "^0.0.10",
"myst-common": "^0.0.12",
"myst-frontmatter": "^0.0.5",
"myst-frontmatter": "^0.0.6",
"node-fetch": "^2.6.7",

@@ -56,0 +55,0 @@ "pretty-hrtime": "^1.0.3",

@@ -23,24 +23,33 @@ import fs, { createReadStream, createWriteStream, mkdirSync } from 'fs';

const TEMPLATE_REGEX = /^[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+$/;
const FULL_TEMPLATE_REGEX = /^(site|tex|docx)\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-]+$/;
function normalizeTemplateName(opts: { kind?: TemplateKind; template?: string }) {
const { template } = opts;
const kind = opts.kind ?? TemplateKind.tex;
if (!template) {
const kind = opts.kind;
if (!template && kind) {
return DEFAULT_TEMPLATES[kind];
}
if (template.match(PARTIAL_TEMPLATE_REGEX)) {
if (template?.match(PARTIAL_TEMPLATE_REGEX) && kind) {
return `${kind}/myst/${template}`;
}
if (template.match(TEMPLATE_REGEX)) {
if (template?.match(TEMPLATE_REGEX) && kind) {
return `${kind}/${template}`;
}
return undefined;
if (template?.match(FULL_TEMPLATE_REGEX)) {
return template;
}
if (!template || !kind) throw new Error('You must specify a template kind, for example, "--tex"');
return template;
}
function templatesUrl(session: ISession) {
return `${session.API_URL}/templates`;
}
function listingUrl(session: ISession, kind?: TemplateKind) {
return `${session.API_URL}/templates/${kind ?? TemplateKind.tex}`;
return `${templatesUrl(session)}/${kind ?? TemplateKind.tex}`;
}
function defaultUrl(session: ISession, template: string) {
return `${session.API_URL}/templates/${template}`;
return `${templatesUrl(session)}/${template}`;
}

@@ -152,3 +161,3 @@

const { templateUrl } = opts;
session.log.info(`🐕 Fetching template metadata from ${templateUrl}`);
session.log.info(`🔍 Querying template metadata from ${templateUrl}`);
const resLink = await fetch(templateUrl);

@@ -216,5 +225,5 @@ if (!resLink.ok) {

export async function fetchPublicTemplate(session: ISession, name: string, kind?: TemplateKind) {
const url = listingUrl(session);
session.log.debug('Fetching template listing information');
const url = templatesUrl(session);
const templateUrl = `${url}/${normalizeTemplateName({ template: name, kind })}`;
session.log.debug(`Fetching template listing information from ${templateUrl}`);
const resLink = await fetch(templateUrl);

@@ -231,4 +240,7 @@ if (!resLink.ok) {

session: ISession,
kind?: TemplateKind,
kind?: TemplateKind | TemplateKind[],
): Promise<TemplateYmlListResponse['items']> {
if (Array.isArray(kind)) {
return (await Promise.all(kind.map((k) => listPublicTemplates(session, k)))).flat();
}
const url = listingUrl(session, kind);

@@ -235,0 +247,0 @@ session.log.debug('Fetching template listing information');

@@ -151,6 +151,15 @@ import fs from 'fs';

} else {
await downloadTemplate(this.session, {
templatePath: this.templatePath,
templateUrl: this.templateUrl,
});
try {
await downloadTemplate(this.session, {
templatePath: this.templatePath,
templateUrl: this.templateUrl,
});
} catch (error) {
this.session.log.debug(`\n\n${(error as Error)?.stack}\n\n`);
throw new Error(
`${
(error as Error).message
}\n\nTo list valid templates, try the command "myst templates list"`,
);
}
}

@@ -157,0 +166,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc