GithubHelp home page GithubHelp logo

add2package's Introduction

Add2Package


WARNING:

This package is highly experimental and is not recommended for use in production applications. Becaue of the way the packaging system works, it will most likely not get much better. However, you may attempt to use it in your app but be warned that there are lots of quirks. That being said, I'm currently using it on a live (non-production) app and it is working pretty well.


Are you tired of listing all of your Meteor package's files out by hand?

Well I've got a solution for you!

Introducing, Add2Package - the insanely easy way to add lots of files to your package.js

Why?

See above.

Just kidding. You know why I made this package? Have you ever tried adding Semantic-UI to a Meteor package? It easily can be 200+ files and there is no way I'm going to add them all by hand to the package.js file.

Thus, Add2Package was born.

How?

As it stands, the only difficult part of using this "package" is that you can't use it directly from atmosphere. In other words, you can't do meteor add scw:add2package.

To get around that, the only way to use it is to clone this repo to your PACKAGE_DIRS and make sure you export that variable in your terminal shell. (more info on that here)

This package creates a few global functions that you can use in your packages.

Please read the quirks at the bottom before trying to use this!

Let me show you...

Package.describe({
  name: 'my-fancy-dancy-package',
  version: '0.0.0',
  summary: "we gotta be stylish. so lets's add some styles"
});

Package.onUse(function(api) {
  api.versionsFrom('1.2');

  api.use([
    'flemay:[email protected]',
    'semantic:[email protected]'
  ]);


  setTimeout(function() {

    // You have to tell us what folder your package is in
    // and pass in a reference to the api
    packageFolder('stargazing-styles', api);

    // Then it's really simple after that

    // Add the Semantic UI Themes
    addFiles('client/lib/semantic-ui/themes/**/*.*', 'client');

    // Add the definitions and site files
    addFiles('client/lib/semantic-ui/+(definitions|site)/**/*.*', 'client');

    // Add everything else not in the semantic-ui directory
    addFiles('client/lib/semantic-ui/!(definitions|site|themes)', 'client');

  }, 100)

})

Here's another example without all the comments:

Package.describe({
  name: 'my:components',
  version: '0.0.0'
})

Package.onUse(function(api) {
  api.versionsFrom('1.2')
  api.use([
    'ecmascript',
    'react'
  ])

  setTimeout(function() {
    packageFolder('my-components', api)

    addFiles('lib/components-list.jsx')
    addFiles('lib/forms/**/!(auth-box).jsx')
    addFiles('lib/forms/**/auth-box.jsx')
    addFiles('lib/layouts/**.*')
  }, 100)
})

Note: You must use the setTimeout() as shown above or it won't work. You also may need to play with the delay a bit.

What's this Glob stuff you mentioned?

Glob lets you:

Match files using the patterns the shell uses, like stars and stuff.

"Globs" are the patterns you type when you do stuff like ls .js on the command line, or put build/ in a .gitignore file.

Here's a little on how to use them...
  • * Matches 0 or more characters in a single path portion
  • ? Matches 1 character
  • [...] Matches a range of characters, similar to a RegExp range. If the first character of the range is ! or ^ then it matches any character not in the range.
  • !(pattern|pattern|pattern) Matches anything that does not match any of the patterns provided.
  • ?(pattern|pattern|pattern) Matches zero or one occurrence of the patterns provided.
  • +(pattern|pattern|pattern) Matches one or more occurrences of the patterns provided.
  • *(a|b|c) Matches zero or more occurrences of the patterns provided
  • @(pattern|pat*|pat?erN) Matches exactly one of the patterns provided
  • ** If a "globstar" is alone in a path portion, then it matches zero or more directories and subdirectories searching for matches. It does not crawl symlinked directories.

You can read more about globs here

API

Add2Package Methods

packageFolder(name, api)

Create a reference to the folder your package resides in and the api defined by that package.

Arguments

  • name - String Must be the name of the directory your package.js file resides in. Not the name of your package
  • api - Object This needs to be the api object passed to Package.onUse() in the callback.

addFiles(pattern, target)

This method basically matches the api.addFiles method but it allows you to define a glob to match multiple files at once.

Arguments

  • pattern - String Pattern to be matched.
  • target - Array or String Any target allowed by the normal api.addFiles method. Also allows the use of "both" to add files to the client and the server.

addAssets(pattern, target)

Same as addFiles() but used to add assets.

Quirks

  • Must be a local package cloned to your PACKAGE_DIRS
  • Must add your files in the callback of a setTimeout()
  • Will not work for stand-alone packages
    • In other words, you can't add this package to a package that will be published to Atmosphere. It will only work if it's available in your local packages as mentioned above.

Shout outs

Thanks to the random stackoverflow citizen who provided the initial code to get me inspired to do this (I can't find your post anymore but I know you're out there)

random citizen

Also, thanks BIG TIME to @rfox90 who posted about globs here and how to use them in package.js

add2package's People

Contributors

sircharleswatson avatar

Stargazers

Angus H. avatar Radu Chiriac avatar  avatar Logan Koester avatar Mason Hensley avatar Aaron avatar Jon Baer avatar Fernando Mumbach avatar Gabriel Almeida avatar Michal Takac avatar Philipp Muens avatar Ben Bressington avatar Michael Shilman avatar

Watchers

Logan Koester avatar James Cloos avatar  avatar

Forkers

michaltakac

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.