Skip to content

Fix creating multiple projects in a single process #2573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2017

Conversation

rosen-vladimirov
Copy link
Contributor

@rosen-vladimirov rosen-vladimirov commented Feb 24, 2017

In case the CLI is required as a library (used in a long living process, not as a command-line interface), trying to create a project multiple times leads to errors.
The problem is in the projectDataService which caches the path to first created project file (package.json) and uses it for all consecutive operations.
In other cases, when CLI had to use the projectDataService, it always had to call projectDataService.initialize method.

Instead of relying on a magically called initialize method, modify the service methods to work with any project dir and execute the required operation for it.
This will fix the creation of multiple projects as all operations will work with currently passed project directory.
Also remove the code that creates a package.json file during loadProjectFile in projectDataService - it's required only when a project is created, so move it there.

Rename the methods getValue, setValue and removeProperty to getNSValue, setNSValue, removeNSProperty as they are intended to modify the nativescript key in package.json.
We can later expose getValue, setValue and removeProperty (they are currently private).

const props = propertyName.split(".");
const propertyToDelete = props.splice(props.length - 1, 1)[0];

_.each(props, (prop, index: number) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the index here?

this.projectData = projectFileContent ? JSON.parse(projectFileContent) : Object.create(null);
return {
projectData,
indent,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to detect the indent. We will detect it here https://github.com/telerik/mobile-cli-lib/blob/master/file-system.ts#L199

let currentData: any = skipNativeScriptKey ? data : (data[CLIENT_NAME_KEY_IN_PROJECT_FILE] = {});

_.each(props, (prop, index: number) => {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this blank line?

let currentData: any = data[CLIENT_NAME_KEY_IN_PROJECT_FILE] = {};

_.each(props, (prop) => {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this blank line?


});

it("does not override already existing property of project data", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the description should be removes only the selected property?

Copy link
Contributor

@Plamen5kov Plamen5kov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After green build.

@rosen-vladimirov rosen-vladimirov force-pushed the vladimirov/fix-create-multiple-projs branch from f23a425 to 03db4c3 Compare February 28, 2017 14:12
this.loadProjectFile();
return this.projectData ? this.projectData[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE][propertyName] : null;
public setNSValue(projectDir: string, key: string, value: any): void {
return this.setValue(projectDir, this.getNativeScriptPropertyName(key), value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gratuitous return statement here

@rosen-vladimirov rosen-vladimirov force-pushed the vladimirov/fix-create-multiple-projs branch from 03db4c3 to 18ef6ce Compare February 28, 2017 14:32
In case the CLI is `required` as a library (used in a long living process, not as a command-line interface), trying to create a project multiple times leads ot error.
The problem is in the `projectDataService` which caches the path to first created project file (package.json) and uses it for all consecutive operations.
In other cases, when CLI had to use the projectDataService, it always had to call `projectDataService.initialize` method.

Instead of relying on a magically called initialize method, modify the service methods to work with any project dir and execute the required operation for it.
This will fix the creation of multiple projects as all operations will work with currently passed project directory.
Also remove the code that creates a `package.json` file during `loadProjectFile` in projectDataService - it's required only when a project is created, so move it there.

Rename the methods getValue, setValue and removeProperty to getNSValue, setNSValue, removeNSProperty as they are intended to modify the nativescript key in package.json.
We can later expose getValue, setValue and removeProperty (they are currently private).

Remove the indentation detection as `$fs.writeJson` file already does this.
@rosen-vladimirov rosen-vladimirov force-pushed the vladimirov/fix-create-multiple-projs branch from 18ef6ce to 7f403b4 Compare February 28, 2017 14:42
@rosen-vladimirov rosen-vladimirov merged commit a39cf09 into master Feb 28, 2017
@rosen-vladimirov rosen-vladimirov deleted the vladimirov/fix-create-multiple-projs branch February 28, 2017 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants