Skip to content

Commit 25edea4

Browse files
NathanWalkerrigor789
authored andcommitted
chore: config and template handling
1 parent e0f8f0f commit 25edea4

File tree

9 files changed

+82
-402
lines changed

9 files changed

+82
-402
lines changed

lib/constants.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,15 @@ export class SubscribeForNewsletterMessages {
297297
":";
298298
}
299299

300-
export class TemplateVersions {
301-
public static v1 = "v1";
302-
public static v2 = "v2";
303-
}
304-
305-
export class ProjectTemplateErrors {
306-
public static InvalidTemplateVersionStringFormat =
307-
"The template '%s' has a NativeScript version '%s' that is not supported. Unable to create project from it.";
308-
}
300+
// export class TemplateVersions {
301+
// public static v1 = "v1";
302+
// public static v2 = "v2";
303+
// }
304+
305+
// export class ProjectTemplateErrors {
306+
// public static InvalidTemplateVersionStringFormat =
307+
// "The template '%s' has a NativeScript version '%s' that is not supported. Unable to create project from it.";
308+
// }
309309

310310
export class Hooks {
311311
public static createProject = "createProject";

lib/definitions/project.d.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,20 @@ interface IProjectConfigService {
299299
* Get value for a given config key path
300300
* @param key the property key path
301301
*/
302-
getValue(key: string): any;
303-
304-
detectInfo(projectDir?: string): { hasTS: boolean; hasJS: boolean, configJSFilePath: string; configTSFilePath: string };
302+
getValue(key: string): any;
305303

306-
setAppId(projectId: string, projectDir?: string): void;
304+
detectInfo(
305+
projectDir?: string
306+
): {
307+
hasTS: boolean;
308+
hasJS: boolean;
309+
configJSFilePath: string;
310+
configTSFilePath: string;
311+
};
312+
313+
getDefaultTSConfig(appId: string): string;
314+
315+
writeDefaultConfig(projectDir?: string, appId?: string): void;
307316
}
308317

309318
interface IAssetItem {
@@ -367,14 +376,6 @@ interface ITemplateData {
367376
* In case template is v2, will be null.
368377
*/
369378
templatePath: string;
370-
/**
371-
* The templateVersion property from nativescript section inside package.json file
372-
* "nativescript": {
373-
"id": "org.nativescript.app6",
374-
"templateVersion": "v2"
375-
}
376-
*/
377-
templateVersion: string;
378379
/**
379380
* The whole content of package.json file
380381
*/

lib/project-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ export class ProjectData implements IProjectData {
262262
return this.nsConfig[constants.CONFIG_NS_APP_ENTRY];
263263
}
264264

265-
return constants.APP_FOLDER_NAME;
265+
return constants.SRC_DIR;
266266
}
267267

268268
public getNsConfigRelativePath(): string {

lib/services/project-config-service.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ export class ProjectConfigService implements IProjectConfigService {
3030
return this.$injector.resolve("projectHelper");
3131
}
3232

33+
public getDefaultTSConfig(appId: string = "org.nativescript.app") {
34+
return `import { NativeScriptConfig } from '@nativescript/core';
35+
36+
export default {
37+
id: '${appId}',
38+
appResourcesPath: 'App_Resources',
39+
android: {
40+
v8Flags: '--expose_gc',
41+
markingMode: 'none'
42+
}
43+
} as NativeScriptConfig;`.trim();
44+
}
45+
3346
public detectInfo(
3447
projectDir?: string
3548
): {
@@ -104,20 +117,13 @@ export class ProjectConfigService implements IProjectConfigService {
104117
return _.get(this.readConfig(), key);
105118
}
106119

107-
// TODO: improve to set any value
108-
// public setValue(projectDir?: string) {
109-
public setAppId(projectId: string, projectDir?: string) {
110-
const { hasTS, configJSFilePath, configTSFilePath } = this.detectInfo(
111-
projectDir
120+
public writeDefaultConfig(projectDir: string, appId?: string) {
121+
const configTSFilePath = path.join(
122+
projectDir || this.projectHelper.projectDir,
123+
CONFIG_FILE_NAME_TS
112124
);
113125

114-
const configPath = hasTS ? configTSFilePath : configJSFilePath;
115-
116-
const rawSource = this.$fs.readText(configPath);
117-
this.$fs.writeFile(
118-
configPath,
119-
rawSource.replace(`org.nativescript.app`, projectId)
120-
);
126+
this.$fs.writeFile(configTSFilePath, this.getDefaultTSConfig(appId));
121127
}
122128
}
123129

0 commit comments

Comments
 (0)