UNPKG

@nuskin/ns-checkout

Version:

Ecomm3 Checkout module

139 lines (128 loc) 4.59 kB
var process = require("process"); var shell = require('shelljs'); module.exports = function(grunt) { var PKG = grunt.file.readJSON('package.json'); grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), compass: { dev: { options: { sassDir: 'src/stylesheets', cssDir: 'src/stylesheets/generatedCSS/' } } }, watch: { css: { files: "**/*.scss", tasks: ['compass:dev'] } }, version_bump: { files: ['package.json'], versionStructure: [{ "name": "major", "priority": 1, "order": 1, "prefix": "", "resettable": false }, { "name": "minor", "priority": 2, "order": 2, "prefix": ".", "resettable": true, "resetTo": 0 }, { "name": "build", "priority": 3, "order": 3, "prefix": ".", "resettable": true, "resetTo": 0 }] } }); grunt.registerTask('getNuskinDeps', () => { var pack = grunt.config('pkg'); var hasDependency = false; Object.keys(pack.jspm.dependencies).map((value, index) => { var dependency = pack.jspm.dependencies[value]; dependency = dependency.substring(0, dependency.indexOf('@')); if (dependency.indexOf('github') == -1 && dependency.indexOf('npm') == -1) { if (hasDependency) { grunt.log.write(', '); } grunt.log.write(value); hasDependency = true; } }); }); //Code to link all dependent modules locally var nsDependencies = PKG.nsDependencies; var depDirectoryMap = { "ns-util": "util", "ns-account": "account", "ns-auth": "auth", "ns-shop": "shop", "ns-cart": "cart", "ns-checkout-common": "checkoutcommon", "ns-checkout": "checkout", "ns-checkout-mobile": "checkoutmobile", "ns-agelocme-core": "agelocme/common", "ns-agelocme-web": "agelocme/web" }; grunt.registerTask('link-all', function() { npmLinkAll(nsDependencies, false); }); grunt.registerTask('link-all-root', function() { npmLinkAll(nsDependencies, true); }); function npmLinkAll(nsDependencies, root) { var parentDirectory = process.cwd(); shell.exec("npm install"); Object.keys(nsDependencies).map((value, index) => { var dependency = nsDependencies[value]; process.chdir(parentDirectory); linkModule(dependency, root); linkToParent(dependency, parentDirectory); }); displayThumbsUp(); } function linkModule(module, root) { console.log("********************************* Linking module: " + module + " ***********************************************"); process.chdir("../" + depDirectoryMap[module]); shell.exec("npm install"); if (root) { shell.exec("sudo npm link"); } else { shell.exec("npm link"); } } function linkToParent(childModule, parentDirectory) { process.chdir(parentDirectory); shell.exec("npm link " + childModule); console.log("********************************* Done linking: " + childModule + " ********************************************"); } function displayThumbsUp() { var thumbsup = "" + " _\n" + " /(|\n" + " ( :\n" + " __ \\ \\ _____\n" + " (____) `|\n" + " (____)| |\n" + " (____).__|\n" + " (___)__.|_____\n"; console.log(thumbsup); shell.exec("echo $USER' thanks for linking me up!'"); } grunt.loadNpmTasks('grunt-contrib-compass'); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-version-bump'); grunt.registerTask('bumpVersion', ['version_bump']); grunt.registerTask('bumpMinorVersion', ['version_bump:minor']); grunt.registerTask('bumpMajorVersion', ['version_bump:major']); grunt.registerTask('template-sass-watch', ['watch']); grunt.registerTask('default', ['compass:dev']); };