-
-
Notifications
You must be signed in to change notification settings - Fork 196
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
Conversation
lib/services/project-data-service.ts
Outdated
const props = propertyName.split("."); | ||
const propertyToDelete = props.splice(props.length - 1, 1)[0]; | ||
|
||
_.each(props, (prop, index: number) => { |
There was a problem hiding this comment.
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?
lib/services/project-data-service.ts
Outdated
this.projectData = projectFileContent ? JSON.parse(projectFileContent) : Object.create(null); | ||
return { | ||
projectData, | ||
indent, |
There was a problem hiding this comment.
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) => { | ||
|
There was a problem hiding this comment.
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) => { | ||
|
There was a problem hiding this comment.
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", () => { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After green build.
f23a425
to
03db4c3
Compare
lib/services/project-data-service.ts
Outdated
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gratuitous return
statement here
03db4c3
to
18ef6ce
Compare
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.
18ef6ce
to
7f403b4
Compare
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 duringloadProjectFile
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).