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

myst-templates

Package Overview
Dependencies
Maintainers
3
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 1.0.3 to 1.0.4

49

dist/download.js
import fs, { createWriteStream, mkdirSync } from 'node:fs';
import { dirname, join, parse } from 'node:path';
import { join, parse, sep } from 'node:path';
import { createHash } from 'node:crypto';
import AdmZip from 'adm-zip';
import { glob } from 'glob';
import yaml from 'js-yaml';
import { copyFileMaintainPath, isDirectory } from 'myst-cli-utils';
import { TemplateKind } from 'myst-common';

@@ -104,19 +106,30 @@ import fetch from 'node-fetch';

*/
function unnestTemplate(path) {
async function unnestTemplate(session, path) {
var _a;
const content = fs.readdirSync(path);
if (!content.includes(TEMPLATE_YML)) {
content.forEach((dir) => {
var _a;
const templateYmlFile = join(path, dir, TEMPLATE_YML);
if (fs.existsSync(templateYmlFile)) {
fs.copyFileSync(templateYmlFile, join(path, TEMPLATE_YML));
const templateYml = yaml.load(fs.readFileSync(templateYmlFile).toString());
(_a = templateYml.files) === null || _a === void 0 ? void 0 : _a.forEach((file) => {
const source = join(path, dir, ...file.split('/'));
const dest = join(path, ...file.split('/'));
fs.mkdirSync(dirname(dest), { recursive: true });
fs.copyFileSync(source, dest);
});
}
});
if (content.includes(TEMPLATE_YML))
return;
let nestedPath;
content.forEach((dir) => {
const templateYmlFile = join(path, dir, TEMPLATE_YML);
if (!nestedPath && fs.existsSync(templateYmlFile)) {
nestedPath = join(path, dir);
}
});
if (!nestedPath)
return;
const templateYmlFile = join(nestedPath, TEMPLATE_YML);
fs.copyFileSync(templateYmlFile, join(path, TEMPLATE_YML));
const templateYml = yaml.load(fs.readFileSync(templateYmlFile).toString());
if ((_a = templateYml.files) === null || _a === void 0 ? void 0 : _a.length) {
await Promise.all(templateYml.files.map(async (file) => {
const resolvedEntry = [...nestedPath.split(sep), file].join('/');
const matches = await glob(resolvedEntry);
matches
.map((match) => match.split('/').join(sep))
.filter((match) => !isDirectory(match))
.forEach((match) => {
copyFileMaintainPath(session, match, nestedPath, path);
});
}));
}

@@ -179,3 +192,3 @@ }

zip.extractAllTo(templatePath);
unnestTemplate(templatePath);
await unnestTemplate(session, templatePath);
}

@@ -182,0 +195,0 @@ export async function fetchPublicTemplate(session, name, kind) {

import fs from 'node:fs';
import path from 'node:path';
import { hashAndCopyStaticFile } from 'myst-cli-utils';
import { globSync } from 'glob';
import { hashAndCopyStaticFile, isDirectory } from 'myst-cli-utils';
import { TemplateOptionType } from 'myst-common';

@@ -423,7 +424,9 @@ import { PAGE_FRONTMATTER_KEYS, RESERVED_EXPORT_KEYS, validateAuthor, validateGithubUrl, validateLicenses, validatePageFrontmatter, } from 'myst-frontmatter';

if (file && opts.templateDir) {
const filePath = path.resolve(opts.templateDir, ...file.split('/'));
if (!fs.existsSync(filePath)) {
const filePath = [...opts.templateDir.split(path.sep), file].join('/');
const matches = globSync(filePath).map((match) => match.split('/').join(path.sep));
const files = matches.filter((match) => !isDirectory(match));
if (!matches.length) {
validationError(`file does not exist: ${filePath}`, fileOpts);
}
else if (fs.lstatSync(filePath).isDirectory()) {
else if (!files.length) {
validationError(`file must not be directory: ${filePath}`, fileOpts);

@@ -430,0 +433,0 @@ }

{
"name": "myst-templates",
"version": "1.0.3",
"version": "1.0.4",
"description": "API types and scripts for downloading MyST Templates",

@@ -42,5 +42,6 @@ "author": "Rowan Cockett <rowan@curvenote.com>",

"commander": "^10.0.1",
"glob": "^10.3.1",
"js-yaml": "^4.1.0",
"myst-cli-utils": "^2.0.1",
"myst-common": "^1.0.3",
"myst-cli-utils": "^2.0.2",
"myst-common": "^1.0.4",
"myst-frontmatter": "^1.0.3",

@@ -47,0 +48,0 @@ "node-fetch": "^3.3.1",

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