Skip to content

Commit a397430

Browse files
Merge pull request #3765 from NativeScript/fatme/fix-project-create
Fix project create when template option is specified with local .tgz
2 parents 10213eb + fa8eb97 commit a397430

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

lib/services/pacote-service.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
import * as pacote from "pacote";
22
import * as tar from "tar";
3+
import * as path from "path";
34

45
export class PacoteService implements IPacoteService {
5-
constructor(private $npm: INodePackageManager) { }
6+
constructor(private $fs: IFileSystem,
7+
private $npm: INodePackageManager) { }
68

79
public async manifest(packageName: string, options?: IPacoteManifestOptions): Promise<any> {
810
// In case `tns create myapp --template https://github.com/NativeScript/template-hello-world.git` command is executed, pacote module throws an error if cache option is not provided.
9-
const manifestOptions = { cache: await this.$npm.getCachePath() };
11+
const cache = await this.$npm.getCachePath();
12+
const manifestOptions = { cache };
1013
if (options) {
1114
_.extend(manifestOptions, options);
1215
}
1316

17+
if (this.$fs.exists(packageName)) {
18+
packageName = path.resolve(packageName);
19+
}
20+
1421
return pacote.manifest(packageName, manifestOptions);
1522
}
1623

lib/services/project-service.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ export class ProjectService implements IProjectService {
119119

120120
this.$logger.trace(`Copying application from '${templateData.templatePath}' into '${destinationDirectory}'.`);
121121
shelljs.cp('-R', path.join(templateData.templatePath, "*"), destinationDirectory);
122-
123-
this.$fs.createDirectory(path.join(projectDir, "platforms"));
124122
break;
125123
case constants.TemplateVersions.v2:
126124
await this.$pacoteService.extractPackage(templateData.templateName, projectDir);

test/project-service.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,15 @@ class ProjectIntegrationTest {
7373
const fs: IFileSystem = this.testInjector.resolve("fs");
7474
const projectDir = path.join(tempFolder, projectName);
7575
const appDirectoryPath = path.join(projectDir, "app");
76-
const platformsDirectoryPath = path.join(projectDir, "platforms");
7776
const tnsProjectFilePath = path.join(projectDir, "package.json");
7877
const tnsModulesPath = path.join(projectDir, constants.NODE_MODULES_FOLDER_NAME, constants.TNS_CORE_MODULES_NAME);
7978
const packageJsonContent = fs.readJson(tnsProjectFilePath);
8079

8180
assert.isTrue(fs.exists(appDirectoryPath));
82-
assert.isTrue(fs.exists(platformsDirectoryPath));
8381
assert.isTrue(fs.exists(tnsProjectFilePath));
8482
assert.isTrue(fs.exists(tnsModulesPath));
8583

8684
assert.isFalse(fs.isEmptyDir(appDirectoryPath));
87-
assert.isTrue(fs.isEmptyDir(platformsDirectoryPath));
8885

8986
const actualAppId = packageJsonContent["nativescript"].id;
9087
const expectedAppId = appId;
@@ -95,18 +92,6 @@ class ProjectIntegrationTest {
9592

9693
const sourceDir = projectSourceDirectory;
9794

98-
// Hidden files (starting with dots ".") are not copied.
99-
const expectedFiles = fs.enumerateFilesInDirectorySync(sourceDir, (file, stat) => stat.isDirectory() || !_.startsWith(path.basename(file), "."));
100-
const actualFiles = fs.enumerateFilesInDirectorySync(appDirectoryPath);
101-
102-
assert.isTrue(actualFiles.length >= expectedFiles.length, "Files in created project must be at least as files in app dir.");
103-
104-
_.each(expectedFiles, file => {
105-
const relativeToProjectDir = helpers.getRelativeToRootPath(sourceDir, file);
106-
const filePathInApp = path.join(appDirectoryPath, relativeToProjectDir);
107-
assert.isTrue(fs.exists(filePathInApp), `File ${filePathInApp} does not exist.`);
108-
});
109-
11095
// assert dependencies and devDependencies are copied from template to real project
11196
const sourcePackageJsonContent = fs.readJson(path.join(sourceDir, "package.json"));
11297
const missingDeps = _.difference(_.keys(sourcePackageJsonContent.dependencies), _.keys(packageJsonContent.dependencies));

0 commit comments

Comments
 (0)