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

@studiowebux/seed

v1.1.2

Published

A module to manage the default values to be create in the Database.

Downloads

5

Readme

@studiowebux/seed

This module allows to load some default values in the app, You need to create a specific file for each resources you need.

Installation

npm i --save @studiowebux/seed

Usage

Scheme for the default value

You need to create a file using this scheme to get the script working has expected:

...

const Language = require('../models/language')

const french = () => {
  return new Promise((resolve, reject) => {
    Language.create({
      defaultValue: true,
      name: "Français",
      shortcuts: ["fr", "fr_ca", "fr_fr"]
    }).then(languageCreated => {
      if (!languageCreated) {
        return reject(Error("Fail to create the resource."));
      }
      return resolve('Default language "french" created.');
    });
  });
};

const english = () => {
  return new Promise((resolve, reject) => {
    Language.create({
      defaultValue: false,
      name: "English",
      shortcuts: ["en", "en_us", "en_ca"]
    }).then(languageCreated => {
      if (!languageCreated) {
        return reject(Error("Fail to create the resource."));
      }
      return resolve('Default language "english" created.');
    });
  });
};
};

module.exports = Promise.all([french(), english()]);

You have to do the same thing for all of your resources,

How to load the files in a specific order

append 00_, 01_, ... in front of your file name (For more details, check the examples directory)

Example

directory

defaults
    00_language.js
    01_role.js
index.js

index.js

const webuxSeed = require("@studiowebux/seed");
const path = require("path");

webuxSeed(path.join(__dirname, "defaults"))
  .then(() => {
    console.log("FInished !");
  })
  .catch(e => {
    console.error(e);
  });

or
index.js

const webuxSeed = require("@studiowebux/seed");
const path = require("path");

async function loadApp() {
  try {
    console.log("Loading Modules and create the APP...");

    const loaded = await webuxSeed(path.join(__dirname, "defaults"));

    if (!loaded) {
      throw new Error("Seed not Loaded");
    }

    console.log(loaded);

    console.log("Continue to load module / Start server ...");
  } catch (e) {
    console.error(e.message);
    process.exit(1);
  }
}

try {
  loadApp();
} catch (e) {
  throw e;
}

OUTPUT:

1. Getting all the default value files in /Users/tgingras/Documents/Studiowebux/webux-seed/examples/defaults.
1.1. Processing file : 00_language.js
Language created !
Language created !
1.2. File 00_language.js Loaded
1.1. Processing file : 01_role.js
Role created !
Role created !
Role created !
1.2. File 01_role.js Loaded
2. All default values loaded from the directory.
Finished !

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

SEE LICENSE IN license.txt