tools/entryGenerator.js
function generateDependenciesFiles ({ suffix, factories, entryFolder }) {
  const braceOpen = '{' // a hack to be able to create a single brace open character in handlebars

  // a map containing:
  // {
  //   'sqrt': true,
  //   'subset': true,
  //   ...
  // }
  const exists = {}
  Object.keys(factories).forEach(factoryName => {
    const factory = factories[factoryName]
    exists[factory.fn] = true
  })

  mkdirSyncIfNotExists(path.join(entryFolder, 'dependencies' + suffix))

  const data = {
    suffix,
    factories: Object.keys(factories).map((factoryName) => {
      const factory = factories[factoryName]

      return {
        suffix,
        factoryName,
        braceOpen,
        name: getDependenciesName(factoryName, factories), // FIXME: rename name with dependenciesName, and functionName with name
        fileName: './dependencies' + suffix + '/' + getDependenciesFileName(factoryName) + '.generated',
        eslintComment: factoryName === 'createSQRT1_2'
          ? ' // eslint-disable-line camelcase'
          : undefined,

        dependencies: factory.dependencies
          .map(stripOptionalNotation)
          .filter(dependency => !IGNORED_DEPENDENCIES[dependency])
          .filter(dependency => {
            if (!exists[dependency]) {
              if (factory.dependencies.indexOf(dependency) !== -1) {
                throw new Error(`Required dependency "${dependency}" missing for factory "${factory.fn}"`)
              }

              return false
            }

            return true
          })
          .map(dependency => {
            const factoryName = findFactoryName(factories, dependency)
            const name = getDependenciesName(factoryName, factories)
            const fileName = './' + getDependenciesFileName(factoryName) + '.generated'

            return {
              suffix,
              name,
              fileName
            }
          })
      }
    })
  }

  // generate a file for every dependency
  data.factories.forEach(factoryData => {
    const generatedFactory = dependenciesFileTemplate(factoryData)

    const p = path.join(entryFolder, factoryData.fileName + '.js')
    fs.writeFileSync(p, generatedFactory)
  })

  // generate a file with links to all dependencies
  const generated = dependenciesIndexTemplate(data)
  fs.writeFileSync(path.join(entryFolder, 'dependencies' + suffix + '.generated.js'), generated)
}
function generateDependenciesFiles ({ suffix, factories, entryFolder }) {
  const braceOpen = '{' // a hack to be able to create a single brace open character in handlebars

  // a map containing:
  // {
  //   'sqrt': true,
  //   'subset': true,
  //   ...
  // }
  const exists = {}
  Object.keys(factories).forEach(factoryName => {
    const factory = factories[factoryName]
    exists[factory.fn] = true
  })

  mkdirSyncIfNotExists(path.join(entryFolder, 'dependencies' + suffix))

  const data = {
    suffix,
    factories: Object.keys(factories).map((factoryName) => {
      const factory = factories[factoryName]

      return {
        suffix,
        factoryName,
        braceOpen,
        name: getDependenciesName(factoryName, factories), // FIXME: rename name with dependenciesName, and functionName with name
        fileName: './dependencies' + suffix + '/' + getDependenciesFileName(factoryName) + '.generated',
        eslintComment: factoryName === 'createSQRT1_2'
          ? ' // eslint-disable-line camelcase'
          : undefined,

        dependencies: factory.dependencies
          .map(stripOptionalNotation)
          .filter(dependency => !IGNORED_DEPENDENCIES[dependency])
          .filter(dependency => {
            if (!exists[dependency]) {
              if (factory.dependencies.indexOf(dependency) !== -1) {
                throw new Error(`Required dependency "${dependency}" missing for factory "${factory.fn}"`)
              }

              return false
            }

            return true
          })
          .map(dependency => {
            const factoryName = findFactoryName(factories, dependency)
            const name = getDependenciesName(factoryName, factories)
            const fileName = './' + getDependenciesFileName(factoryName) + '.generated'

            return {
              suffix,
              name,
              fileName
            }
          })
      }
    })
  }

  // generate a file for every dependency
  data.factories.forEach(factoryData => {
    const generatedFactory = dependenciesFileTemplate(factoryData)

    const p = path.join(entryFolder, factoryData.fileName + '.js')
    fs.writeFileSync(p, generatedFactory)
  })

  // generate a file with links to all dependencies
  const generated = dependenciesIndexTemplate(data)
  fs.writeFileSync(path.join(entryFolder, 'dependencies' + suffix + '.generated.js'), generated)
}
function generateDependenciesFiles ( { suffix , factories , entryFolder } ) { const braceOpen = '{' // a hack to be able to create a single brace open character in handlebars // a map containing: // { //   'sqrt': true, //   'subset': true, //   ... // } const exists = { } Object . keys ( factories ) . forEach ( factoryName => { const factory = factories [ factoryName ] exists [ factory . fn ] = true } ) mkdirSyncIfNotExists ( path . join ( entryFolder , 'dependencies' + suffix ) ) const data = { suffix , factories : Object . keys ( factories ) . map ( ( factoryName ) => { const factory = factories [ factoryName ] return { suffix , factoryName , braceOpen , name : getDependenciesName ( factoryName , factories ) , // FIXME: rename name with dependenciesName, and functionName with name fileName : './dependencies' + suffix + '/' + getDependenciesFileName ( factoryName ) + '.generated' , eslintComment : factoryName === 'createSQRT1_2' ? ' // eslint-disable-line camelcase' : undefined , dependencies : factory . dependencies . map ( stripOptionalNotation ) . filter ( dependency => ! IGNORED_DEPENDENCIES [ dependency ] ) . filter ( dependency => { if ( ! exists [ dependency ] ) { if ( factory . dependencies . indexOf ( dependency ) !== - 1 ) { throw new Error ( ` ${ dependency } ${ factory . fn } ` ) } return false } return true } ) . map ( dependency => { const factoryName = findFactoryName ( factories , dependency ) const name = getDependenciesName ( factoryName , factories ) const fileName = './' + getDependenciesFileName ( factoryName ) + '.generated' return { suffix , name , fileName } } ) } } ) } // generate a file for every dependency data . factories . forEach ( factoryData => { const generatedFactory = dependenciesFileTemplate ( factoryData ) const p = path . join ( entryFolder , factoryData . fileName + '.js' ) fs . writeFileSync ( p , generatedFactory ) } ) // generate a file with links to all dependencies const generated = dependenciesIndexTemplate ( data ) fs . writeFileSync ( path . join ( entryFolder , 'dependencies' + suffix + '.generated.js' ) , generated ) }
Generate index files like
dependenciesAny.generated.js
dependenciesNumber.generated.js
And the individual files for every dependencies collection.
Generate index files like dependenciesAny . generated . js dependenciesNumber . generated . js And the individual files for every dependencies collection .