Skip to content

Commit

Permalink
Copy node_modules if the directory exists (apache#607)
Browse files Browse the repository at this point in the history
  • Loading branch information
erisu authored Dec 19, 2018
1 parent 5f44af3 commit f228d90
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 1 addition & 2 deletions bin/create
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ if (argv['activity-name']) config.setName(argv['activity-name']);
var options = {
link: argv.link || argv.shared,
customTemplate: argv.argv.remain[3],
activityName: argv['activity-name'],
copyPlatformNodeModules: true
activityName: argv['activity-name']
};

require('./templates/cordova/loggingHelper').adjustLoggerLevel(argv);
Expand Down
9 changes: 6 additions & 3 deletions bin/lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,18 @@ function copyBuildRules (projectPath, isLegacy) {
}
}

function copyScripts (projectPath, options) {
function copyScripts (projectPath) {
var bin = path.join(ROOT, 'bin');
var srcScriptsDir = path.join(bin, 'templates', 'cordova');
var destScriptsDir = path.join(projectPath, 'cordova');
// Delete old scripts directory if this is an update.
shell.rm('-rf', destScriptsDir);
// Copy in the new ones.
shell.cp('-r', srcScriptsDir, projectPath);
if (options.copyPlatformNodeModules) shell.cp('-r', path.join(ROOT, 'node_modules'), destScriptsDir);

let nodeModulesDir = path.join(ROOT, 'node_modules');
if (fs.existsSync(nodeModulesDir)) shell.cp('-r', nodeModulesDir, destScriptsDir);

shell.cp(path.join(bin, 'check_reqs*'), destScriptsDir);
shell.cp(path.join(bin, 'android_sdk_version*'), destScriptsDir);
var check_reqs = path.join(destScriptsDir, 'check_reqs');
Expand Down Expand Up @@ -324,7 +327,7 @@ exports.create = function (project_path, config, options, events) {
var manifest_path = path.join(app_path, 'AndroidManifest.xml');
manifest.write(manifest_path);

exports.copyScripts(project_path, options);
exports.copyScripts(project_path);
exports.copyBuildRules(project_path);
});
// Link it to local android install.
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ describe('create', function () {
});
it('should copy template scripts into generated project', function (done) {
create.create(project_path, config_mock, {}, events_mock).then(function () {
expect(create.copyScripts).toHaveBeenCalledWith(project_path, {});
expect(create.copyScripts).toHaveBeenCalledWith(project_path);
}).fail(fail).done(done);
});
it('should copy build rules / gradle files into generated project', function (done) {
Expand Down

0 comments on commit f228d90

Please sign in to comment.