npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mochi-inc-japan/algolia-tools-cli-generator

v2.0.5

Published

Auto cli generator for general usage algolia from node. This library mainly targets typescript but may be available as js module.

Downloads

37

Readme

@mochi-inc-japan/algolia-tools-cli-generator

Auto cli generator for general usage algolia from node. This library mainly targets typescript but may be available as js module.

Ready to use

You need reading env setting if command auto generation.

ALGOLIA_ID: your algolia id
ALGOLIA_ADMIN_KEY: your algolia admin key
ALGOLIA_SEARCH_KEY: our algolia search key
INDEX_NAMESPACE (Optional): prefix for algolia index, this is used to set different environments with one algolia account.

package.json

package.json

  "aftools" : {
    "modulePath": "algoliaIndexManager",
    "out": "dist",
    "dFiles": ["./internalAmbientFiles", "index.d.ts"],
    "envFile": ".env.some"
  }

modulePath: your algolia index manager relative module path from package.json. this is object consistes of IndexManager Class Constructor. It explained later and see example cases.

out (Optional): builded relative cli path from package.json. Default is ${projectRoot}/bin. types (Optional): project internal types. .

firebaseServiceAccountPath (Optional): relative firebase-service json path from package.json. FIREBASE_SERVICE_ACCOUNT_PATH valiable is prior than this. Default is ${projectRoot}/bin.

dFiles: string[] (Optional): For including ambient definition files through build, sometimes you need them using global type in your index modules. You can specify directory and .d.ts file path.

envFile (Optional): your env file specified, default is .env. If not specified, machine variables is used .

Example Index ManagerModules

Make algoliaIndexManager/userExample.ts (if you specify ./algoliaIndexManager as modulePath)

import { AlgoliaIndexManager, IndexInterface } from '@moch-inc-japan/algolia-tools'

type UserSchema = {
  id: string
  name: string
}
export default class UserIndexManager implements IndexInterface {
  private algoliaIndexManager: AlgoliaIndexManager
  public constructor(args: { algoliaIndexManager: AlgoliaIndexManager }) {
    this.algoliaIndexManager = args.algoliaIndexManager
  }

  public sendIndex = async (userId: string, user: UserSchema) => {
    const result = await this.algoliaIndexManager.sendIndex('users', user)
    if (result) {
      console.log(`users index has been updated: [userId:${user.id}]`)
      return true
    } else {
      console.error('users index update has been failed')
      return false
    }
  }

  public batchSendToIndex = async () => {
    const result = await this.algoliaIndexManager.sendIndex('users', [])
    return result
  }

  public deleteIndexData = async (userIds: string[]) => {
    const result = await this.algoliaIndexManager.deleteIndexData('users', userIds)
    if (result) {
      console.log(`user index has been deleted: [userIds:${userIds}]`)
      return true
    } else {
      console.error('user index delete has been failed')
      return false
    }
  }
}

And you make algoliaIndexManager/index.ts

import users from './userExample'
export default {
  users // This exported as collectionName, so you should use named import specify to collection id
}

Usage

cli init or update indexModules

aftools-build

This is typescript tsc wrapper so you can use tsc --option if your source code including ambient file and json Module like

aftools-build --typeRoots ${DFILE_PATH} --resolveJsonModule

and you can exec build command

aftools-build --verbose

cli run

aftools <scriptId>

You can switch an env file from option. It's prior than config envFile.

aftools-build --envfile ${env_path} <scriptId>

builtin script

see aftools help.

npx aftools

Usage as Modules

Your module can be used backend. We probide algoliaModule default exported. So you can use same logic introduced in cli.

For example,

import algoliaModule from '@mochi-inc-japan/algolia-tools'
import indexManagers from './algoliaIndexManager'

const manager = algoliaModule(
  {
    client,
    indexNamespace,
  },
  indexManagers
)


manager.indices.users.batchSendIndex()

so on.

Extension for Commander

Auto Mode

Add algolia-tools.config.js in your project aloglia-tools-cli-generator.

const Plugins = require('@mochi-inc-japan/plugin-algolia-tools-firestore')
module.exports = {
  plugins: [Plugins.FirestorePlugin],
  commanderPlugins: [Plugins.FirestoreCommanderPlugin]
}

config path is changeable via package.json aftools configPath.

Manual Mode

If you use commader, you can extend it by defined commands in this library.

import AlgoliaModule from '@mochi-inc-japan/algolia-tools'
import { createAlgoliaCommanderPlugin } from '@mochi-inc-japan/algolia-cli-tools'
import { createAlgoliaCommanderPlugin } from '@mochi-inc-japan/plugin-algolia-tools-firestore'
import indexManagers from './algoliaIndexManager'
import commander from 'commander'

const algoliaModule = AlgoliaModule(
  {
    client,
    indexNamespace,
  },
  indexManagers,
  {
    plugin: [FirestorePlugin]
  }
)

const algoliaProjectManager = new AlgoliaProjectManager(algoliaModule)

// extended to commander commands
createAlgoliaCommanderPlugin(algoliaProjectManager)(commander)
createFirestoreCommanderPlugin(algoliaProjectManager.algoliaModule)(commander)// optional if you use firestore

WARNING

This library cli may include your secret files bundled code. So you should not include bundle task files in git repository your aftools-build code.