angular-cli-ghpages
Advanced tools
Comparing version
@@ -6,5 +6,7 @@ { | ||
"description": "Add GitHub pages deploy schematic (angular-cli-ghpages)", | ||
"factory": "./ng-add#ngAdd" | ||
"factory": "./ng-add#ngAdd", | ||
"schema": "./ng-add-schema.json", | ||
"aliases": ["install"] | ||
} | ||
} | ||
} | ||
} |
@@ -20,3 +20,5 @@ "use strict"; | ||
} | ||
const configuration = options.configuration ? options.configuration : 'production'; | ||
const configuration = options.configuration | ||
? options.configuration | ||
: 'production'; | ||
const overrides = Object.assign({}, (options.baseHref && { baseHref: options.baseHref })); | ||
@@ -29,3 +31,6 @@ context.logger.info(`đĻ Building "${context.target.project}". Configuration: "${configuration}".${options.baseHref ? ' Your base-href: "' + options.baseHref + '"' : ''}`); | ||
}, overrides); | ||
yield build.result; | ||
const buildResult = yield build.result; | ||
if (!buildResult.success) { | ||
throw new Error('Error while building the app.'); | ||
} | ||
} | ||
@@ -32,0 +37,0 @@ yield engine.run(projectRoot, options, context.logger); |
@@ -22,32 +22,34 @@ "use strict"; | ||
const architect_1 = require("@angular-devkit/architect"); | ||
const core_1 = require("@angular-devkit/core"); | ||
const node_1 = require("@angular-devkit/core/node"); | ||
const core_1 = require("@angular-devkit/core"); | ||
const os_1 = __importDefault(require("os")); | ||
const path = __importStar(require("path")); | ||
const engine = __importStar(require("../engine/engine")); | ||
const actions_1 = __importDefault(require("./actions")); | ||
const engine = __importStar(require("../engine/engine")); | ||
exports.default = architect_1.createBuilder((options, context) => __awaiter(this, void 0, void 0, function* () { | ||
const root = core_1.normalize(context.workspaceRoot); | ||
const workspace = new core_1.experimental.workspace.Workspace(root, new node_1.NodeJsSyncHost()); | ||
yield workspace | ||
.loadWorkspaceFromHost(core_1.normalize('angular.json')) | ||
.toPromise(); | ||
if (!context.target) { | ||
throw new Error('Cannot deploy the application without a target'); | ||
} | ||
const targets = workspace.getProjectTargets(context.target.project); | ||
if (!targets || | ||
!targets.build || | ||
!targets.build.options || | ||
!targets.build.options.outputPath) { | ||
throw new Error('Cannot find the project output directory'); | ||
} | ||
const isWin = os_1.default.platform() === 'win32'; | ||
const workspaceRoot = !isWin ? workspace.root : core_1.asWindowsPath(workspace.root); | ||
try { | ||
const root = core_1.normalize(context.workspaceRoot); | ||
const workspace = new core_1.experimental.workspace.Workspace(root, new node_1.NodeJsSyncHost()); | ||
yield workspace | ||
.loadWorkspaceFromHost(core_1.normalize('angular.json')) | ||
.toPromise(); | ||
if (!context.target) { | ||
throw new Error('Cannot deploy the application without a target'); | ||
} | ||
const targets = workspace.getProjectTargets(context.target.project); | ||
if (!targets || | ||
!targets.build || | ||
!targets.build.options || | ||
!targets.build.options.outputPath) { | ||
throw new Error('Cannot find the project output directory'); | ||
} | ||
const isWin = os_1.default.platform() === 'win32'; | ||
const workspaceRoot = !isWin | ||
? workspace.root | ||
: core_1.asWindowsPath(workspace.root); | ||
yield actions_1.default(engine, context, path.join(workspaceRoot, targets.build.options.outputPath), options); | ||
} | ||
catch (e) { | ||
context.logger.error('Error when trying to deploy:', e); | ||
console.error(e); | ||
context.logger.error('â An error occurred when trying to deploy:'); | ||
context.logger.error(e.message); | ||
return { success: false }; | ||
@@ -54,0 +56,0 @@ } |
@@ -18,9 +18,9 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fse = __importStar(require("fs-extra")); | ||
const path = __importStar(require("path")); | ||
const fse = __importStar(require("fs-extra")); | ||
const defaults_1 = require("./defaults"); | ||
const ghpages = require('gh-pages'); | ||
function run(dir, options, logger) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
options = prepareOptions(options, logger); | ||
const ghpages = require('gh-pages'); | ||
if (options.dryRun) { | ||
@@ -32,17 +32,10 @@ logger.info('Dry-run / SKIPPED: cleaning of the cache directory'); | ||
} | ||
try { | ||
yield checkIfDistFolderExists(dir); | ||
yield createNotFoundPage(dir, options, logger); | ||
yield createCnameFile(dir, options, logger); | ||
yield publishViaGhPages(ghpages, dir, options, logger); | ||
logger.info('đ Successfully published via angular-cli-ghpages! Have a nice day!'); | ||
} | ||
catch (error) { | ||
logger.error('â An error occurred!'); | ||
throw error; | ||
} | ||
yield checkIfDistFolderExists(dir); | ||
yield createNotFoundPage(dir, options, logger); | ||
yield createCnameFile(dir, options, logger); | ||
yield publishViaGhPages(ghpages, dir, options, logger); | ||
logger.info('đ Successfully published via angular-cli-ghpages! Have a nice day!'); | ||
}); | ||
} | ||
exports.run = run; | ||
; | ||
function prepareOptions(origOptions, logger) { | ||
@@ -52,2 +45,13 @@ const options = Object.assign({}, defaults_1.defaults, origOptions); | ||
options.silent = !origOptions.noSilent; | ||
const util = require('util'); | ||
let debuglog = util.debuglog; | ||
util.debuglog = set => { | ||
if (set === 'gh-pages') { | ||
return function () { | ||
let message = util.format.apply(util, arguments); | ||
logger.info(message); | ||
}; | ||
} | ||
return debuglog(set); | ||
}; | ||
} | ||
@@ -66,13 +70,29 @@ if (origOptions.noDotfiles) { | ||
} | ||
; | ||
options['logger'] = function (message) { logger.info(message); }; | ||
if (process.env.TRAVIS) { | ||
options.message += ' -- ' + process.env.TRAVIS_COMMIT_MESSAGE + ' \n\n' + | ||
'Triggered by commit: https://github.com/' + process.env.TRAVIS_REPO_SLUG + '/commit/' + process.env.TRAVIS_COMMIT + '\n' + | ||
'Travis CI build: https://travis-ci.org/' + process.env.TRAVIS_REPO_SLUG + '/builds/' + process.env.TRAVIS_BUILD_ID; | ||
options.message += | ||
' -- ' + | ||
process.env.TRAVIS_COMMIT_MESSAGE + | ||
' \n\n' + | ||
'Triggered by commit: https://github.com/' + | ||
process.env.TRAVIS_REPO_SLUG + | ||
'/commit/' + | ||
process.env.TRAVIS_COMMIT + | ||
'\n' + | ||
'Travis CI build: https://travis-ci.org/' + | ||
process.env.TRAVIS_REPO_SLUG + | ||
'/builds/' + | ||
process.env.TRAVIS_BUILD_ID; | ||
} | ||
if (process.env.CIRCLECI) { | ||
options.message += '\n\n' + | ||
'Triggered by commit: https://github.com/' + process.env.CIRCLE_PROJECT_USERNAME + '/' + process.env.CIRCLE_PROJECT_REPONAME + '/commit/' + process.env.CIRCLE_SHA1 + '\n' + | ||
'CircleCI build: ' + process.env.CIRCLE_BUILD_URL; | ||
options.message += | ||
'\n\n' + | ||
'Triggered by commit: https://github.com/' + | ||
process.env.CIRCLE_PROJECT_USERNAME + | ||
'/' + | ||
process.env.CIRCLE_PROJECT_REPONAME + | ||
'/commit/' + | ||
process.env.CIRCLE_SHA1 + | ||
'\n' + | ||
'CircleCI build: ' + | ||
process.env.CIRCLE_BUILD_URL; | ||
} | ||
@@ -108,3 +128,3 @@ if (process.env.GH_TOKEN && options.repo) { | ||
logger.info('(Hint: are you sure that you have setup the directory correctly?)'); | ||
logger.debug('Diagnostic info', err); | ||
logger.debug('Diagnostic info: ' + err.message); | ||
return; | ||
@@ -129,4 +149,3 @@ } | ||
catch (err) { | ||
logger.error('CNAME file could not be created. Stopping execution.'); | ||
throw err; | ||
throw new Error('CNAME file could not be created. ' + err.message); | ||
} | ||
@@ -138,17 +157,27 @@ }); | ||
if (options.dryRun) { | ||
logger.info(`Dry-run / SKIPPED: publishing folder "${dir}" with the following options: ` + JSON.stringify({ | ||
dir: dir, | ||
repo: options.repo || 'falsy: current working directory (which must be a git repo in this case) will be used to commit & push', | ||
message: options.message, | ||
branch: options.branch, | ||
user: options.user || 'falsy: local or global git username & email properties will be taken', | ||
silent: options.silent || 'falsy: logging is in silent mode by default', | ||
dotfiles: options.dotfiles || 'falsy: dotfiles are included by default', | ||
cname: options.cname || 'falsy: no CNAME file will be created', | ||
}, null, ' ')); | ||
logger.info(`Dry-run / SKIPPED: publishing folder "${dir}" with the following options: ` + | ||
JSON.stringify({ | ||
dir: dir, | ||
repo: options.repo || | ||
'falsy: current working directory (which must be a git repo in this case) will be used to commit & push', | ||
message: options.message, | ||
branch: options.branch, | ||
user: options.user || | ||
'falsy: local or global git username & email properties will be taken', | ||
silent: options.silent || 'falsy: logging is in silent mode by default', | ||
dotfiles: options.dotfiles || 'falsy: dotfiles are included by default', | ||
cname: options.cname || 'falsy: no CNAME file will be created' | ||
}, null, ' ')); | ||
return; | ||
} | ||
return yield ghPages.publish(dir, options); | ||
return new Promise((resolve, reject) => { | ||
ghPages.publish(dir, options, error => { | ||
if (error) { | ||
return reject(error); | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
} | ||
//# sourceMappingURL=engine.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const core_1 = require("@angular-devkit/core"); | ||
const schematics_1 = require("@angular-devkit/schematics"); | ||
const core_1 = require("@angular-devkit/core"); | ||
function getWorkspace(host) { | ||
@@ -25,3 +25,3 @@ const possibleFiles = ['/angular.json', '/.angular.json']; | ||
} | ||
exports.ngAdd = ({ project: DeployOptions }) => (tree, options) => { | ||
exports.ngAdd = (options) => (tree, _context) => { | ||
const { path: workspacePath, workspace } = getWorkspace(tree); | ||
@@ -28,0 +28,0 @@ if (!options.project) { |
{ | ||
"name": "angular-cli-ghpages", | ||
"version": "0.6.0", | ||
"description": "Deployment from the Angular CLI to GitHub pages (or any other branch on any other remote)", | ||
"version": "0.6.1", | ||
"description": "Deploy your Angular app to GitHub pages directly from the Angular CLI.", | ||
"main": "index.js", | ||
@@ -11,3 +11,3 @@ "bin": { | ||
"scripts": { | ||
"build": "rimraf dist && json2ts deploy/schema.json > deploy/schema.d.ts && tsc && copyfiles builders.json collection.json package.json angular-cli-ghpages deploy/schema.json dist && copyfiles ../README.md dist/README.md", | ||
"build": "rimraf dist && json2ts deploy/schema.json > deploy/schema.d.ts && tsc && copyfiles builders.json collection.json ng-add-schema.json package.json angular-cli-ghpages deploy/schema.json dist && copyfiles ../README.md dist/README.md", | ||
"test": "jest" | ||
@@ -17,2 +17,5 @@ }, | ||
"builders": "./builders.json", | ||
"ng-add": { | ||
"save": "devDependencies" | ||
}, | ||
"repository": { | ||
@@ -51,11 +54,14 @@ "type": "git", | ||
"devDependencies": { | ||
"@angular-devkit/architect": "^0.803.0-next.0", | ||
"@angular-devkit/core": "^8.3.0-next.0", | ||
"@angular-devkit/schematics": "^8.3.0-next.0", | ||
"@angular-devkit/architect": "^0.803.0", | ||
"@angular-devkit/core": "^8.3.0", | ||
"@angular-devkit/schematics": "^8.3.0", | ||
"@types/fs-extra": "^8.0.0", | ||
"@types/jest": "^24.0.16", | ||
"@types/jest": "^24.0.18", | ||
"@types/node": "^12.6.9", | ||
"copyfiles": "^2.1.1", | ||
"husky": "^3.0.7", | ||
"jest": "^24.8.0", | ||
"json-schema-to-typescript": "^7.0.0", | ||
"prettier": "1.18.2", | ||
"pretty-quick": "^1.11.1", | ||
"rimraf": "^2.6.3", | ||
@@ -75,2 +81,7 @@ "ts-jest": "^24.0.2", | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "pretty-quick --staged" | ||
} | ||
}, | ||
"jest": { | ||
@@ -77,0 +88,0 @@ "transform": { |
@@ -8,3 +8,3 @@ # angular-cli-ghpages | ||
 | ||
 | ||
@@ -20,2 +20,3 @@ **Table of contents:** | ||
- [--configuration](#configuration) | ||
- [--no-build](#no-build) | ||
- [--repo](#repo) | ||
@@ -30,4 +31,5 @@ - [--message](#message) | ||
6. [đ Configuration File](#configuration-file) | ||
7. [đ Next milestones](#milestones) | ||
8. [âī¸ FAQ](#faq) | ||
7. [đ Environments](#environments) | ||
8. [đ Next milestones](#milestones) | ||
9. [âī¸ FAQ](#faq) | ||
@@ -44,8 +46,6 @@ | ||
In the past this project was a standalone program. | ||
This is still possible: | ||
See the documentation at [README_standalone](docs/README_standalone). | ||
## â ī¸ Prerequisites <a name="prerequisites"></a> | ||
@@ -56,3 +56,4 @@ | ||
- Git 1.9 or higher (execute `git --version` to check your version) | ||
- Angular project created via [Angular CLI](https://github.com/angular/angular-cli) v8.3.0-next.0 or greater (execute `ng update @angular/cli@8.3.0-next.1 @angular/core@8.2.1` to upgrade your project if necessary) | ||
- Angular project created via [Angular CLI](https://github.com/angular/angular-cli) v8.3.0 or greater (execute `ng update @angular/cli @angular/core` to upgrade your project if necessary) | ||
- older Angular projects can still use the standalone program. See the documentation at [README_standalone](https://github.com/angular-schule/angular-cli-ghpages/blob/master/docs/README_standalone.md). | ||
@@ -66,7 +67,7 @@ | ||
1. Install the next version of the Angular CLI (v8.3.0-next.0 or greater) globally | ||
1. Install the latest version of the Angular CLI (v8.3.0 or greater) globally | ||
and create a new Angular project. | ||
```sh | ||
npm install -g @angular/cli@next | ||
npm install -g @angular/cli | ||
ng new your-angular-project --defaults | ||
@@ -105,3 +106,3 @@ cd your-angular-project | ||
```sh | ||
ng run your-angular-project:deploy | ||
ng deploy your-angular-project | ||
``` | ||
@@ -171,19 +172,3 @@ | ||
#### --repo <a name="repo"></a> | ||
* __optional__ | ||
* Default: URL of the origin remote of the current dir (assumes a Git repository) | ||
* Example: `ng deploy --repo=https://github.com/<username>/<repositoryname>.git` | ||
By default, this command assumes that the current working directory is a Git repository, | ||
and that you want to push changes to the `origin` remote. | ||
If instead your files are not in a git repository, or if you want to push to another repository, | ||
you can provide the repository URL in the `repo` option. | ||
**Hint:** | ||
Set an environment variable with the name `GH_TOKEN` and it will be automatically added to the URL. | ||
(`https://github.com/<username>/<repositoryname>.git` is changed to `https://XXX@github.com/<username>/<repositoryname>.git` | ||
if there is an environment variable `GH_TOKEN` with the value `XXX`. | ||
Learn more about [GitHub tokens here](https://help.github.com/articles/creating-an-access-token-for-command-line-use/).) | ||
#### --configuration <a name="configuration"></a> | ||
@@ -215,2 +200,19 @@ * __optional__ | ||
#### --repo <a name="repo"></a> | ||
* __optional__ | ||
* Default: URL of the origin remote of the current dir (assumes a Git repository) | ||
* Example: `ng deploy --repo=https://github.com/<username>/<repositoryname>.git` | ||
By default, this command assumes that the current working directory is a Git repository, | ||
and that you want to push changes to the `origin` remote. | ||
If instead your files are not in a git repository, or if you want to push to another repository, | ||
you can provide the repository URL in the `repo` option. | ||
**Hint:** | ||
Set an environment variable with the name `GH_TOKEN` and it will be automatically added to the URL. | ||
(`https://github.com/<username>/<repositoryname>.git` is changed to `https://XXX@github.com/<username>/<repositoryname>.git` | ||
if there is an environment variable `GH_TOKEN` with the value `XXX`. | ||
Learn more about [GitHub tokens here](https://help.github.com/articles/creating-an-access-token-for-command-line-use/).) | ||
#### --message <a name="message"></a> | ||
@@ -257,5 +259,6 @@ * __optional__ | ||
Logging is in silent mode by default. | ||
In silent mode, log messages are suppressed and error messages are sanitized. | ||
In silent mode, the error messages for git operations are always sanitized. | ||
(The message is always: `'Unspecified error (run without silent option for detail)'`) | ||
The `--no-silent` option enables extended console logging. | ||
The `--no-silent` option enables detailed error messages and extended console logging. | ||
Keep this untouched if the repository URL or other information passed to git commands is sensitive! | ||
@@ -307,3 +310,17 @@ | ||
To avoid all these command-line cmd options, you can write down your configuration in the `angular.json` file in the `options` attribute of your deploy project's architect. Just change the kebab-case<sup id="configuration-file-mark-1">[1](#configuration-file-def-1)</sup> to lower camel case<sup id="configuration-file-mark-2">[2](#configuration-file-def-2)</sup> | ||
To avoid all these command-line cmd options, you can write down your configuration in the `angular.json` file in the `options` attribute of your deploy project's architect. Just change the kebab-case to lower camel case. This is the notation of all options in lower camel case: | ||
* baseHref | ||
* configuration | ||
* noBuild | ||
* repo | ||
* message | ||
* branch | ||
* name | ||
* noSilent | ||
* noDotfiles | ||
* cname | ||
* dryRun | ||
A list of all avaiable options is also available [here](https://github.com/angular-schule/angular-cli-ghpages/blob/master/src/deploy/schema.json). | ||
@@ -313,3 +330,3 @@ Example: | ||
```sh | ||
ng deploy your-project-name --base-href=https://angular-schule.github.io/angular-cli-ghpages/ --name=angular --email=schule@example.com | ||
ng deploy --base-href=https://angular-schule.github.io/angular-cli-ghpages/ --name="Angular Schule Team" --email=team@angular.schule | ||
``` | ||
@@ -324,4 +341,4 @@ | ||
"baseHref": "https://angular-schule.github.io/angular-cli-ghpages/", | ||
"name": "angular", | ||
"email": "schule@example.com" | ||
"name": "Angular Schule Team", | ||
"email": "team@angular.schule" | ||
} | ||
@@ -331,12 +348,17 @@ } | ||
And just run `ng deploy your-project-name` đ. | ||
And just run `ng deploy` đ. | ||
###### You can always use the [--dry-run](#dry-run) option to verify if your configuration is right. | ||
> âšī¸ You can always use the [--dry-run](#dry-run) option to verify if your configuration is right. | ||
--- | ||
<a id="configuration-file-def-1">1.</a> In kebab case, all letters are written in lower case and the words are separated by a hyphen or minus sign. "Kebab Case" becomes "kebab-case". [âŠ](#configuration-file-mark-1) | ||
## đ Environments <a name="environments"></a> | ||
<a id="configuration-file-def-2">2.</a> Lower camel case (part of CamelCase) is a naming convention in which a name is formed of multiple words that are joined together as a single word with the first letter of each of the multiple words (except the first one) capitalized within the new word that forms the name. "Lower Camel Case" becomes "lowerCamelCase" [âŠ](#configuration-file-mark-2) | ||
We have seen `angular-cli-ghpages` running on various environments, like Travis CI, Circle Ci or Github Actions. | ||
Please share your knowledge by writing an article about how to set up the deployment. | ||
1. [GitHub Actions](https://github.com/angular-schule/angular-cli-ghpages/blob/master/docs/README_environment_github_actions.md) by [Dharmen Shah](https://github.com/shhdharmen) | ||
2. TODO! | ||
## đ Next milestones <a name="milestones"></a> | ||
@@ -357,3 +379,3 @@ | ||
Before posting any issue, [please read the FAQ first](https://github.com/angular-schule/angular-cli-ghpages/wiki/FAQ). | ||
See the contributors documentation at [README_contributors](docs/README_contributors) if you want to debug and test this project. | ||
See the contributors documentation at [README_contributors](https://github.com/angular-schule/angular-cli-ghpages/blob/master/docs/README_contributors.md) if you want to debug and test this project. | ||
@@ -360,0 +382,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
60167
6.58%23
4.55%448
12%382
6.11%15
25%