You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by er...@apache.org on 2020/01/21 00:25:38 UTC
[cordova-electron] branch master updated: refactor (create):
simplify project creation (#129)
This is an automated email from the ASF dual-hosted git repository.
erisu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-electron.git
The following commit(s) were added to refs/heads/master by this push:
new 7af81cc refactor (create): simplify project creation (#129)
7af81cc is described below
commit 7af81cc68d728a4aee12642c46e279395504f775
Author: エリス <er...@users.noreply.github.com>
AuthorDate: Tue Jan 21 09:25:31 2020 +0900
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
---
.eslintignore | 3 +-
.gitignore | 1 +
.npm-scripts/prepack.js | 5 +++
.npmignore | 7 +++-
bin/create | 2 +-
bin/lib/create.js | 38 +++++----------------
.../{project => platform_www}/cdv-electron-main.js | 0
.../cdv-electron-settings.json | 0
bin/templates/{project => platform_www}/config.xml | 0
bin/templates/{project => }/www/css/index.css | 0
bin/templates/{project => }/www/icons/icon.png | Bin
bin/templates/{project => }/www/img/logo.png | Bin
bin/templates/{project => }/www/img/splash.png | Bin
bin/templates/{project => }/www/index.html | 0
bin/templates/{project => }/www/js/index.js | 0
package.json | 5 ++-
16 files changed, 27 insertions(+), 34 deletions(-)
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 @@ temp
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 @@ npm-debug.log*
.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 @@ if (argv.help || !projectPath) {
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 events = require('cordova-common').events;
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 @@ module.exports.createProject = (project_path, package_name, project_name, option
}
// 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
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
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
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/",
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org