refactor (create): simplify project creation (#129)
* reorganize template structure
* create npm pack pre-hook script (also performs on publish)
* stop packaging of raw cordova-js source files with deployed npm package & do not bundle with app
diff --git a/.eslintignore b/.eslintignore
index a547141..e2cdfc6 100644
--- a/.eslintignore
+++ b/.eslintignore
@@ -1 +1,2 @@
-cordova-lib/cordova.js
\ No newline at end of file
+cordova-lib/cordova.js
+bin/templates/platform_www/cordova.js
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 735c56d..5efb8f8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@
node_modules/
.nyc_output/
coverage/
+bin/templates/platform_www/cordova.js
\ No newline at end of file
diff --git a/.npm-scripts/prepack.js b/.npm-scripts/prepack.js
new file mode 100644
index 0000000..3f580c0
--- /dev/null
+++ b/.npm-scripts/prepack.js
@@ -0,0 +1,5 @@
+const { resolve } = require('path');
+const { copyFileSync } = require('fs-extra');
+
+// copy cordova.js to bin/templates/project
+copyFileSync(resolve('cordova-lib/cordova.js'), resolve('bin/templates/platform_www/cordova.js'));
diff --git a/.npmignore b/.npmignore
index ad2eb52..a3960e5 100644
--- a/.npmignore
+++ b/.npmignore
@@ -19,4 +19,9 @@
.git
.gitattributes
.github
-.gitignore
\ No newline at end of file
+.gitignore
+
+# others
+.npm-scripts
+cordova-js-src
+cordova-lib
diff --git a/bin/create b/bin/create
index d2fa7b9..4d1118a 100755
--- a/bin/create
+++ b/bin/create
@@ -52,7 +52,7 @@
console.log(' <project_template_dir>: Path to project template (override).');
process.exit(0);
} else {
- const configPath = path.resolve(__dirname, 'templates/project/config.xml');
+ const configPath = path.resolve(__dirname, 'templates/platform_www/config.xml');
const config = new ConfigParser(configPath);
// apply overrides (package and project names
diff --git a/bin/lib/create.js b/bin/lib/create.js
index 7d50ff4..7c3f1b2 100644
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@ -26,21 +26,21 @@
const check_reqs = require('./../templates/cordova/lib/check_reqs.js');
// exported method to create a project, returns a promise that resolves with null
-module.exports.createProject = (project_path, package_name, project_name, options) => {
+module.exports.createProject = (platform_dir, package_name, project_name, options) => {
/*
// create the dest and the standard place for our api to live
// platforms/platformName/cordova/Api.js
*/
events.emit('log', 'Creating Cordova project for cordova-electron:');
- events.emit('log', '\tPath: ' + project_path);
+ events.emit('log', '\tPath: ' + platform_dir);
events.emit('log', '\tName: ' + project_name);
// Set default values for path, package and name
- project_path = project_path || 'CordovaExample';
+ platform_dir = platform_dir || 'CordovaExample';
// Check if project already exists
- if (fs.existsSync(project_path)) {
+ if (fs.existsSync(platform_dir)) {
events.emit('error', 'Oops, destination already exists! Delete it and try again');
}
@@ -51,37 +51,15 @@
}
// Make sure that the platform directory is created if missing.
- fs.ensureDirSync(project_path);
+ fs.ensureDirSync(platform_dir);
- // copy templates/build-res directory ( recursive )
- fs.copySync(path.join(ROOT, 'bin/templates/build-res'), path.join(project_path, 'build-res'), { overwrite: false });
-
- // copy templates/cordova directory ( recursive )
- fs.copySync(path.join(ROOT, 'bin/templates/cordova'), path.join(project_path, 'cordova'), { overwrite: false });
-
- // copy templates/www directory ( recursive )
- fs.copySync(path.join(ROOT, 'bin/templates/project/www'), path.join(project_path, 'www'), { overwrite: false });
+ // copy templates directory to the platform directory recursively
+ fs.copySync(path.join(ROOT, 'bin/templates'), path.join(platform_dir), { overwrite: false });
// recreate our node_modules structure in the new project
if (fs.existsSync(path.join(ROOT, 'node_modules'))) {
- fs.copySync(path.join(ROOT, 'node_modules'), path.join(project_path, 'cordova', 'node_modules'), { overwrite: false });
+ fs.copySync(path.join(ROOT, 'node_modules'), path.join(platform_dir, 'cordova', 'node_modules'), { overwrite: false });
}
- const platform_www = path.join(project_path, 'platform_www');
-
- fs.ensureDirSync(platform_www);
-
- // copy cordova-js-src directory
- fs.copySync(path.join(ROOT, 'cordova-js-src'), path.join(platform_www, 'cordova-js-src'), { overwrite: false });
-
- // copy cordova js file to platform_www
- fs.copySync(path.join(ROOT, 'cordova-lib', 'cordova.js'), path.join(platform_www, 'cordova.js'), { overwrite: false });
-
- // copy cdv-electron-main.js
- fs.copySync(path.join(ROOT, 'bin/templates/project/cdv-electron-main.js'), path.join(platform_www, 'cdv-electron-main.js'), { overwrite: false });
-
- // copy cdv-electron-settings.json
- fs.copySync(path.join(ROOT, 'bin/templates/project/cdv-electron-settings.json'), path.join(platform_www, 'cdv-electron-settings.json'), { overwrite: false });
-
return Promise.resolve();
};
diff --git a/bin/templates/project/cdv-electron-main.js b/bin/templates/platform_www/cdv-electron-main.js
similarity index 100%
rename from bin/templates/project/cdv-electron-main.js
rename to bin/templates/platform_www/cdv-electron-main.js
diff --git a/bin/templates/project/cdv-electron-settings.json b/bin/templates/platform_www/cdv-electron-settings.json
similarity index 100%
rename from bin/templates/project/cdv-electron-settings.json
rename to bin/templates/platform_www/cdv-electron-settings.json
diff --git a/bin/templates/project/config.xml b/bin/templates/platform_www/config.xml
similarity index 100%
rename from bin/templates/project/config.xml
rename to bin/templates/platform_www/config.xml
diff --git a/bin/templates/project/www/css/index.css b/bin/templates/www/css/index.css
similarity index 100%
rename from bin/templates/project/www/css/index.css
rename to bin/templates/www/css/index.css
diff --git a/bin/templates/project/www/icons/icon.png b/bin/templates/www/icons/icon.png
similarity index 100%
rename from bin/templates/project/www/icons/icon.png
rename to bin/templates/www/icons/icon.png
Binary files differ
diff --git a/bin/templates/project/www/img/logo.png b/bin/templates/www/img/logo.png
similarity index 100%
rename from bin/templates/project/www/img/logo.png
rename to bin/templates/www/img/logo.png
Binary files differ
diff --git a/bin/templates/project/www/img/splash.png b/bin/templates/www/img/splash.png
similarity index 100%
rename from bin/templates/project/www/img/splash.png
rename to bin/templates/www/img/splash.png
Binary files differ
diff --git a/bin/templates/project/www/index.html b/bin/templates/www/index.html
similarity index 100%
rename from bin/templates/project/www/index.html
rename to bin/templates/www/index.html
diff --git a/bin/templates/project/www/js/index.js b/bin/templates/www/js/index.js
similarity index 100%
rename from bin/templates/project/www/js/index.js
rename to bin/templates/www/js/index.js
diff --git a/package.json b/package.json
index 1dcb4be..e4622e7 100644
--- a/package.json
+++ b/package.json
@@ -15,6 +15,7 @@
],
"scripts": {
"lint": "eslint .",
+ "prepack": "node .npm-scripts/prepack.js",
"test": "npm run lint && npm run test:coverage",
"test:coverage": "nyc npm run test:unit",
"test:unit": "jasmine --config=tests/spec/unit.json"
@@ -51,8 +52,10 @@
"nyc": {
"all": true,
"exclude": [
+ ".npm-scripts/",
"bin/templates/build-res/",
- "bin/templates/project/",
+ "bin/templates/platform_www/",
+ "bin/templates/www/",
"cordova-js-src/",
"cordova-lib/",
"coverage/",