src/jsarch.js
async function initJSArch({ CONFIG, EOL, glob, fs, parser, log = noop }) {
  return jsArch;

  /**
   * Compile an run a template
   * @param {Object}   options
   * Options (destructured)
   * @param {Object}   options.cwd
   * Current working directory
   * @param {Object}   options.patterns
   * Patterns to look files for (see node-glob)
   * @param {Object}   options.eol
   * End of line character (default to the OS one)
   * @param {Object}   options.titleLevel
   * The base title level of the output makdown document
   * @param {Object}   options.base
   * The base directory for the ARCHITECTURE.md references
   * @return {Promise<String>}
   * Computed architecture notes as a markdown file
   */
  async function jsArch({
    cwd,
    patterns,
    eol,
    titleLevel = TITLE_LEVEL,
    base = BASE,
  }) {
    eol = eol || EOL;
    const files = await _computePatterns({ glob, log }, cwd, patterns);
    const architectureNotes = _linearize(
      await Promise.all(
        files.map(_extractArchitectureNotes.bind(null, { parser, fs, log })),
      ),
    );
    const content = architectureNotes
      .sort(compareNotes)
      .reduce((content, architectureNote) => {
        let linesLink =
          '#L' +
          architectureNote.loc.start.line +
          '-L' +
          architectureNote.loc.end.line;
        if (CONFIG.gitProvider.toLowerCase() === 'bitbucket') {
          linesLink =
            '#' +
            path.basename(architectureNote.filePath) +
            '-' +
            architectureNote.loc.start.line +
            ':' +
            architectureNote.loc.end.line;
        }
        return (
          content +
          eol +
          eol +
          titleLevel +
          architectureNote.num
            .split('.')
            .map(() => '#')
            .join('') +
          ' ' +
          architectureNote.title +
          eol +
          eol +
          architectureNote.content.replace(
            new RegExp(
              '([\r\n]+)[ \t]{' + architectureNote.loc.start.column + '}',
              'g',
            ),
            '$1',
          ) +
          eol +
          eol +
          '[See in context](' +
          base +
          '/' +
          path.relative(cwd, architectureNote.filePath) +
          linesLink +
          ')' +
          eol +
          eol
        );
      }, '');

    if (content) {
      return (
        JSARCH_PREFIX.replace(EOL_REGEXP, eol) +
        titleLevel +
        ' Architecture Notes' +
        eol +
        eol +
        content
      );
    }
    return content;
  }
}
async function initJSArch({ CONFIG, EOL, glob, fs, parser, log = noop }) {
  return jsArch;

  /**
   * Compile an run a template
   * @param {Object}   options
   * Options (destructured)
   * @param {Object}   options.cwd
   * Current working directory
   * @param {Object}   options.patterns
   * Patterns to look files for (see node-glob)
   * @param {Object}   options.eol
   * End of line character (default to the OS one)
   * @param {Object}   options.titleLevel
   * The base title level of the output makdown document
   * @param {Object}   options.base
   * The base directory for the ARCHITECTURE.md references
   * @return {Promise<String>}
   * Computed architecture notes as a markdown file
   */
  async function jsArch({
    cwd,
    patterns,
    eol,
    titleLevel = TITLE_LEVEL,
    base = BASE,
  }) {
    eol = eol || EOL;
    const files = await _computePatterns({ glob, log }, cwd, patterns);
    const architectureNotes = _linearize(
      await Promise.all(
        files.map(_extractArchitectureNotes.bind(null, { parser, fs, log })),
      ),
    );
    const content = architectureNotes
      .sort(compareNotes)
      .reduce((content, architectureNote) => {
        let linesLink =
          '#L' +
          architectureNote.loc.start.line +
          '-L' +
          architectureNote.loc.end.line;
        if (CONFIG.gitProvider.toLowerCase() === 'bitbucket') {
          linesLink =
            '#' +
            path.basename(architectureNote.filePath) +
            '-' +
            architectureNote.loc.start.line +
            ':' +
            architectureNote.loc.end.line;
        }
        return (
          content +
          eol +
          eol +
          titleLevel +
          architectureNote.num
            .split('.')
            .map(() => '#')
            .join('') +
          ' ' +
          architectureNote.title +
          eol +
          eol +
          architectureNote.content.replace(
            new RegExp(
              '([\r\n]+)[ \t]{' + architectureNote.loc.start.column + '}',
              'g',
            ),
            '$1',
          ) +
          eol +
          eol +
          '[See in context](' +
          base +
          '/' +
          path.relative(cwd, architectureNote.filePath) +
          linesLink +
          ')' +
          eol +
          eol
        );
      }, '');

    if (content) {
      return (
        JSARCH_PREFIX.replace(EOL_REGEXP, eol) +
        titleLevel +
        ' Architecture Notes' +
        eol +
        eol +
        content
      );
    }
    return content;
  }
}
async function initJSArch ( { CONFIG , EOL , glob , fs , parser , log = noop } ) { return jsArch ; /**
   * Compile an run a template
   * @param {Object}   options
   * Options (destructured)
   * @param {Object}   options.cwd
   * Current working directory
   * @param {Object}   options.patterns
   * Patterns to look files for (see node-glob)
   * @param {Object}   options.eol
   * End of line character (default to the OS one)
   * @param {Object}   options.titleLevel
   * The base title level of the output makdown document
   * @param {Object}   options.base
   * The base directory for the ARCHITECTURE.md references
   * @return {Promise<String>}
   * Computed architecture notes as a markdown file
   */ async function jsArch ( { cwd , patterns , eol , titleLevel = TITLE_LEVEL , base = BASE , } ) { eol = eol || EOL ; const files = await _computePatterns ( { glob , log } , cwd , patterns ) ; const architectureNotes = _linearize ( await Promise . all ( files . map ( _extractArchitectureNotes . bind ( null , { parser , fs , log } ) ) , ) , ) ; const content = architectureNotes . sort ( compareNotes ) . reduce ( ( content , architectureNote ) => { let linesLink = '#L' + architectureNote . loc . start . line + '-L' + architectureNote . loc . end . line ; if ( CONFIG . gitProvider . toLowerCase ( ) === 'bitbucket' ) { linesLink = '#' + path . basename ( architectureNote . filePath ) + '-' + architectureNote . loc . start . line + ':' + architectureNote . loc . end . line ; } return ( content + eol + eol + titleLevel + architectureNote . num . split ( '.' ) . map ( ( ) => '#' ) . join ( '' ) + ' ' + architectureNote . title + eol + eol + architectureNote . content . replace ( new RegExp ( '([\r\n]+)[ \t]{' + architectureNote . loc . start . column + '}' , 'g' , ) , '$1' , ) + eol + eol + '[See in context](' + base + '/' + path . relative ( cwd , architectureNote . filePath ) + linesLink + ')' + eol + eol ) ; } , '' ) ; if ( content ) { return ( JSARCH_PREFIX . replace ( EOL_REGEXP , eol ) + titleLevel + ' Architecture Notes' + eol + eol + content ) ; } return content ; } }
Declare jsArch in the dependency injection system
@param {Object}   services
Services (provided by the dependency injector)
@param {Object}   services.CONFIG
The JSArch config
@param {Object}   services.EOL
The OS EOL chars
@param {Object}   services.glob
Globbing service
@param {Object}   services.fs
File system service
@param {Object}   services.parser
Parser service
@param {Object}   [services.log = noop]
Logging service
@returns {Promise<Function>}
Declare jsArch in the dependency injection system