fix: pages do not support non-default app path from nsconfig.json
This commit is contained in:
Родитель
da84cc9d84
Коммит
2c8f1470b0
|
@ -20,7 +20,7 @@ export class NsStarterKitsPageService implements INsStarterKitsPageService {
|
|||
addPage(pageName: string, pageTemplate: any, appPath: string, version?: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const displayName = pageTemplate.displayName.toLowerCase();
|
||||
const newPageDirectory = util.path.join(appPath, "app");
|
||||
const newPageDirectory = util.path.join(appPath, this.getAppDir(appPath));
|
||||
const pagesDirectory = util.path.join(__dirname, "../pages");
|
||||
const emptyPackageJson: any = { name: "pageTemplate" };
|
||||
|
||||
|
@ -50,6 +50,23 @@ export class NsStarterKitsPageService implements INsStarterKitsPageService {
|
|||
});
|
||||
}
|
||||
|
||||
private getAppDir(appPath: string): string {
|
||||
try {
|
||||
const nsConfigPath = util.path.join(appPath, "nsconfig.json");
|
||||
const stat = util.fs.statSync(nsConfigPath);
|
||||
if (stat.isFile()) {
|
||||
const nsConfig = util.fs.readJsonSync(nsConfigPath);
|
||||
if (nsConfig && nsConfig.appPath) {
|
||||
return nsConfig.appPath;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// return default path
|
||||
}
|
||||
|
||||
return "app";
|
||||
}
|
||||
|
||||
private createPage(sourceDirectory: string, destinationDirectory: string, pageName: string): Promise<string> {
|
||||
const camelCaseNameString = _.camelCase(pageName);
|
||||
const pageDirectoryPath = util.path.join(destinationDirectory, pageName);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "nativescript-starter-kits",
|
||||
"version": "0.3.4",
|
||||
"version": "0.3.5",
|
||||
"description": "CLI extension for the NatvieScript CLI",
|
||||
"main": "lib/bootstrap.js",
|
||||
"scripts": {
|
||||
|
@ -36,6 +36,7 @@
|
|||
"mocha": "3.1.2",
|
||||
"mocha-typescript": "^1.0.4",
|
||||
"nativescript": "https://github.com/NativeScript/nativescript-cli/tarball/master",
|
||||
"sinon": "^4.1.1",
|
||||
"should": "7.0.2",
|
||||
"spec-xunit-file": "0.0.1-3",
|
||||
"tslint": "5.6.0",
|
||||
|
@ -48,7 +49,6 @@
|
|||
"lodash": "4.13.1",
|
||||
"node-cache": "^4.1.1",
|
||||
"request": "^2.81.0",
|
||||
"request-promise-native": "^1.0.5",
|
||||
"sinon": "^4.1.1"
|
||||
"request-promise-native": "^1.0.5"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,8 +84,7 @@ describe("PageService Api", () => {
|
|||
});
|
||||
|
||||
it("Should return the newly created page directory path", () => {
|
||||
const newPageDirectory = "dummyDirectory";
|
||||
const clonedPagesDirectory = "dummyClonedPagesDirecotyr";
|
||||
const clonedPagesDirectory = "dummyClonedPagesDirectory";
|
||||
|
||||
sandbox.stub(util.fs, "emptyDir")
|
||||
.returns(Promise.resolve());
|
||||
|
@ -100,10 +99,10 @@ describe("PageService Api", () => {
|
|||
.returns(Promise.resolve(clonedPagesDirectory));
|
||||
|
||||
sandbox.stub(pageService, "createPage")
|
||||
.returns(Promise.resolve(newPageDirectory));
|
||||
.returns(Promise.resolve());
|
||||
|
||||
return expect(pageService.addPage(pageName, pageTemplate, appPath))
|
||||
.to.eventually.be.an("string", newPageDirectory);
|
||||
.to.eventually.equal(util.path.join(appPath, "app"));
|
||||
});
|
||||
|
||||
it("Should run OK with empty version string", () => {
|
||||
|
@ -130,7 +129,7 @@ describe("PageService Api", () => {
|
|||
});
|
||||
|
||||
sandbox.stub(pageService, "createPage")
|
||||
.returns(Promise.resolve(newPageDirectory));
|
||||
.returns(Promise.resolve());
|
||||
|
||||
return expect(pageService.addPage(pageName, pageTemplate, appPath, ""))
|
||||
.to.eventually.be.an("string", newPageDirectory);
|
||||
|
@ -152,7 +151,7 @@ describe("PageService Api", () => {
|
|||
sandbox.stub(util.childProcess, "spawn")
|
||||
.callsFake((command: string, commandArguments: Array<string>, options: any) => {
|
||||
expect(commandArguments.join(" ")).to.include("@" + templateVersion);
|
||||
|
||||
|
||||
return {
|
||||
on: (method: string, callback: any) => {
|
||||
return callback(0);
|
||||
|
@ -161,10 +160,39 @@ describe("PageService Api", () => {
|
|||
});
|
||||
|
||||
sandbox.stub(pageService, "createPage")
|
||||
.returns(Promise.resolve(newPageDirectory));
|
||||
.returns(Promise.resolve());
|
||||
|
||||
return expect(pageService.addPage(pageName, pageTemplate, appPath, templateVersion))
|
||||
.to.eventually.be.an("string", newPageDirectory);
|
||||
});
|
||||
|
||||
it("Should run OK with different app path", () => {
|
||||
const appDir = "src";
|
||||
const clonedPagesDirectory = "dummyClonedPagesDirectory";
|
||||
|
||||
sandbox.stub(util.fs, "emptyDir")
|
||||
.returns(Promise.resolve());
|
||||
|
||||
sandbox.stub(util.fs, "outputJson")
|
||||
.returns(Promise.resolve());
|
||||
|
||||
sandbox.stub(util.fs, "statSync")
|
||||
.returns({ isFile: () => true });
|
||||
|
||||
sandbox.stub(util.fs, "readJsonSync")
|
||||
.returns({ appPath: appDir });
|
||||
|
||||
sandbox.stub(util, "pageExists")
|
||||
.returns(Promise.resolve(false));
|
||||
|
||||
sandbox.stub(npmService, "installPageTemplate")
|
||||
.returns(Promise.resolve(clonedPagesDirectory));
|
||||
|
||||
sandbox.stub(pageService, "createPage")
|
||||
.returns(Promise.resolve());
|
||||
|
||||
return expect(pageService.addPage(pageName, pageTemplate, appPath))
|
||||
.to.eventually.equal(util.path.join(appPath, appDir));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче