Skip to content

Commit

Permalink
Module update + project and module lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
ericabouaf committed Nov 28, 2012
1 parent fd3c50c commit a01e63e
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 37 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -43,14 +43,14 @@ Or install it as a developer :

git clone git://github.com/neyric/yproject.git
cd yproject
npm link .
npm link


## Usage

### Create a new project

yproject create myproject
yproject myproject

This will create the following structure :

Expand Down
13 changes: 9 additions & 4 deletions bin/ymodule.js
Expand Up @@ -60,8 +60,13 @@ if (argv._.length > 0) {

}
else {
// TODO: existing module
// not creating a module
console.log("TODO: try to check if we are within a YUI module (if we have a build.json file)");
console.log("THEN, apply these options to the current module", argv);

var moduleInfos = yproject.moduleLookup();
if (moduleInfos === false) {
yproject.log('err', 'Unable to find build.json in parent directories...');
yproject.log('err', 'Cannot update module !');
process.exit(1);
}

yproject.createModule(moduleInfos.name, argv);
}
7 changes: 4 additions & 3 deletions example.sh
Expand Up @@ -7,17 +7,18 @@ rm -rf mytest
yproject mytest

# Create some modules
cd mytest/src
cd mytest

ymodule basic
ymodule dummy --no-assets --no-lang
ymodule myfirstwidget -w

# Build Everything
cd src
shifter --walk

# Build the doc
cd ..

# Build the doc (will read yuidoc.json)
yuidoc

# Documentation for the project
Expand Down
89 changes: 62 additions & 27 deletions lib/yproject.js
Expand Up @@ -50,20 +50,26 @@ var yproject = {
createModule: function(moduleName, options, templatePath) {
yproject.log('log', "Creating module " + moduleName);

// Lookup for project
var projectInfos = yproject.projectLookup();
if (projectInfos === false) {
yproject.log('err', "Unable to find yuidoc.json or package.json in any parent directory !");
yproject.log('err', "Cannot create module " + moduleName + ": project not found !");
return;
}

var projectName = projectInfos.name;
var destPath = path.join(projectInfos.path, 'src', moduleName);

var locals = {projectName: projectName, moduleName: moduleName};

if (!templatePath) {
templatePath = path.join(__dirname, '..', 'templates', 'module');
}

var destPath = moduleName;

// Creating module directory
yproject.mkdir(destPath);

// TODO: autodetect projectName
var projectName = 'mytest';

var locals = {projectName: projectName, moduleName: moduleName};

// Optional folders
['assets', 'docs', 'lang', 'tests'].forEach(function (option) {
if (options[option]) {
Expand Down Expand Up @@ -137,33 +143,62 @@ var yproject = {
},


// TODO: get project path & name
projectLookup: function () {
// TODO: move up the folder hierarchy to find a yuidoc.json or package.json
},
// get project path & name
projectLookup: function (lookupPath) {

if (!lookupPath) {
lookupPath = process.cwd();
}

var yuidocPath = path.join(lookupPath, 'yuidoc.json');
if (fs.existsSync(yuidocPath)) {
var docinfos = JSON.parse(fs.readFileSync(yuidocPath).toString());
return {
name: docinfos.name,
path: lookupPath
};
}

// TODO: get module path & name
moduleLookup: function () {
// TODO: move up the folder hierarchy to find a src/ directory
var packagePath = path.join(lookupPath, 'package.json');
if (fs.existsSync(packagePath)) {
var packageInfos = JSON.parse(fs.readFileSync(packagePath).toString());
return {
name: packageInfos.name,
path: lookupPath
};
}

// move up the folder hierarchy
var parentPath = path.dirname(lookupPath);
if (parentPath === lookupPath) {
return false;
}
return yproject.projectLookup(parentPath);
},

/**
* Retrieve the project config, if it exists
*/
/*getProjectConfig: function () {
var config;
// get module path & name
moduleLookup: function (lookupPath) {

try {
config = fs.readFileSync('package.json');
config = JSON.parse(config);
if (!lookupPath) {
lookupPath = process.cwd();
}
catch (e) {
console.log('Error reading project config... continue anyway');
config = {};

var buildPath = path.join(lookupPath, 'build.json');
if (fs.existsSync(buildPath)) {
var moduleInfos = JSON.parse(fs.readFileSync(buildPath).toString());
return {
name: moduleInfos.name,
path: lookupPath
};
}

return config;
},*/
// move up the folder hierarchy
var parentPath = path.dirname(lookupPath);
if (parentPath === lookupPath) {
return false;
}
return yproject.moduleLookup(parentPath);
},


mkdir: function(path) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "yproject",
"version": "1.3.0",
"version": "2.0.0",
"description": "Command line tool to simplify YUI3-based projects & librairies development",
"author": "Eric Abouaf <eric.abouaf@gmail.com>",
"bugs": { "web" : "http://github.com/neyric/yproject/issues" },
Expand Down

0 comments on commit a01e63e

Please sign in to comment.