breaking: remove platform-centered workflow (#138)
* breaking: remove platform centric binaries
* refactor (Api): enforce config argument
* test (Api): always provide config argument to createPlatform
diff --git a/bin/create b/bin/create
deleted file mode 100755
index 4d1118a..0000000
--- a/bin/create
+++ /dev/null
@@ -1,73 +0,0 @@
-#!/usr/bin/env node
-
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-/*
- * create a Cordova project
- *
- * USAGE
- * ./create <path_to_new_project> <package_name> <project_name>
- *
- * EXAMPLE
- * ./create ~/Desktop/radness org.apache.cordova.radness Radness
- */
-
-const path = require('path');
-const ConfigParser = require('cordova-common').ConfigParser;
-const Api = require('./templates/cordova/Api');
-
-const argv = require('nopt')({
- help: Boolean,
- cli: Boolean,
- shared: Boolean, // alias for --link
- link: Boolean
-}, { d: '--verbose' });
-
-const projectPath = argv.argv.remain[0];
-
-if (argv.help || !projectPath) {
- console.log('Usage: $0 [--link] [--cli] <path_to_new_project> <package_name> <project_name> [<project_template_dir>]');
- console.log(' --link (optional): Link directly against the shared copy of the CordovaLib instead of a copy of it.');
- console.log(' --cli (optional): Use the CLI-project template.');
- console.log(' <path_to_new_project>: Path to your new Cordova iOS project');
- console.log(' <package_name>: Package name, following reverse-domain style convention');
- console.log(' <project_name>: Project name');
- console.log(' <project_template_dir>: Path to project template (override).');
- process.exit(0);
-} else {
- const configPath = path.resolve(__dirname, 'templates/platform_www/config.xml');
- const config = new ConfigParser(configPath);
-
- // apply overrides (package and project names
- if (argv.argv.remain[1]) {
- config.setPackageName(argv.argv.remain[1]);
- }
- if (argv.argv.remain[2]) {
- config.setName(argv.argv.remain[2]);
- }
-
- const options = {
- cli: argv.cli,
- link: argv.link || argv.shared,
- customTemplate: argv.argv.remain[3]
- };
-
- Api.createPlatform(projectPath, config, options);
-}
diff --git a/bin/create.bat b/bin/create.bat
deleted file mode 100644
index be02257..0000000
--- a/bin/create.bat
+++ /dev/null
@@ -1,26 +0,0 @@
-:: Licensed to the Apache Software Foundation (ASF) under one
-:: or more contributor license agreements. See the NOTICE file
-:: distributed with this work for additional information
-:: regarding copyright ownership. The ASF licenses this file
-:: to you under the Apache License, Version 2.0 (the
-:: "License"); you may not use this file except in compliance
-:: with the License. You may obtain a copy of the License at
-::
-:: http://www.apache.org/licenses/LICENSE-2.0
-::
-:: Unless required by applicable law or agreed to in writing,
-:: software distributed under the License is distributed on an
-:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-:: KIND, either express or implied. See the License for the
-:: specific language governing permissions and limitations
-:: under the License.
-
-@ECHO OFF
-SET script_path="%~dp0create"
-IF EXIST %script_path% (
- node %script_path% %*
-) ELSE (
- ECHO.
- ECHO ERROR: Could not find 'create' script in 'bin' folder, aborting...>&2
- EXIT /B 1
-)
\ No newline at end of file
diff --git a/bin/templates/cordova/Api.js b/bin/templates/cordova/Api.js
index bf5dc64..bdd033f 100644
--- a/bin/templates/cordova/Api.js
+++ b/bin/templates/cordova/Api.js
@@ -26,6 +26,7 @@
const {
ActionStack,
ConfigChanges: { PlatformMunger },
+ CordovaError,
CordovaLogger,
events: selfEvents,
PlatformJson,
@@ -361,10 +362,12 @@
Api.updatePlatform = () => Promise.resolve();
Api.createPlatform = (dest, config, options, events) => {
+ if (!config) throw new CordovaError('An Electron platform can not be created with a missing config argument.');
+
events = setupEvents(events);
- const name = config ? config.name() : 'HelloCordova';
- const id = config ? config.packageName() : 'io.cordova.hellocordova';
+ const name = config.name();
+ const id = config.packageName();
try {
// we create the project using our scripts in this platform
diff --git a/bin/templates/cordova/build b/bin/templates/cordova/build
deleted file mode 100755
index 5ad92d4..0000000
--- a/bin/templates/cordova/build
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env node
-
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-const argv = require('nopt')({
- help: Boolean
-}, {
- help: ['/?', '-h', 'help', '-help', '--help', '/help']
-});
-
-argv.binPath = process.argv[1];
-
-const build = require('./lib/build');
-
-if (argv.help) {
- build.help(argv);
- process.exit(0);
-}
-
-build.run(argv);
diff --git a/bin/templates/cordova/build.bat b/bin/templates/cordova/build.bat
deleted file mode 100644
index edf884c..0000000
--- a/bin/templates/cordova/build.bat
+++ /dev/null
@@ -1,26 +0,0 @@
-:: Licensed to the Apache Software Foundation (ASF) under one
-:: or more contributor license agreements. See the NOTICE file
-:: distributed with this work for additional information
-:: regarding copyright ownership. The ASF licenses this file
-:: to you under the Apache License, Version 2.0 (the
-:: "License"); you may not use this file except in compliance
-:: with the License. You may obtain a copy of the License at
-::
-:: http://www.apache.org/licenses/LICENSE-2.0
-::
-:: Unless required by applicable law or agreed to in writing,
-:: software distributed under the License is distributed on an
-:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-:: KIND, either express or implied. See the License for the
-:: specific language governing permissions and limitations
-:: under the License.
-
-@ECHO OFF
-SET script_path="%~dp0build"
-IF EXIST %script_path% (
- node %script_path% %*
-) ELSE (
- ECHO.
- ECHO ERROR: Could not find 'build' script in 'cordova' folder, aborting...>&2
- EXIT /B 1
-)
diff --git a/bin/templates/cordova/clean b/bin/templates/cordova/clean
deleted file mode 100755
index 6115685..0000000
--- a/bin/templates/cordova/clean
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env node
-
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-const argv = require('nopt')({
- help: Boolean
-}, {
- help: ['/?', '-h', 'help', '-help', '--help', '/help']
-});
-
-argv.binPath = process.argv[1];
-
-const clean = require('./lib/clean');
-
-if (argv.help) {
- clean.help(argv);
- process.exit(0);
-}
-
-clean.run(argv);
diff --git a/bin/templates/cordova/clean.bat b/bin/templates/cordova/clean.bat
deleted file mode 100644
index 9049aee..0000000
--- a/bin/templates/cordova/clean.bat
+++ /dev/null
@@ -1,26 +0,0 @@
-:: Licensed to the Apache Software Foundation (ASF) under one
-:: or more contributor license agreements. See the NOTICE file
-:: distributed with this work for additional information
-:: regarding copyright ownership. The ASF licenses this file
-:: to you under the Apache License, Version 2.0 (the
-:: "License"); you may not use this file except in compliance
-:: with the License. You may obtain a copy of the License at
-::
-:: http://www.apache.org/licenses/LICENSE-2.0
-::
-:: Unless required by applicable law or agreed to in writing,
-:: software distributed under the License is distributed on an
-:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-:: KIND, either express or implied. See the License for the
-:: specific language governing permissions and limitations
-:: under the License.
-
-@ECHO OFF
-SET script_path="%~dp0clean"
-IF EXIST %script_path% (
- node %script_path% %*
-) ELSE (
- ECHO.
- ECHO ERROR: Could not find 'clean' script in 'cordova' folder, aborting...>&2
- EXIT /B 1
-)
diff --git a/bin/templates/cordova/log b/bin/templates/cordova/log
deleted file mode 100755
index 4a027b0..0000000
--- a/bin/templates/cordova/log
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/usr/bin/env node
-
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-console.log('cordova/log');
diff --git a/bin/templates/cordova/run b/bin/templates/cordova/run
deleted file mode 100755
index bdbfc50..0000000
--- a/bin/templates/cordova/run
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/usr/bin/env node
-
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-const argv = require('nopt')({
- help: Boolean,
- target: String,
- port: Number
-}, {
- help: ['/?', '-h', 'help', '-help', '--help', '/help']
-});
-
-argv.binPath = process.argv[1];
-
-const runForrest = require('./lib/run');
-
-if (argv.help) {
- runForrest.help(argv);
- process.exit(0);
-}
-
-runForrest.run(argv);
diff --git a/bin/templates/cordova/run.bat b/bin/templates/cordova/run.bat
deleted file mode 100644
index 18023b5..0000000
--- a/bin/templates/cordova/run.bat
+++ /dev/null
@@ -1,26 +0,0 @@
-:: Licensed to the Apache Software Foundation (ASF) under one
-:: or more contributor license agreements. See the NOTICE file
-:: distributed with this work for additional information
-:: regarding copyright ownership. The ASF licenses this file
-:: to you under the Apache License, Version 2.0 (the
-:: "License"); you may not use this file except in compliance
-:: with the License. You may obtain a copy of the License at
-::
-:: http://www.apache.org/licenses/LICENSE-2.0
-::
-:: Unless required by applicable law or agreed to in writing,
-:: software distributed under the License is distributed on an
-:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-:: KIND, either express or implied. See the License for the
-:: specific language governing permissions and limitations
-:: under the License.
-
-@ECHO OFF
-SET script_path="%~dp0run"
-IF EXIST %script_path% (
- node %script_path% %*
-) ELSE (
- ECHO.
- ECHO ERROR: Could not find 'run' script in 'cordova' folder, aborting...>&2
- EXIT /B 1
-)
diff --git a/bin/update b/bin/update
deleted file mode 100644
index f2e7c75..0000000
--- a/bin/update
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/usr/bin/env node
-
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-const update = require('./lib/update');
-
-// check for help flag
-if (['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) > -1) {
- update.help();
-} else {
- update.run(process.argv)
- .then(
- () => {
- console.log('Successfully updated electron project.'); // won't happen .. it's not supported
- },
- err => {
- console.error('Update failed due to', err);
- process.exit(2);
- }
- );
-}
diff --git a/bin/update.bat b/bin/update.bat
deleted file mode 100644
index 0573e69..0000000
--- a/bin/update.bat
+++ /dev/null
@@ -1,26 +0,0 @@
-:: Licensed to the Apache Software Foundation (ASF) under one
-:: or more contributor license agreements. See the NOTICE file
-:: distributed with this work for additional information
-:: regarding copyright ownership. The ASF licenses this file
-:: to you under the Apache License, Version 2.0 (the
-:: "License"); you may not use this file except in compliance
-:: with the License. You may obtain a copy of the License at
-::
-:: http://www.apache.org/licenses/LICENSE-2.0
-::
-:: Unless required by applicable law or agreed to in writing,
-:: software distributed under the License is distributed on an
-:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-:: KIND, either express or implied. See the License for the
-:: specific language governing permissions and limitations
-:: under the License.
-
-@ECHO OFF
-SET script_path="%~dp0update"
-IF EXIST %script_path% (
- node %script_path% %*
-) ELSE (
- ECHO.
- ECHO ERROR: Could not find 'update' script in 'bin' folder, aborting...>&2
- EXIT /B 1
-)
diff --git a/package.json b/package.json
index c10c15f..b868b6c 100644
--- a/package.json
+++ b/package.json
@@ -3,7 +3,6 @@
"version": "2.0.0-dev",
"description": "electron apps as a target for cordova developers",
"main": "bin/templates/cordova/Api.js",
- "bin": "bin/create",
"repository": "github:apache/cordova-electron",
"bugs": "https://github.com/apache/cordova-electron/issues",
"kewords": [
diff --git a/tests/spec/unit/Api.spec.js b/tests/spec/unit/Api.spec.js
index 2aae8fe..32a4a8e 100644
--- a/tests/spec/unit/Api.spec.js
+++ b/tests/spec/unit/Api.spec.js
@@ -20,7 +20,7 @@
const fs = require('fs-extra');
const path = require('path');
const rewire = require('rewire');
-const { events, PluginInfo } = require('cordova-common');
+const { events, PluginInfo, ConfigParser } = require('cordova-common');
const templateDir = path.resolve(__dirname, '..', '..', '..', 'bin', 'templates');
@@ -423,21 +423,21 @@
});
describe('createPlatform method', () => {
+ let config;
+
beforeEach(() => {
fs.removeSync(tmpDir);
+ config = new ConfigParser(path.join(FIXTURES, 'test-config-empty.xml'));
});
afterEach(() => {
fs.removeSync(tmpDir);
});
- /**
- * @todo improve createPlatform to test actual created platforms.
- */
- it('should export static createPlatform function', () => {
+ it('should create cordova project at the provided destination', () => {
spyOn(events, 'emit');
- return Api.createPlatform(tmpDir)
+ return Api.createPlatform(tmpDir, config)
.then((results) => {
expect(events.emit).toHaveBeenCalledWith(
'log',
@@ -450,7 +450,11 @@
it('should emit createPlatform not callable when error occurs.', () => {
spyOn(create, 'createProject').and.returnValue(new Error('Some Random Error'));
- expect(() => Api.createPlatform(tmpDir)).toThrowError();
+ expect(() => Api.createPlatform(tmpDir, config)).toThrowError();
+ });
+
+ it('should throw error when config argument is missing.', () => {
+ expect(() => Api.createPlatform(tmpDir)).toThrowError(/An Electron platform can not be created with a missing config argument./);
});
});
diff --git a/tests/spec/unit/create.spec.js b/tests/spec/unit/create.spec.js
index ac40ecc..36fc91f 100644
--- a/tests/spec/unit/create.spec.js
+++ b/tests/spec/unit/create.spec.js
@@ -20,35 +20,11 @@
const fs = require('fs-extra');
const path = require('path');
const rewire = require('rewire');
-const execa = require('execa');
const cordova_bin = path.join(__dirname, '../../../bin');// is this the same on all platforms?
const tmpDir = path.join(__dirname, '../../../temp');
-const createScriptPath = path.join(cordova_bin, 'create');
const create = rewire(path.join(cordova_bin, 'lib', 'create'));
-function createAndVerify (projectname, projectid) {
- // remove existing folder
- fs.removeSync(tmpDir);
- fs.ensureDirSync(tmpDir);
-
- const tempProjectDir = path.join(tmpDir, projectname);
- const projectCreateProcess = execa.sync(createScriptPath, [tempProjectDir, projectid, projectname]);
- expect(projectCreateProcess.exitCode).toBe(0);
-
- // created project has scripts in the cordova folder
- // build, clean, log, run, version
- const tempCordovaScriptsPath = path.join(tempProjectDir, 'cordova');
- expect(fs.existsSync(path.join(tempCordovaScriptsPath, 'build'))).toBe(true);
- expect(fs.existsSync(path.join(tempCordovaScriptsPath, 'clean'))).toBe(true);
- expect(fs.existsSync(path.join(tempCordovaScriptsPath, 'log'))).toBe(true);
- expect(fs.existsSync(path.join(tempCordovaScriptsPath, 'run'))).toBe(true);
- expect(fs.existsSync(path.join(tempCordovaScriptsPath, 'version'))).toBe(true);
-
- // clean-up
- fs.removeSync(tmpDir);
-}
-
function createAndValidateProjectDirName (projectname, projectid, { copyNodeModules = false } = {}) {
// remove existing folder
fs.removeSync(tmpDir);
@@ -75,17 +51,6 @@
}
describe('create', () => {
- it('has a create script in bin/cordova', () => {
- expect(fs.existsSync(createScriptPath)).toBe(true);
- });
-
- it('create project and check for bin files', () => {
- const projectname = 'testcreate';
- const projectid = 'com.test.app1';
-
- createAndVerify(projectname, projectid);
- });
-
it('create project with ascii name, no spaces', () => {
const projectname = 'testcreate';
const projectid = 'com.test.app1';