diff --git a/package.js b/package.js index 29bfd96..5694d6d 100644 --- a/package.js +++ b/package.js @@ -1,6 +1,6 @@ Package.describe({ summary: "Use npm modules with your Meteor App", - version: "1.5.0", + version: "1.5.1", git: "https://github.com/meteorhacks/npm.git", name: "meteorhacks:npm" }); diff --git a/plugin/init_npm.js b/plugin/init_npm.js index 2a469be..3b4df78 100644 --- a/plugin/init_npm.js +++ b/plugin/init_npm.js @@ -1,15 +1,15 @@ -var path = Npm.require('path'); -var fs = Npm.require('fs'); -var mkdirp = Npm.require('mkdirp'); -var echo = Npm.require('node-echo'); -var beautify = Npm.require('js-beautify'); +var path = require('path'); +var fs = require('fs'); +var mkdirp = require('mkdirp'); +var echo = require('node-echo'); +var beautify = require('js-beautify'); var npmContainerDir = path.resolve('./packages/npm-container'); var packagesJsonPath = path.resolve('./packages.json'); var packageJsPath = path.resolve(npmContainerDir, 'package.js'); var indexJsPath = path.resolve(npmContainerDir, 'index.js'); -if(canProceed() && !fs.existsSync(packagesJsonPath)) { +if (canProceed() && !fs.existsSync(packagesJsonPath)) { console.log('\n'); console.log("-> creating `packages.json` for the first time."); console.log("-> add your npm modules to `packages.json`"); @@ -18,7 +18,7 @@ if(canProceed() && !fs.existsSync(packagesJsonPath)) { fs.writeFileSync(packagesJsonPath, '{\n \n}'); } -if(canProceed() && !fs.existsSync(npmContainerDir)) { +if (canProceed() && !fs.existsSync(npmContainerDir)) { console.log("=> Creating container package for npm modules"); // create new npm container directory @@ -42,10 +42,10 @@ if(canProceed() && !fs.existsSync(npmContainerDir)) { // check whether is this `meteor test-packages` or not function canProceed() { - var unAcceptableCommands = {'test-packages': 1, 'publish': 1}; - if(process.argv.length > 2) { + var unAcceptableCommands = { 'test-packages': 1, 'publish': 1 }; + if (process.argv.length > 2) { var command = process.argv[2]; - if(unAcceptableCommands[command]) { + if (unAcceptableCommands[command]) { return false; } } @@ -57,9 +57,9 @@ function canProceed() { function getContent(func) { var lines = func.toString().split('\n'); // Drop the function declaration and closing bracket - var onlyBody = lines.slice(1, lines.length -1); + var onlyBody = lines.slice(1, lines.length - 1); // Drop line number comments generated by Meteor, trim whitespace, make string - onlyBody = _.map(onlyBody, function(line) { + onlyBody = _.map(onlyBody, function (line) { return line.slice(0, line.lastIndexOf("//")).trim(); }).join('\n'); // Make it look normal @@ -69,20 +69,20 @@ function getContent(func) { // Following function has been defined to just get the content inside them // They are not executables function _indexJsContent() { - Meteor.npmRequire = function(moduleName) { + Meteor.npmRequire = function (moduleName) { var module = Npm.require(moduleName); return module; }; - Meteor.require = function(moduleName) { + Meteor.require = function (moduleName) { console.warn('Meteor.require is deprecated. Please use Meteor.npmRequire instead!'); return Meteor.npmRequire(moduleName); }; } -function _packageJsContent () { - var path = Npm.require('path'); - var fs = Npm.require('fs'); +function _packageJsContent() { + var path = require('path'); + var fs = require('fs'); Package.describe({ summary: 'Contains all your npm dependencies', @@ -94,19 +94,19 @@ function _packageJsContent () { try { var fileContent = fs.readFileSync(packagesJsonFile); var packages = JSON.parse(fileContent.toString()); - Npm.depends(packages); - } catch(ex) { + depends(packages); + } catch (ex) { console.error('ERROR: packages.json parsing error [ ' + ex.message + ' ]'); } // Adding the app's packages.json as a used file for this package will get // Meteor to watch it and reload this package when it changes - Package.onUse(function(api) { + Package.onUse(function (api) { api.addFiles('index.js', 'server'); - if(api.addAssets) { + if (api.addAssets) { api.addAssets('../../packages.json', 'server'); } else { - api.addFiles('../../packages.json', 'server', {isAsset: true}); + api.addFiles('../../packages.json', 'server', { isAsset: true }); } }); } \ No newline at end of file