Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function pack (pluginName) {
const pluginDirectory = path.join(__dirname, 'plugins', pluginName)
const packageSrc = path.join(__dirname, 'plugin-template/package.json')
const packageDst = path.join(pluginDirectory, 'package.json')
const setupSrc = path.join(__dirname, 'plugin-template/setup.js')
const setupDst = path.join(pluginDirectory, 'setup.js')
fse.ensureDir(pluginDirectory, (error) => {
if (error) { return console.error(error) }
async.parallel([
// create special directories
(next) => {
createPluginSpecialDirectories(pluginName, next)
},
// copy package.json
(next) => {
fse.pathExists(packageDst, (error, exists) => {
if (error || exists) { return next(error) }
return fse.copy(packageSrc, packageDst, next)
})
},
// copy setup.js
(next) => {
fse.pathExists(setupDst, (error, exists) => {
downloadUrl,
icon
} = modelInfo;
const nameResult = name.match(/#([\d]+)\s([\w\.\s♀♂]+)/);
const realName = nameResult[2];
const modelNum = nameResult[1];
const exportPath = `models/${modelNum}/`;
// copy icon
if (! await fs.pathExists(`${exportPath}icon.png`)){
await fs.copy(`origin_models/${name}/icon.png`, `${exportPath}icon.png`);
}
const exportGLTFPath = `models/${modelNum}/glTF/`;
await fs.ensureDir(`${exportGLTFPath}`);
if (! await fs.pathExists(`${exportGLTFPath}model.gltf`)){
const convertPath = `${exportGLTFPath}origin.gltf`;
const amcPath = `${exportGLTFPath}model.gltf`;
// blender convert
if (! await fs.pathExists(convertPath)) {
const modelPath = (await getModelPath(name)).replace(/#/g, '\\#').replace(/ /g, '\\ ');
if (!modelPath) {
console.log(`No model called ${name}`.warn);
return;
}
const cmd = `${blenderPath} -b -P ${pythonPath} -- ${modelPath} ${convertPath}`;
console.log(`convertStart: ${modelNum}`);
await execa.shell(cmd);
const create = async (options: Object) => {
const { src } = options;
if (!src) {
throw Error(`Cannot create file, "src" is missing.`);
}
const pwd: string = (process.env.PWD: any);
const paths = {
url: `/files/`,
folder: `${pwd}/static/`
};
fs.ensureDir(paths.folder);
let { buffer, type } = decodeBase64Src(options.src);
// If we are dealing with an image, compress it.
if (supportedImageTypes.includes(type)) {
const image = await compressImage({ buffer, type });
buffer = image.buffer;
type = image.type;
}
// Generate unique filename.
const extension: string = mime.extension(type);
let name = filenameWithoutExtension(options.name);
name += name ? "_" : "";
name += `${uniqueId()}.${extension}`;
name = sanitizeFilename(name);
const createConfig: CreateConfig = async ({ directory, fileName, reporter }) => {
// file name & location
const pathToFile = path.join(directory, fileName)
const { dir } = path.parse(pathToFile)
await fs.ensureDir(dir)
return async (schema) => {
// documents
const docPromises = [
'./src/**/*.{ts,tsx}',
'./node_modules/gatsby-*/**/*.js',
].map(async docGlob => {
const _docGlob = path.join(directory, docGlob)
return loadDocuments(_docGlob).catch(err => {
reporter.warn('[gatsby-plugin-graphql-codegen] ' + err.message)
})
})
const results = await Promise.all(docPromises)
const documents = results.reduce((acc, cur) => {
if (!cur) return acc
return (acc as DocumentFile[]).concat(cur)
private async createDirectoriesAsync() {
try {
await Promise.all([
fs.ensureDir(this._config.contentDirectory),
fs.ensureDir(this._config.dataDirectory)
]);
} catch (e) { /* Do nothing */ }
}
async _renderTemplateFiles(data, currentPath, outPath) {
logger.log(`Creating output directory "${outPath}"`);
await fs.ensureDir(outPath);
logger.log(`Reading template directory "${this.path}"`);
return Promise.all(fs.readdirSync(currentPath).map(async (templateFile) => {
const templateFilePath = path.resolve(currentPath, templateFile);
logger.log(`Checking if "${templateFile}" is a directory`);
const templateFileStat = fs.lstatSync(templateFilePath);
const isDirectory = templateFileStat.isDirectory();
if (isDirectory) {
const subDirectoryOutPath = path.resolve(outPath, templateFile);
// Recursive call to render all subdirectory files
return this._renderTemplateFiles(data, templateFilePath, subDirectoryOutPath);
} else if (!templateFileStat.isFile()) {
return;
}
// Removes the ".mustache" suffix
async function downloadSource() {
await fs.remove(temp);
await fs.ensureDir(temp),
console.log(`Downloading: '${downloadUrl}'`);
await download(downloadUrl, temp)
console.log(`Unzipping to '${path.join(temp, fileName.replace(/\.zip$/, ''))}'...`);
fs.createReadStream(path.join(temp, fileName))
.pipe(unzipper.Extract({ path: temp }))
console.log('Done unzipping!');
}
function makeOutputFilePath(filePath, cb) {
const dir = path.dirname(filePath);
fs.ensureDir(dir, (err) => {
if (err) {
log.error(`Unable to setup directory for ${filePath}. File will not be written.`);
log.error(err);
} else {
cb(filePath);
}
});
return filePath;
}
async before() {
this.options.build.plugins.unshift(new webpack.IgnorePlugin(/\.md$/));
const pagesDir = join(this.options.srcDir, this.options.dir.pages);
if (!exists(pagesDir)) {
this.$press.$placeholderPagesDir = pagesDir;
await fsExtra.ensureDir(pagesDir);
}
},
async compile() {
async run(log: LogString) {
try {
log(`Validating starter config`);
const config = await validateConfig(this.starterDir);
await fs.ensureDir(this.dest);
await copyFiles(config, log, this.starterDir, this.dest);
await updateVersions(config, log, this.dest, this.adaptVersion);
await runScripts(config, log, this.starterDir, this.dest, this.args);
} catch (err) {
err = ensureError(err);
throw new SpecError(this.spec, err.message);
}
}