Skip to content

Commit 73c6eea

Browse files
authored
Merge branch 'master' into include-paths-support
2 parents 3dbf5d2 + dd378fe commit 73c6eea

File tree

8 files changed

+170
-87
lines changed

8 files changed

+170
-87
lines changed

packages/angular-cli/commands/build.run.ts

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ export default function buildRun(commandOptions: BuildOptions) {
2222
}
2323
}
2424

25+
if (typeof commandOptions.sourcemap === 'undefined') {
26+
if (commandOptions.target == 'development') {
27+
commandOptions.sourcemap = true;
28+
}
29+
if (commandOptions.target == 'production') {
30+
commandOptions.sourcemap = false;
31+
}
32+
}
33+
2534
const project = this.project;
2635

2736
// Check angular version.

packages/angular-cli/commands/build.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const BuildCommand = Command.extend({
3939
{ name: 'suppress-sizes', type: Boolean, default: false },
4040
{ name: 'base-href', type: String, default: null, aliases: ['bh'] },
4141
{ name: 'aot', type: Boolean, default: false },
42-
{ name: 'sourcemap', type: Boolean, default: true, aliases: ['sm'] },
42+
{ name: 'sourcemap', type: Boolean, aliases: ['sm'] },
4343
{ name: 'vendor-chunk', type: Boolean, default: true },
4444
{ name: 'verbose', type: Boolean, default: false },
4545
{ name: 'progress', type: Boolean, default: true },

packages/angular-cli/commands/github-pages-deploy.run.ts

+53-25
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,20 @@ export default function githubPagesDeployRun(options: GithubPagesDeployOptions,
113113

114114
function createGitHubRepoIfNeeded() {
115115
return execPromise('git remote -v')
116-
.then(function (stdout) {
117-
if (!/origin\s+(https:\/\/|git@)github\.com/m.test(stdout)) {
118-
return createGithubRepoTask.run(createGithubRepoOptions)
119-
.then(() => {
120-
// only push starting branch if it's not the destinationBranch
121-
// this happens commonly when using github user pages, since
122-
// they require the destination branch to be 'master'
123-
if (destinationBranch !== initialBranch) {
124-
execPromise(`git push -u origin ${initialBranch}`);
125-
}
126-
});
127-
}
128-
});
116+
.then(function(stdout) {
117+
if (!/origin\s+(https:\/\/|git@)github\.com/m.test(stdout)) {
118+
return createGithubRepoTask.run(createGithubRepoOptions)
119+
.then(() => generateRemoteUrl())
120+
.then((upstream: string) => {
121+
// only push starting branch if it's not the destinationBranch
122+
// this happens commonly when using github user pages, since
123+
// they require the destination branch to be 'master'
124+
if (destinationBranch !== initialBranch) {
125+
execPromise(`git push -u ${upstream} ${initialBranch}`);
126+
}
127+
});
128+
}
129+
});
129130
}
130131

131132
function checkoutGhPages() {
@@ -191,30 +192,57 @@ export default function githubPagesDeployRun(options: GithubPagesDeployOptions,
191192
}
192193

193194
function pushToGitRepo() {
194-
return execPromise(`git push origin ${ghPagesBranch}:${destinationBranch}`)
195-
.catch((err) => returnStartingBranch()
196-
.catch(() => Promise.reject(err)));
195+
return generateRemoteUrl()
196+
.then(upstream => {
197+
return execPromise(`git push ${upstream} ${ghPagesBranch}:${destinationBranch}`);
198+
})
199+
.catch((err) => returnStartingBranch()
200+
.catch(() => Promise.reject(err) ));
197201
}
198202

199203
function printProjectUrl() {
200-
return execPromise('git remote -v')
201-
.then((stdout) => {
202-
let match = stdout.match(/origin\s+(?:https:\/\/|git@)github\.com(?:\:|\/)([^\/]+)/m);
203-
let userName = match[1].toLowerCase();
204-
let url = `https://${userName}.github.io/${options.userPage ? '' : (baseHref + '/')}`;
205-
ui.writeLine(chalk.green(`Deployed! Visit ${url}`));
206-
ui.writeLine('Github pages might take a few minutes to show the deployed site.');
207-
});
204+
return getUsernameFromGitOrigin()
205+
.then((userName) => {
206+
let url = `https://${userName}.github.io/${options.userPage ? '' : (baseHref + '/')}`;
207+
ui.writeLine(chalk.green(`Deployed! Visit ${url}`));
208+
ui.writeLine('Github pages might take a few minutes to show the deployed site.');
209+
});
208210
}
209211

210212
function failGracefully(error: Error) {
211213
if (error && (/git clean/.test(error.message) || /Permission denied/.test(error.message))) {
212214
ui.writeLine(error.message);
213215
let msg = 'There was a permissions error during git file operations, ' +
214-
'please close any open project files/folders and try again.';
216+
'please close any open project files/folders and try again.';
217+
msg += `\nYou might also need to return to the ${initialBranch} branch manually.`;
215218
return Promise.reject(new SilentError(msg.concat(branchErrMsg)));
216219
} else {
217220
return Promise.reject(error);
218221
}
219222
}
223+
224+
function generateRemoteUrl(): Promise<String> {
225+
if (createGithubRepoOptions.ghToken && createGithubRepoOptions.ghUsername) {
226+
return Promise.resolve(`https://${createGithubRepoOptions.ghToken}@github.com/` +
227+
`${createGithubRepoOptions.ghUsername}/${createGithubRepoOptions.projectName}.git`);
228+
}
229+
230+
if (createGithubRepoOptions.ghToken && !createGithubRepoOptions.ghUsername) {
231+
return getUsernameFromGitOrigin()
232+
.then(username => {
233+
return Promise.resolve(`https://${createGithubRepoOptions.ghToken}@github.com/` +
234+
`${username}/${createGithubRepoOptions.projectName}.git`);
235+
});
236+
}
237+
238+
return Promise.resolve('origin');
239+
}
240+
241+
function getUsernameFromGitOrigin(): Promise<String> {
242+
return execPromise('git remote -v')
243+
.then((stdout) => {
244+
let match = stdout.match(/origin\s+(?:https:\/\/|git@)github\.com(?:\:|\/)([^\/]+)/m);
245+
return match[1].toLowerCase();
246+
});
247+
}
220248
}

packages/angular-cli/commands/github-pages-deploy.ts

+57-57
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,71 @@ const Command = require('../ember-cli/lib/models/command');
22
import { oneLine } from 'common-tags';
33

44
export interface GithubPagesDeployOptions {
5-
message?: string;
6-
target?: string;
7-
environment?: string;
8-
userPage?: boolean;
9-
skipBuild?: boolean;
10-
ghToken?: string;
11-
ghUsername?: string;
12-
baseHref?: string;
5+
message?: string;
6+
target?: string;
7+
environment?: string;
8+
userPage?: boolean;
9+
skipBuild?: boolean;
10+
ghToken?: string;
11+
ghUsername?: string;
12+
baseHref?: string;
1313
}
1414

1515
const githubPagesDeployCommand = Command.extend({
16-
name: 'github-pages:deploy',
17-
aliases: ['gh-pages:deploy'],
18-
description: oneLine`
16+
name: 'github-pages:deploy',
17+
aliases: ['gh-pages:deploy'],
18+
description: oneLine`
1919
Build the test app for production, commit it into a git branch,
2020
setup GitHub repo and push to it
2121
`,
22-
works: 'insideProject',
22+
works: 'insideProject',
2323

24-
availableOptions: [
25-
{
26-
name: 'message',
27-
type: String,
28-
default: 'new gh-pages version',
29-
description: 'The commit message to include with the build, must be wrapped in quotes.'
30-
}, {
31-
name: 'target',
32-
type: String,
33-
default: 'production',
34-
aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }]
35-
}, {
36-
name: 'environment',
37-
type: String,
38-
default: '',
39-
aliases: ['e']
40-
}, {
41-
name: 'user-page',
42-
type: Boolean,
43-
default: false,
44-
description: 'Deploy as a user/org page'
45-
}, {
46-
name: 'skip-build',
47-
type: Boolean,
48-
default: false,
49-
description: 'Skip building the project before deploying'
50-
}, {
51-
name: 'gh-token',
52-
type: String,
53-
default: '',
54-
description: 'Github token'
55-
}, {
56-
name: 'gh-username',
57-
type: String,
58-
default: '',
59-
description: 'Github username'
60-
}, {
61-
name: 'base-href',
62-
type: String,
63-
default: null,
64-
aliases: ['bh']
65-
}],
24+
availableOptions: [
25+
{
26+
name: 'message',
27+
type: String,
28+
default: 'new gh-pages version',
29+
description: 'The commit message to include with the build, must be wrapped in quotes.'
30+
}, {
31+
name: 'target',
32+
type: String,
33+
default: 'production',
34+
aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }]
35+
}, {
36+
name: 'environment',
37+
type: String,
38+
default: '',
39+
aliases: ['e']
40+
}, {
41+
name: 'user-page',
42+
type: Boolean,
43+
default: false,
44+
description: 'Deploy as a user/org page'
45+
}, {
46+
name: 'skip-build',
47+
type: Boolean,
48+
default: false,
49+
description: 'Skip building the project before deploying'
50+
}, {
51+
name: 'gh-token',
52+
type: String,
53+
default: '',
54+
description: 'Github token'
55+
}, {
56+
name: 'gh-username',
57+
type: String,
58+
default: '',
59+
description: 'Github username'
60+
}, {
61+
name: 'base-href',
62+
type: String,
63+
default: null,
64+
aliases: ['bh']
65+
}],
6666

67-
run: function(options: GithubPagesDeployOptions, rawArgs: string[]) {
68-
return require('./github-pages-deploy.run').default.call(this, options, rawArgs);
69-
}
67+
run: function(options: GithubPagesDeployOptions, rawArgs: string[]) {
68+
return require('./github-pages-deploy.run').default.call(this, options, rawArgs);
69+
}
7070
});
7171

7272

tests/acceptance/github-pages-deploy.spec.js

+40-2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,44 @@ describe('Acceptance: ng github-pages:deploy', function() {
7777
return ng(['github-pages:deploy', '--skip-build']);
7878
});
7979

80+
it('should deploy with token and username', function () {
81+
let token = 'token',
82+
username = 'bar';
83+
84+
execStub.addExecSuccess('git status --porcelain')
85+
.addExecSuccess('git rev-parse --abbrev-ref HEAD', initialBranch)
86+
.addExecSuccess('git remote -v', remote)
87+
.addExecSuccess(`git checkout ${ghPagesBranch}`)
88+
.addExecSuccess('git ls-files')
89+
.addExecSuccess('git rm -r ')
90+
.addExecSuccess('git add .')
91+
.addExecSuccess(`git commit -m "${message}"`)
92+
.addExecSuccess(`git checkout ${initialBranch}`)
93+
.addExecSuccess(`git push https://${token}@github.com/${username}/${project}.git ${ghPagesBranch}:${ghPagesBranch}`)
94+
.addExecSuccess('git remote -v', remote);
95+
96+
return ng(['github-pages:deploy', '--skip-build', `--gh-token=${token}`, `--gh-username=${username}`]);
97+
})
98+
99+
it('should deploy with token only', function () {
100+
let token = 'token';
101+
102+
execStub.addExecSuccess('git status --porcelain')
103+
.addExecSuccess('git rev-parse --abbrev-ref HEAD', initialBranch)
104+
.addExecSuccess('git remote -v', remote)
105+
.addExecSuccess(`git checkout ${ghPagesBranch}`)
106+
.addExecSuccess('git ls-files')
107+
.addExecSuccess('git rm -r ')
108+
.addExecSuccess('git add .')
109+
.addExecSuccess(`git commit -m "${message}"`)
110+
.addExecSuccess(`git checkout ${initialBranch}`)
111+
.addExecSuccess('git remote -v', remote)
112+
.addExecSuccess(`git push https://${token}@github.com/username/${project}.git ${ghPagesBranch}:${ghPagesBranch}`)
113+
.addExecSuccess('git remote -v', remote);
114+
115+
return ng(['github-pages:deploy', '--skip-build', `--gh-token=${token}`]);
116+
});
117+
80118
it('should deploy with changed defaults', function() {
81119
let userPageBranch = 'master',
82120
message = 'not new gh-pages version';
@@ -126,14 +164,14 @@ describe('Acceptance: ng github-pages:deploy', function() {
126164
.addExecSuccess('git rev-parse --abbrev-ref HEAD', initialBranch)
127165
.addExecSuccess('git remote -v', noRemote)
128166
.addExecSuccess(`git remote add origin [email protected]:${username}/${project}.git`)
129-
.addExecSuccess(`git push -u origin ${initialBranch}`)
167+
.addExecSuccess(`git push -u https://${token}@github.com/${username}/${project}.git ${initialBranch}`)
130168
.addExecSuccess(`git checkout ${ghPagesBranch}`)
131169
.addExecSuccess('git ls-files')
132170
.addExecSuccess('git rm -r ')
133171
.addExecSuccess('git add .')
134172
.addExecSuccess(`git commit -m "${message}"`)
135173
.addExecSuccess(`git checkout ${initialBranch}`)
136-
.addExecSuccess(`git push origin ${ghPagesBranch}:${ghPagesBranch}`)
174+
.addExecSuccess(`git push https://${token}@github.com/${username}/${project}.git ${ghPagesBranch}:${ghPagesBranch}`)
137175
.addExecSuccess('git remote -v', remote);
138176

139177
var httpsStub = sinon.stub(https, 'request', httpsRequestStubFunc);

tests/e2e/tests/build/sourcemap.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import {expectToFail} from '../../utils/utils';
66
export default function() {
77
return ng('build')
88
.then(() => expectFileToExist('dist/main.bundle.map'))
9+
910
.then(() => ng('build', '--no-sourcemap'))
10-
.then(() => expectToFail(() => expectFileToExist('dist/main.bundle.map')));
11+
.then(() => expectToFail(() => expectFileToExist('dist/main.bundle.map')))
12+
13+
.then(() => ng('build', '--prod', '--output-hashing=none'))
14+
.then(() => expectToFail(() => expectFileToExist('dist/main.bundle.map')))
15+
16+
.then(() => ng('build', '--prod', '--output-hashing=none', '--sourcemap'))
17+
.then(() => expectFileToExist('dist/main.bundle.map'));
1118
}

tsconfig.json

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"moduleResolution": "node",
77
"noEmitOnError": true,
88
"noImplicitAny": true,
9+
"noUnusedParameters": true,
10+
"noUnusedLocals": true,
911
"outDir": "./dist",
1012
"rootDir": ".",
1113
"sourceMap": true,

tslint.json

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"no-trailing-whitespace": true,
2020
"no-bitwise": true,
2121
"no-unused-expression": true,
22-
"no-unused-variable": true,
2322
"no-var-keyword": true,
2423
"one-line": [
2524
true,

0 commit comments

Comments
 (0)