Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Module update + project and module lookup

  • Loading branch information...
commit a01e63eb6764134b2deafad48f54b8182a411e3d 1 parent fd3c50c
@neyric authored
View
4 README.md
@@ -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 :
View
13 bin/ymodule.js
@@ -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);
}
View
7 example.sh
@@ -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
View
89 lib/yproject.js
@@ -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]) {
@@ -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) {
View
2  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" },
Please sign in to comment.
Something went wrong with that request. Please try again.