How to use the upath.basename function in upath

To help you get started, we’ve selected a few upath 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 pixelnest / presskit.html / lib / core / generator.js View on Github external
async function copyMandatoryFiles () {
  const buildDir = createAndGetBuildFolder()

  for (const f of assetsToCopy) {
    const filepath = path.resolve(f)

    // Get filename and dirname from the provided path.
    const filename = path.basename(filepath)
    const dirname = path.basename(path.dirname(filepath))

    // Create the directory for this file if needed.
    // ie. css/master.css needs a `css` directory.
    const targetDir = path.join(buildDir, dirname)
    sfs.createDir(targetDir)

    // And copy the file.
    const targetPath = path.join(targetDir, filename)

    console.log('- ' + targetPath)
    try {
      await writeFilePromised(targetPath, await readFilePromised(filepath))
    } catch (e) {
      const msg = chalk.dim(`(${e.message})`)
      console.error(`There was an error while copying ${chalk.bold(filename)}. ${msg}`)
    }
github ryanelian / instapack / src / SassBuildTool.ts View on Github external
css: cleanResult.styles
        };

        if (this.variables.sourceMap && postcssResult.map && cleanResult.sourceMap) {
            const sm3: RawSourceMap = cleanResult.sourceMap.toJSON();
            sm3.sources[0] = '/(intermediate)/(postcss-output).css';
            sm3.file = upath.basename(cssOutputPath);

            // console.log(sm3.sources);
            // console.log(sm3.file);

            result.map = mergeSourceMap(postcssResult.map, sm3);
            // console.log(result.map.sources);
            // console.log(result.map.file);

            const sourceMapFileName = upath.basename(cssOutputPath) + '.map';
            result.css += `\n/*# sourceMappingURL=${sourceMapFileName} */`;
        }

        return result;
    }
github ryanelian / instapack / src / SassBuildTool.ts View on Github external
const cleanResult = new CleanCSS(cleanCssOptions).minify(postcssResult.css);
        const errors: Error[] = cleanResult.errors;
        if (errors.length) {
            const errorMessage = "Error when minifying CSS:\n" + errors.map(Q => '- ' + Q.toString()).join("\n");
            throw new Error(errorMessage);
        }

        const result: CssBuildResult = {
            css: cleanResult.styles
        };

        if (this.variables.sourceMap && postcssResult.map && cleanResult.sourceMap) {
            const sm3: RawSourceMap = cleanResult.sourceMap.toJSON();
            sm3.sources[0] = '/(intermediate)/(postcss-output).css';
            sm3.file = upath.basename(cssOutputPath);

            // console.log(sm3.sources);
            // console.log(sm3.file);

            result.map = mergeSourceMap(postcssResult.map, sm3);
            // console.log(result.map.sources);
            // console.log(result.map.file);

            const sourceMapFileName = upath.basename(cssOutputPath) + '.map';
            result.css += `\n/*# sourceMappingURL=${sourceMapFileName} */`;
        }

        return result;
    }
github pixelnest / presskit.html / lib / core / builder.js View on Github external
function getPageFolder (buildFolder, dataFilePath, pageType) {
  // Logic:
  // - Company page should be placed in the root folder.
  // - But each product page is a subfolder.

  // If it's not a company page, it means that the page is in a subfolder.
  if (pageType !== 'company') {
    const productFolderName = path.basename(path.dirname(dataFilePath))
    const subfolder = path.join(buildFolder, productFolderName)
    return subfolder
  }

  // Company's page? It's simply the build folder!
  return buildFolder
}
github pingyhq / pingy-cli / packages / compile / lib / baby-tolk.js View on Github external
const dontCompile = function(pathName) {
  // Baby Tolk wont compile files that begin with an underscore `_`.
  // This is by convention.
  const baseName = Path.basename(pathName);
  return baseName[0] === '_';
};
github ryanelian / instapack / src / SassImportResolver.ts View on Github external
export async function sassImport(source: string, request: string): Promise {
    // https://github.com/ryanelian/instapack/issues/99
    // source               :   "E:/VS/MyProject/client/css/index.scss"
    // request / @import    :   "@ryan/something"

    const lookupStartPath = upath.dirname(source);        // E:/VS/MyProject/client/css/
    const requestFileName = upath.basename(request);      // something
    const requestDir = upath.dirname(request);            // @ryan/

    if (requestFileName.startsWith('_') === false) {
        const partialFolderLookups = [lookupStartPath];
        if (requestDir !== '.') {
            // upath.dirname('test') === '.'
            // upath.dirname('test/') === '.' && upath.basename('test/') === 'test'
            // @import 'test' must not be resolved into /node_modules/_test.scss
            partialFolderLookups.push('node_modules');
        }

        const partialSassResolver = ResolverFactory.createResolver({
            fileSystem: fs,
            extensions: ['.scss'],
            modules: partialFolderLookups,
            mainFiles: [],
github upash / peco / lib / engine / create-app-template.js View on Github external
const pathToId = file => {
  return path.basename(file).replace(/[^a-zA-Z0-9_]/g, '_')
}
github ryanelian / instapack / bin / SassBuildTool.js View on Github external
sourceMap: this.variables.sourceMap,
            sourceMapInlineSources: this.variables.sourceMap
        };
        const cleanResult = new CleanCSS(cleanCssOptions).minify(postcssResult.css);
        const errors = cleanResult.errors;
        if (errors.length) {
            const errorMessage = "Error when minifying CSS:\n" + errors.map(Q => '- ' + Q.toString()).join("\n");
            throw new Error(errorMessage);
        }
        const result = {
            css: cleanResult.styles
        };
        if (this.variables.sourceMap && postcssResult.map && cleanResult.sourceMap) {
            const sm3 = cleanResult.sourceMap.toJSON();
            sm3.sources[0] = '/(intermediate)/(postcss-output).css';
            sm3.file = upath.basename(cssOutputPath);
            result.map = mergeSourceMap(postcssResult.map, sm3);
            const sourceMapFileName = upath.basename(cssOutputPath) + '.map';
            result.css += `\n/*# sourceMappingURL=${sourceMapFileName} */`;
        }
        return result;
    }
    build() {
github ryanelian / instapack / src / SassBuildTool.ts View on Github external
fixSassGeneratedSourceMap(sm: RawSourceMap): void {
        const folder = upath.basename(this.virtualSassOutputFilePath);
        sm.sources = sm.sources.map(s => {
            const absolute = upath.join(folder, s);
            return '/' + upath.relative(this.finder.root, absolute);
        });
    }

upath

A proxy to `path`, replacing `\` with `/` for all results (supports UNC paths) & new methods to normalize & join keeping leading `./` and add, change, default, trim file extensions.

MIT
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis