Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion gruntRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ module.exports = function (grunt) {
// Determine the location where grunt should be run, and store the current location
var gruntPath = getPathFromName(options.name);
var originalPath = process.cwd();
var flags = _.filter(options.flag, function(value) { // Remove the gruntfile option if present
return !_.startsWith("gruntfile", 2)
});

var command = getGruntCommand();
var commandArgs = getTasks(options.tasks).concat(options.flags); // Pass any command line args to the child grunt task.
var commandArgs = getTasks(options.tasks).concat(flags); // Pass any command line args to the child grunt task.
var commandConfig = getCommandConfig(gruntPath, commandArgs);

// Log the command with arguments
Expand Down
4 changes: 2 additions & 2 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,10 @@ module.exports = function (grunt) {
// calling pattern library happens to contain one of the
// dependencies used by pattern pack. For more info:
// https://www.npmjs.com/package/load-grunt-parent-tasks
log.log("load parent tasks");
log.verbose("load parent tasks");
require("load-grunt-parent-tasks")(grunt, loadTaskConfig);
} else {
log.log("load tasks");
log.verbose("load tasks");
require("load-grunt-tasks")(grunt, loadTaskConfig);
}

Expand Down
2 changes: 1 addition & 1 deletion gruntfileConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"build": "./html",
"src": "./src",
"assets": "./src/assets",
"theme": "./node_modules/patternpack-example-theme",
"theme": "patternpack-example-theme",
"logo": "/theme-assets/images/logo.svg",
"css": {
"preprocessor": "sass",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "patternpack",
"description": "Generates pattern library content from simple markdown and css",
"version": "1.0.3",
"version": "1.0.4",
"license": "MIT",
"dependencies": {
"assemble": "^0.4.42",
Expand Down
66 changes: 41 additions & 25 deletions tasks/patternpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ module.exports = function (grunt) {

var log = require("../gruntLogHelper.js")(grunt);
var fs = require("fs");
var path = require("path");
var _ = require("lodash");
_.defaultsDeep = require("merge-defaults"); // Add deep defaults capabilities to lodash

var npmPath = "./node_modules/";
var packageName = "patternpack";
var packagePath = npmPath + packageName;
var packagePath = "./" + path.relative(process.cwd(), path.dirname(__dirname)); // "./node_modules/patternpack"
var packageName = path.basename(packagePath); // "patternpack"
var tasksValues = ["default", "build", "integrate", "release", "release-patch", "release-minor", "release-major", "", undefined];
var cssPreprocessorValues = ["less", "sass", "none", "", undefined];
var gruntTaskName = "patternpack";
Expand All @@ -20,7 +20,7 @@ module.exports = function (grunt) {
build: "./html",
src: "./src",
assets: "./src/assets",
theme: npmPath + "patternpack-example-theme",
theme: "patternpack-example-theme",
logo: "/theme-assets/images/logo.svg",

// Operation to run (default|build|release)
Expand Down Expand Up @@ -53,26 +53,49 @@ module.exports = function (grunt) {
}
};

function getPackagePathOrFallbackPath(path) {
var validatedPath;
var pathOfPackage = npmPath + path;
function getPathOrPackagePath(path) {
var packagePath;

if (fs.existsSync(pathOfPackage)) {
validatedPath = pathOfPackage;
} else if (fs.existsSync(path)) {
validatedPath = path;
} else {
throw new Error("Could not be found: " + pathOfPackage + " or " + path);
// Attempt to find the configured location
if (fs.existsSync(path)) {
packagePath = path;
}
return validatedPath;

// If not found, look for the path as a node package
if (!packagePath) {
packagePath = getPackagePath(path);
}

if (!packagePath) {
throw new Error("Could not find package: " + path);
}

return packagePath;
}

function getPackagePath(name) {
var currentPath = "./" + path.relative(process.cwd(), path.dirname(__dirname));
var dependencyPaths = [
"./node_modules/",
"../node_modules/",
currentPath + "/node_modules/"
];

// Look for the package in any of the node_modules locations
var packageDependencyPath = _.find(dependencyPaths, function(path) {
return fs.existsSync(path + name);
});

// Return the validated location of the package
// Otherwise return undefined
return packageDependencyPath ? packageDependencyPath + name : undefined;
}

function applyOverrides(value, overrideValue) {
return _.defaultsDeep(_.cloneDeep(overrideValue), value);
}

function getOptions(context) {
var path = require("path");
var options = {};
var optionOverrides = context.options();
var optionOverridesFile = grunt.file.exists(optionsOverrideFileName) ? grunt.file.readJSON(optionsOverrideFileName) : {};
Expand All @@ -90,24 +113,18 @@ module.exports = function (grunt) {
options = applyOverrides(options, optionOverridesFile);

// Resolve the theme path either from a path or from a package name
if (optionOverrides.theme) {
optionOverrides.theme = getPackagePathOrFallbackPath(optionOverrides.theme);
}
log.verbose("Theme paths");
log.verbose("Default: " + optionDefaults.theme);
log.verbose("Override: " + optionOverrides.theme);

// If the pattern is specified by the user then get the relative path,
// otherwise use the path inside pattern pack to provide the default patterns.
options.theme = optionOverrides.theme ? path.relative(packagePath, optionOverrides.theme) : optionDefaults.theme;
options.theme = optionOverrides.theme ? optionOverrides.theme : optionDefaults.theme;
options.theme = getPathOrPackagePath(options.theme);
options.theme = path.relative(packagePath, options.theme)
log.verbose("Resolved: " + options.theme);

return options;
}

function transformOptions(options) {
var path = require("path");

// Add the relative path to the root of the calling pattern library
options.root = path.relative(packagePath, "");

Expand Down Expand Up @@ -143,7 +160,6 @@ module.exports = function (grunt) {
function ensureFilesExist(options) {
// TODO: File generation should be enhanced to use templates rather than
// the current implementation that generates the files inline.
var path = require("path");
var mkdirp = require("mkdirp");

// Create core css file if it does not exist
Expand Down