Skip to content

Commit 6302101

Browse files
Agnes Linagnes512
authored andcommitted
fix: fix conflict
1 parent 57391a6 commit 6302101

File tree

5 files changed

+66
-4
lines changed

5 files changed

+66
-4
lines changed

packages/cli/lib/project-generator.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
const BaseGenerator = require('./base-generator');
88
const utils = require('./utils');
99
const chalk = require('chalk');
10+
<<<<<<< HEAD
1011
const cliVersion = require('../package.json').version;
12+
=======
13+
const path = require('path');
14+
>>>>>>> af20999f... fix(cli): fix app default project name. relevant test added
1115

1216
module.exports = class ProjectGenerator extends BaseGenerator {
1317
// Note: arguments and options should be defined in the constructor.
@@ -132,7 +136,8 @@ module.exports = class ProjectGenerator extends BaseGenerator {
132136
name: 'name',
133137
message: 'Project name:',
134138
when: this.projectInfo.name == null,
135-
default: this.options.name || this.appname,
139+
default:
140+
this.options.name || utils.toFileName(path.basename(process.cwd())),
136141
validate: utils.validate,
137142
},
138143
{

packages/cli/lib/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const connectors = require('../generators/datasource/connectors.json');
2626
const stringifyObject = require('stringify-object');
2727
const camelCase = _.camelCase;
2828
const kebabCase = _.kebabCase;
29+
const untildify = require('untildify');
30+
const tildify = require('tildify');
2931
const readdirAsync = promisify(fs.readdir);
3032
const toFileName = name => {
3133
return kebabCase(name).replace(/\-(\d+)$/g, '$1');
@@ -127,6 +129,8 @@ exports.camelCase = camelCase;
127129
exports.toVarName = toVarName;
128130
exports.pluralize = pluralize;
129131
exports.urlSlug = urlSlug;
132+
exports.untildify = untildify;
133+
exports.tildify = tildify;
130134

131135
exports.validate = function(name) {
132136
const isValid = validate(name).validForNewPackages;

packages/cli/package-lock.json

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
"unicode-10.0.0": "^0.7.5",
6464
"update-notifier": "^3.0.1",
6565
"url-slug": "^2.1.1",
66+
"untildify": "^4.0.0",
67+
"tildify": "^2.0.0",
6668
"validate-npm-package-name": "^3.0.0",
6769
"yeoman-generator": "^4.0.1"
6870
},

packages/cli/test/integration/generators/app.integration.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@
66
'use strict';
77

88
const fs = require('fs');
9+
const os = require('os');
910
const {promisify} = require('util');
1011
const path = require('path');
12+
const tildify = require('tildify');
1113
const assert = require('yeoman-assert');
1214
const helpers = require('yeoman-test');
1315
const generator = path.join(__dirname, '../../../generators/app');
16+
<<<<<<< HEAD
1417
const cliVersion = require('../../../package.json').version;
18+
=======
19+
const build = require('@loopback/build');
20+
>>>>>>> af20999f... fix(cli): fix app default project name. relevant test added
1521
const props = {
1622
name: 'my-app',
1723
description: 'My app for LoopBack 4',
@@ -210,3 +216,38 @@ function testFormat() {
210216
process.env.CI && !process.env.DEBUG
211217
? describe.skip
212218
: describe('app-generator with --format', testFormat);
219+
220+
/** For testing if the generator handles default values properly */
221+
describe('app-generator with default values', () => {
222+
const rootDir = path.join(__dirname, '../../../..');
223+
const defaultValProjPath = path.join(rootDir, 'sandbox/default-value-app');
224+
const sandbox = path.join(rootDir, 'sandbox');
225+
const pathToDefValApp = path.join(defaultValProjPath, 'default-value-app');
226+
const defaultValProps = {
227+
name: '',
228+
description: 'An app to test out default values',
229+
outdir: '',
230+
};
231+
232+
before(async () => {
233+
// default-value-app should not exist at this point
234+
assert.equal(fs.existsSync(defaultValProjPath), false);
235+
assert.equal(fs.existsSync(pathToDefValApp), false);
236+
return (
237+
helpers
238+
.run(generator)
239+
.inDir(defaultValProjPath)
240+
// Mark it private to prevent accidental npm publication
241+
.withOptions({private: true})
242+
.withPrompts(defaultValProps)
243+
);
244+
});
245+
it('scaffold a new app for default-value-app', async () => {
246+
// default-value-app should be created at this point
247+
assert.equal(fs.existsSync(pathToDefValApp), true);
248+
});
249+
after(() => {
250+
process.chdir(sandbox);
251+
build.clean(['node', 'run-clean', defaultValProjPath]);
252+
});
253+
});

0 commit comments

Comments
 (0)