How to use the canonical-path.relative function in canonical-path

To help you get started, we’ve selected a few canonical-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 angular / angular / aio / tools / stackblitz-builder / builder.js View on Github external
var extn = path.extname(fileName);
      if (extn == '.png') {
        content = this._encodeBase64(fileName);
        fileName = fileName.substr(0, fileName.length - 4) + '.base64.png'
      } else {
        content = fs.readFileSync(fileName, 'utf-8');
      }

      if (extn == '.js' || extn == '.ts' || extn == '.css') {
        content = content + this.copyrights.jsCss;
      } else if (extn == '.html') {
        content = content + this.copyrights.html;
      }
      // var escapedValue = escapeHtml(content);

      var relativeFileName = path.relative(config.basePath, fileName);

      // Is the main a custom index-xxx.html file? Rename it
      if (relativeFileName == config.main) {
        relativeFileName = 'src/index.html';
      }

      // A custom main.ts file? Rename it
      if (/src\/main[-.]\w+\.ts$/.test(relativeFileName)) {
        relativeFileName = 'src/main.ts'
      }

      if (relativeFileName == 'index.html') {
        if (config.description == null) {
          // set config.description to title from index.html
          var matches = /<title>(.*)&lt;\/title&gt;/.exec(content);
          if (matches) {</title>
github angular / angular / aio / tools / stackblitz-builder / builder.js View on Github external
_buildStackblitzFrom(configFileName) {
    // replace ending 'stackblitz.json' with 'stackblitz.no-link.html' to create output file name;
    var outputFileName = `stackblitz.no-link.html`;
    outputFileName = configFileName.replace(/stackblitz\.json$/, outputFileName);
    var altFileName;
    if (this.destPath && this.destPath.length > 0) {
      var partPath = path.dirname(path.relative(this.basePath, outputFileName));
      var altFileName = path.join(this.destPath, partPath, path.basename(outputFileName)).replace('.no-link.', '.');
    }
    try {
      var config = this._initConfigAndCollectFileNames(configFileName);
      var postData = this._createPostData(config, configFileName);
      this._addDependencies(postData);
      var html = this._createStackblitzHtml(config, postData);
      fs.writeFileSync(outputFileName, html, 'utf-8');
      if (altFileName) {
        var altDirName = path.dirname(altFileName);
        fs.ensureDirSync(altDirName);
        fs.writeFileSync(altFileName, html, 'utf-8');
      }
    } catch (e) {
      // if we fail delete the outputFile if it exists because it is an old one.
      if (this._existsSync(outputFileName)) {
github angular / angular / aio / tools / ng-packages-installer / index.js View on Github external
_printWarning() {
    const relativeScriptPath = path.relative('.', __filename.replace(/\.js$/, ''));
    const absoluteProjectDir = path.resolve(this.projectDir);
    const restoreCmd = `node ${relativeScriptPath} restore ${absoluteProjectDir}`;

    // Log a warning.
    this._warn([
      `The project at "${absoluteProjectDir}" is running against the local Angular build.`,
      '',
      'To restore the npm packages run:',
      '',
      `  "${restoreCmd}"`,
    ].join('\n'));
  }
github angular / angular / docs / links-package / services / getLinkInfo.js View on Github external
linkInfo.valid = false;
      linkInfo.errorType = 'ambiguous';
      linkInfo.error = 'Ambiguous link: "' + url + '".\n' +
        docs.reduce(function(msg, doc) { return msg + '\n  "' + doc.id + '" ('+ doc.docType + ') : (' + doc.path + ' / ' + doc.fileInfo.relativePath + ')'; }, 'Matching docs: ');

    } else if ( docs.length >= 1 ) {

      linkInfo.url = docs[0].path;
      linkInfo.title = title || encodeCodeBlock(docs[0].name, true);
      linkInfo.type = 'doc';

      if ( getLinkInfoImpl.relativeLinks && currentDoc && currentDoc.path ) {
        var currentFolder = path.dirname(currentDoc.path);
        var docFolder = path.dirname(linkInfo.url);
        var relativeFolder = path.relative(path.join('/', currentFolder), path.join('/', docFolder));
        linkInfo.url = path.join(relativeFolder, path.basename(linkInfo.url));
        log.debug(currentDoc.path, docs[0].path, linkInfo.url);
      }

    } else if ( url.indexOf('#') > 0 ) {
      var pathAndHash = url.split('#');
      linkInfo = getLinkInfoImpl(pathAndHash[0], title, currentDoc);
      linkInfo.url = linkInfo.url + '#' + pathAndHash[1];
      return linkInfo;

    } else if ( url.indexOf('/') === -1 && url.indexOf('#') !== 0 ) {

      linkInfo.valid = false;
      linkInfo.errorType = 'missing';
      linkInfo.error = 'Invalid link (does not match any doc): "' + url + '"';
github angular / dgeni-packages / typescript / src / services / TsParser / getFileInfo.ts View on Github external
export function getFileInfo(symbol: Symbol, basePath: string) {
  const fileName = symbol.declarations![0].getSourceFile().fileName;
  const file = path.resolve(basePath, fileName);
  return {
    filePath: file,
    baseName: path.basename(file, path.extname(file)),
    extension: path.extname(file).replace(/^\./, ''),
    basePath: basePath,
    relativePath: fileName,
    projectRelativePath: path.relative(basePath, file)
  };
}
github angular / dgeni-packages / jsdoc / processors / extractJSDocComments.spec.js View on Github external
var createFileInfo = function(file, content, basePath) {
    return {
      filePath: file,
      baseName: path.basename(file, path.extname(file)),
      extension: path.extname(file).replace(/^\./, ''),
      basePath: basePath,
      relativePath: path.relative(basePath, file),
      content: content,
      ast: jsParser(content),
    };
  };
github angular / angular / aio / tools / transforms / content-package / readers / content.spec.js View on Github external
var createFileInfo = function(file, content, basePath) {
    return {
      fileReader: fileReader.name,
      filePath: file,
      baseName: path.basename(file, path.extname(file)),
      extension: path.extname(file).replace(/^\./, ''),
      basePath: basePath,
      relativePath: path.relative(basePath, file),
      content: content
    };
  };
github jaredhanson / electrolyte / lib / container.js View on Github external
Container.prototype._loadComponent = function(id, cb) {
  debug('autoload %s', id);
  var order = this._order
    , asm, comp, rid
    , i, len;
  
  for (i = 0, len = order.length; i &lt; len; ++i) {
    asm = this._assemblies[order[i]];
    rid = path.relative(asm.namespace, id);
    if (rid.indexOf('../') == 0) { continue; }
    comp = asm.load(id);
  
    if (comp) {
      spec = this._registerComponent(id, comp, asm);
      return cb(null, spec);
    }
  }
  return cb(new ComponentNotFoundError("Cannot find component '" + id + "'"));
}
github angular / angular / packages / compiler-cli / src / ngcc / src / host / dts_mapper.ts View on Github external
getDtsFileNameFor(sourceFileName: string): string {
    const relativeSourcePath = relative(this.sourceRoot, sourceFileName);
    return resolve(this.dtsRoot, relativeSourcePath).replace(/\.js$/, '.d.ts');
  }
}
github angular / angular / tools / docs / content-package / readers / content.spec.js View on Github external
var createFileInfo = function(file, content, basePath) {
    return {
      fileReader: fileReader.name,
      filePath: file,
      baseName: path.basename(file, path.extname(file)),
      extension: path.extname(file).replace(/^\./, ''),
      basePath: basePath,
      relativePath: path.relative(basePath, file),
      content: content
    };
  };

canonical-path

paths that always use forward slashes

MIT
Latest version published 6 years ago

Package Health Score

50 / 100
Full package analysis