How to use the path.parse function in path

To help you get started, we’ve selected a few path examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MaartenDesnouck / google-apps-script / lib / functions / unpackRemote.js View on Github external
name: local,
        source: data,
    });

    // Sync create all necessary files
    for (const remoteFile of remoteFiles) {
        createFile(remoteFile);
    }

    // If there was no file specified to pull we will do a cleanup
    if (!fileName) {
        // Remove all .gs, .js, .html and appsscript.json files that were not in remote.json unless they are in .gasignore
        const toDelete = [];
        for (const localFileName of localFiles) {
            const localExtension = path.parse(localFileName).ext;
            const fileNameWithoutExtension = path.join(path.parse(localFileName).dir, path.parse(localFileName).name);
            if (eaft.isPushable(localExtension, fileNameWithoutExtension, extensions, ignoreRegexes) &&
                !remoteNames.includes(localFileName) && localFileName !== constants.INCLUDE_FILE) {
                toDelete.push(path.join(rootFolder, localFileName));
            }
        }

        // Delete files
        for (const fileToDelete of toDelete) {
            fs.removeSync(fileToDelete);
        }

        // Remove all empty folders
        const allFolders = getAllFolders(rootFolder).sort().reverse();
        for (const emptyFolder of allFolders) {
            const files = fs.readdirSync(emptyFolder);
            if (files.length === 0) {
github keystonejs / keystone-classic / website / gatsby-node.js View on Github external
exports.onCreateNode = (
	{ node, boundActionCreators, getNode } /* : NodeParams */
) => {
	const { createNodeField } = boundActionCreators;


	if (node.internal.type === 'MarkdownRemark') {
		const fileNode = getNode(node.parent);

		const parsedFilePath = path.parse(fileNode.relativePath);
		let section = parsedFilePath.dir;
		let slug;

		if (
			parsedFilePath.name.match(/Readme/i)
			&& fileNode.dir.match(/\/fields\/types\//)
		) {
			section = 'api/field'; // fake the path for slug consistency
			slug = `/${section}/${kebabify(parsedFilePath.dir)}`;
		} else {
			if (parsedFilePath.name === 'index') {
				slug = `/${kebabify(parsedFilePath.dir)}`;
			} else {
				slug = `/${kebabify(parsedFilePath.dir)}/${kebabify(
					parsedFilePath.name
				)}`;
github akaJes / marlin-config / app / mc-tool.js View on Github external
module.exports.updateH=(root,file,json)=>{
    var h=inFile(file);
    return h
    .then(mc.h2json)
    .then(addNumber)
    .then(loadConfig(Promise.resolve(json)))
    .then(onlyChanged)
    .then(extendFrom(h))
    .then(array2text)
    .then(outFile(path.join(root,'Marlin',path.parse(file).base)))
    .then(a=>(console.log('updated h: ',path.relative(root,file)),a))
    .catch(a=>{ console.log('fail h: ',file,a); throw a;})
}
github huan / file-box / src / file-box.ts View on Github external
public static fromFile (
    path:   string,
    name?:  string,
  ): FileBox {
    if (!name) {
      name = nodePath.parse(path).base
    }
    const options: FileBoxOptions = {
      name,
      path,
      type : FileBoxType.File,
    }

    return new FileBox(options)
  }
github VirgilSecurity / virgil-e3kit-js / packages / e3kit / prepare.js View on Github external
sources.forEach(src => {
        const dest = path.join(outputPath, path.parse(src).base);
        fs.copyFileSync(src, dest);
    });
};
github mjmlio / mjml / packages / mjml-cli / src / client.js View on Github external
const outputFileName = (input, output) => {
  const outputIsDirectory = isDirectory(output)
  const { ext, name } = path.parse((!output || outputIsDirectory) ? input : output)
  let dir = outputIsDirectory ? output : './'

  if (output && !outputIsDirectory) {
    const { dir: outDir } = path.parse(output)
    dir = outDir == '' ? dir : outDir
  }

  return path.format({
    dir: dir,
    name: name.replace('.mjml', ''),
    ext: ext == ".mjml" ? '.html' : ext
  })
}
github facebook / relay / packages / react-relay / classic / tools / __mocks__ / getGoldenMatchers.js View on Github external
const fixtureInfo = fs.readdirSync(absoluteFixtures).map(file => {
        const {ext, name: nameWithType} = path.parse(file);
        const {ext: type, name} = path.parse(nameWithType);
        const fixture = path.join(absoluteFixtures, file);
        invariant(
          ext !== '' && (type === '.input' || type === '.golden'),
          `toMatchGolden: "${file}" must be named ` +
            '"*.input.$EXTENSION" or "*.golden.$EXTENSION".',
        );
        invariant(
          fs.statSync(fixture).isFile(),
          `toMatchGolden: "${file}" must be a regular file.`,
        );
        return {
          ext: ext.slice(1),
          fixture,
          name,
          type: type.slice(1),
github Turfjs / turf / packages / turf-polygonize / bench.js View on Github external
const fixtures = fs.readdirSync(directory).map(filename => {
    return {
        name: path.parse(filename).name,
        geojson: load.sync(directory + filename)
    };
});
github badgen / badgen.net / libs / icons.js View on Github external
fs.readdirSync(join(__dirname, iconFolder)).forEach(filename => {
    const imageType = {
      '.svg': 'svg+xml',
      '.png': 'png'
    }[parse(filename).ext]

    if (!imageType) return

    const key = parse(filename).name
    const iconFile = join(__dirname, iconFolder, filename)
    const svgSource = fs.readFileSync(iconFile, 'utf8')
    const svg = whiten ? whitenSVG(svgSource) : svgSource
    const b64 = Buffer.from(svg).toString('base64')

    icons[key] = `data:image/${imageType};base64,${b64}`
  })