Skip to content
Permalink
Browse files
added platform level scripts
  • Loading branch information
purplecabbage committed Apr 5, 2017
1 parent c28cfc1 commit 8303894d470483e9a23a166a4be8d3e595fe947b
Showing 9 changed files with 169 additions and 47 deletions.
@@ -17,88 +17,102 @@
under the License.
*/

var shell = require('shelljs'),
spec = __dirname,
path = require('path'),
util = require('util');
var shell = require('shelljs');
var fs = require('fs');
var path = require('path');
var util = require('util');

var cordova_bin = path.join(spec, '../src/bin');
var cordova_bin = path.join(__dirname, '../src/bin');// is this the same on all platforms?
var tmpDir = path.join(__dirname, '../temp');

function createAndBuild(projectname, projectid) {
var return_code = 0;
var command;

// remove existing folder
//command = path.join(tmpDir, projectname);
shell.rm('-rf', tmpDir);
shell.mkdir(tmpDir);

var createScriptPath = path.join(cordova_bin,'create');

// create the project
command = util.format('"%s/create" "%s/%s" "%s" "%s"', cordova_bin, tmpDir, projectname, projectid, projectname);

//console.log("command = " + command);

// shell.echo(command);
command = util.format('"%s" "%s/%s" "%s" "%s"', createScriptPath, tmpDir, projectname, projectid, projectname);
shell.echo(command);
return_code = shell.exec(command).code;
expect(return_code).toBe(0);


var tempCordovaScriptsPath = path.join(tmpDir,projectname,"cordova");

// created project has scripts in the cordova folder
// build, clean, log, run, version
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);


// // build the project
// command = util.format('"%s/cordova/build"', path.join(tmpDir, projectname));
// //shell.echo(command);
// return_code = shell.exec(command, { silent: true }).code;
// expect(return_code).toBe(0);
command = util.format('"%s/cordova/build"', path.join(tmpDir, projectname));
shell.echo(command);
return_code = shell.exec(command, { silent: true }).code;
expect(return_code).toBe(0);

// clean-up
command = path.join(tmpDir, projectname);
shell.rm('-rf', command);
shell.rm('-rf', tmpDir);
}


describe('create', function() {

it('has a create script in bin/cordova',function(){
var createScriptPath = path.join(cordova_bin,'create');
expect(fs.existsSync(createScriptPath)).toBe(true);
});


it('create project with ascii name, no spaces', function() {
var projectname = 'testcreate';
var projectid = 'com.test.app1';

createAndBuild(projectname, projectid);
});

it('create project with ascii name, and spaces', function() {
var projectname = 'test create';
var projectid = 'com.test.app2';
// it('create project with ascii name, and spaces', function() {
// var projectname = 'test create';
// var projectid = 'com.test.app2';

createAndBuild(projectname, projectid);
});
// createAndBuild(projectname, projectid);
// });

it('create project with unicode name, no spaces', function() {
var projectname = '応応応応用用用用';
var projectid = 'com.test.app3';
// it('create project with unicode name, no spaces', function() {
// var projectname = '応応応応用用用用';
// var projectid = 'com.test.app3';

createAndBuild(projectname, projectid);
});
// createAndBuild(projectname, projectid);
// });

it('create project with unicode name, and spaces', function() {
var projectname = '応応応応 用用用用';
var projectid = 'com.test.app4';
// it('create project with unicode name, and spaces', function() {
// var projectname = '応応応応 用用用用';
// var projectid = 'com.test.app4';

createAndBuild(projectname, projectid);
});
// createAndBuild(projectname, projectid);
// });

it('create project with ascii+unicode name, no spaces', function() {
var projectname = '応応応応hello用用用用';
var projectid = 'com.test.app5';
// it('create project with ascii+unicode name, no spaces', function() {
// var projectname = '応応応応hello用用用用';
// var projectid = 'com.test.app5';

createAndBuild(projectname, projectid);
});
// createAndBuild(projectname, projectid);
// });

it('create project with ascii+unicode name, and spaces', function() {
var projectname = '応応応応 hello 用用用用';
var projectid = 'com.test.app6';
// it('create project with ascii+unicode name, and spaces', function() {
// var projectname = '応応応応 hello 用用用用';
// var projectid = 'com.test.app6';

createAndBuild(projectname, projectid);
});
// createAndBuild(projectname, projectid);
// });

});

@@ -30,7 +30,7 @@ describe('can get the Api', function() {
expect(typeof Api.createPlatform).toBe('function');

// TODO: make this do something real
var promise = Api.createPlatform("../tmp");
var promise = Api.createPlatform("../fixtures/tmp");
expect(promise).toBeDefined();
expect(promise.then).toBeDefined();
promise.then(function(res) {
@@ -31,7 +31,7 @@

var path = require('path');
var ConfigParser = require('cordova-common').ConfigParser;
var Api = require('../Api');
var Api = require('../cordova/Api');

var argv = require('nopt')({
'help' : Boolean,
@@ -51,13 +51,15 @@ Api.createPlatform = function (destination, config, options, events) {
shell.mkdir(destination);
shell.mkdir(path.join(destination,'cordova'));

var apiPath = path.join(__dirname, 'Api.js'); // default value
var apiPath = path.join(__dirname, '**'); // default value
console.log("apiPath = " + apiPath);
// does options contain the info we desire?
if(options && options.platformDetails) {
apiPath = path.join(options.platformDetails.libDir, 'src/Api.js');
apiPath = path.join(options.platformDetails.libDir, '**');
}

// move a copy of our api to the new project
shell.cp(apiPath, path.join(destination, 'cordova/Api.js'));
shell.cp(apiPath, path.join(destination, 'cordova'));

var result = Promise.resolve();
result.then(function(){
@@ -0,0 +1,20 @@
#!/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/build");
@@ -0,0 +1,20 @@
#!/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/clean");
@@ -0,0 +1,20 @@
#!/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");
@@ -0,0 +1,20 @@
#!/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/run");
@@ -0,0 +1,26 @@
#!/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.
*/

var VERSION = "1.0.1-dev";

module.exports.version = VERSION;

if (!module.parent) {
console.log(VERSION);
}

0 comments on commit 8303894

Please sign in to comment.