What is package manager? • a tool that allows you to specify a list of dependencies for your library or application • provide a reliable, standard mechanism for installing software created by third-parties - ne moramo da znamo kako se neka biblioteka instalira, kako se kompajlira, build-a. treba da pratimo konvencije packaga manager • provide dependency management - ako jedna biblioteka zahteva druge dve, da bi se instalira, package manager ce nam skrenuti paznju i reci nam da treba i te dve da instaliramo, takodje ako imamo vec tu instalirano, nested tree, specific version requierements for dependencies, so that compatible versions work together • keep you up to date with new versions and easily upgrades • reproduce stack for new developer • keep dependecies out of your repo
repository for the publishing of open-source Node.js projects ◦ command-line utility for interacting with said repository that aids in package installation, version management ◦ dependency management ▪ node project with a package.json file, you can run npm install from the project root and npm will install all the dependencies listed in the package.json • used for backend projects, but also on frontend • nested tree • many other browser-oriented tools mentioned later are themselves npm packages
script loading, scaffolding, compile/build • Bower - package manager for FE ◦ created by Twitter ◦ can contain any assets a website might need, such as CSS, JavaScript or images ◦ install bower - npm install -g bower
.bowerrc json file in the root of a project folder { "directory" : "components", "json" : "bower.json", "endpoint" : "https://Bower.herokuapp.com", "searchpath" : "", "shorthand_resolver" : "" } • directory - local directory name and location in which the components will be installed. • json - name of the json file which contains the values describing (i.e. name, version, main, dependencies) a Bower component • endpoint - registry that is search, by name, for a component. The default registry is at https://Bower.herokuapp.com and can be viewed as a json object at https://Bower.herokuapp. com/packages. • searchpath - an array of additional registries that can be searched if the component is not found at the first registry indicated by endpoint. • shorthand_resolver - Define a custom template for shorthand component names.
clean, bower install • bower install jquery ◦ specific version, commit, tagged version, master, save dev ◦ (bower install jquery#1.7.0) • if next version of library comes out - bower update • i don’t need it anymore - bower uninstall jquery • The biggest difference is that npm does nested dependency tree, which doesn't work that well on the front-end, while Bower requires a flat dependency tree • many projects use both is that they use Bower for front-end packages and npm for developer tools like Grunt, JSHint, CoffeeScript
Concatenate and compress our files. Run our preprocessors. Optimize images. Run tests. ◦ using different tools for above tasks, do it manually ◦ automation, less tasks - easier job • 2 main stream task runners ◦ grunt.js ◦ gulp.js
that grows everyday (as we speak :O) ◦ utility ◦ flexible - hundreds of plugins, you can automate anything you can think of ▪ you’re so special? create your own task
Node.js • task-based command-line tool that speeds up workflows • install grunt cli npm install -g grunt -cli • run the version of Grunt which has been installed next to a Gruntfile • npm init create a package.json file in the root directory • Gruntfile.js file in the root directory
the project name, version and author • package.json file is also responsible for managing dependencies • run npm install to fetch all the packages and store them in node_modules
function • takes grunt as parameter module.exports = function(grunt) { // Configuration, Tasks and Plugins. }; • configuration ◦ grunt.initConfig: object containing the project configuration as well as any task configurations ▪ pkg: grunt.file.readJSON('package.json') - imports config data from package.json ▪ task: {...}, task_two: {...} });
need to be specified in your package.json file and installed using npm install. ▪ // Load the Grunt plugins. grunt.loadNpmTasks('grunt-contrib-compass'); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-jshint'); ▪ require("matchdep").filterDev("grunt-*").forEach(grunt.loadNpmTasks); • grunt.registerTask method is used specify a set of tasks that should run when the grunt command is executed. ◦ // Register the default tasks. grunt.registerTask('default', ['watch']);
what’s the difference? ◦ use of streams ▪ more control over your flow and relieves you of temporary folders and files. you put a file in and you get a file out ◦ code-over-configuration makes for a simpler and more intuitive build ▪ strict plugin guidelines assure plugins stay simple and work the way you expect. With a minimal API surface ▪ more readable ◦ each plugin should only perform a single action
a banner? Use the javascript minifier • Plugins do things that don't need to be plugins ▪ Need to run your tests? Use a plugin • Grunt config format is a mess that tries to do everything ▪ Not idiomatic with "the node way" • Headache of temp files/folders due to bad flow control
a name • gulp.run(tasks...) - runs all tasks with maximum concurrency • gulp.watch(glob, fn) - runs a function when a file that matches the glob changes • gulp.src(glob) - returns a readable stream • gulp.dest(folder) - returns a writable stream
• grunt/gulp - the build tool • bower - for package management npm install -g yo • yo can generate several types of applications, but it needs help from plug-ins, or generators to get the job done. • To scaffold a web application, you'll need to grab the web app generator
# scaffold out a AngularJS project bower install angular-ui # install a dependency for your project from Bower grunt test # test your app grunt serve # preview your app (formerly `grunt server`) grunt # build the application for deployment