You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

angular-server-side-configuration

Package Overview
Dependencies
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-server-side-configuration - npm Package Compare versions

Comparing version

to
2.0.0-beta.0

api-extractor.json

12

CHANGELOG.md

@@ -0,1 +1,11 @@

# 2.0.0-beta.0 (2019-03-10)
### Features
* Implemented NG_ENV variant as an alternative for process.env
### Breaking Changes
* Removed deprecated ProcessEnvConfiguration
# 1.3.0 (2019-03-09)

@@ -10,3 +20,3 @@

* EnvironmentVariablesConfiguration has been deprecated. Use ProcessEnvConfiguration instead.
* EnvironmentVariablesConfiguration has been deprecated. Use ProcessEnvConfiguration instead

@@ -13,0 +23,0 @@ ### Internal Changes

591

index.d.ts

@@ -0,306 +1,315 @@

/**
* Options for applyAndSaveRecursively
*
* @public
*/
export declare interface ApplyAndSaveRecursivelyOptions {
/**
* The root directory from which to search files. (Defaults to instance directory.)
*/
directory?: string;
/**
* The file pattern in which the configuration should be inserted
* (Defaults to /index.html$/).
*/
filePattern?: RegExp;
}
/**
* @public
*/
export declare function cli(): {
parse(args: string[]): any;
parse(args: string[]): any;
};
declare abstract class CommandBase {
private _name;
constructor(_name: string);
execute(): Promise<void>;
protected abstract _execute(): Promise<void>;
protected _logValue(message: string, value: any): void;
protected _log(message: string): void;
/**
* The base command class.
*
* @public
*/
export declare abstract class CommandBase {
private _name;
constructor(_name: string);
execute(): Promise<void>;
protected abstract _execute(): Promise<void>;
protected _logValue(message: string, value: any): void;
protected _log(message: string): void;
}
/**
* Discover and apply configuration.
*
* @public
*/
export declare abstract class Configuration {
readonly variables: string[];
/**
* The directory. Defaults to current working directory.
*/
directory: string;
/**
* The default pattern for files to have the environment variables inserted into.
*/
readonly defaultInsertionFilePattern: RegExp;
/**
* An array of replacement functions.
*/
readonly replacements: Array<(fileContent: string, fileName: string) => string>;
/**
* @param variables - Optional array of environment variable names to populate.
*/
constructor(variables?: string[]);
/**
* Set the directory, where the files to be configured reside in.
* Default is current working directory.
* @param directory - The directory to work in.
* @returns This instance.
*/
setDirectory(directory: string): this;
/**
* Searches for environment variable declarations in
* files matched by file pattern, starting from given directory.
*
* @param options - Options for searching environment variables.
* @returns This instance.
*/
searchEnvironmentVariables(options?: SearchEnvironmentVariablesOptions): this;
/**
* Replace the base href attribute for the file received through
* applyTo, applyAndSaveTo or applyAndSaveRecursively.
*
* @param newBaseHref - The new base href.
* @returns This instance.
*/
replaceBaseHref(newBaseHref: string): this;
/**
* Replace the html lang attribute for the file received through
* applyTo, applyAndSaveTo or applyAndSaveRecursively.
*
* @param newHtmlLang - The new base href.
* @returns This instance.
*/
replaceHtmlLang(newHtmlLang: string): this;
/**
* Replace the attribute value of a tag for the file received through
* applyTo, applyAndSaveTo or applyAndSaveRecursively.
*
* @param tag - The tag, whose attribute value should be replaced.
* @param attribute - The attribute, whose value should be replaced.
* @param newValue - The new attribute value.
* @returns This instance.
*/
replaceTagAttribute(tag: string, attribute: string, newValue: string): this;
/**
* Add a replacement for the file received through applyTo, applyAndSaveTo or applyAndSaveRecursively.
*
* @param regex - A RegExp object or literal. The match or matches are replaced with replaceValue.
* @param replaceValue - The value that replaces the substring matched by the regex parameter.
* @returns This instance.
*/
regexReplace(regex: RegExp, replaceValue: string): this;
/**
* Replace the placeholder with the populated variables wrapped in an IIFE inside a script tag.
* @param placeholder - The placeholder to replace with the populated variables.
* (Defaults to &lt;!--CONFIG--&gt;.)
* @returns This instance.
*/
insertVariables(placeholder?: string | RegExp): this;
/**
* Insert the populated variables (wrapped in an IIFE inside a script tag) into the head tag.
* Appends variables to title tag, or if not found, at the end of the head tag.
* @returns This instance.
*/
insertVariablesIntoHead(): this;
/**
* Add a replacement function for the file received through applyTo, applyAndSaveTo or
* applyAndSaveRecursively. The function receives the file content and the file name as
* parameters and returns the file content with the replacement applied.
*
* @param replacement - The replacement function.
* @returns This instance.
*/
replace(replacement: (fileContent: string, fileName: string) => string): this;
/**
* Apply the replacements to the content of the matched files and save them asynchronously.
* @param options - Options for applying replacements.
* @returns A promise, which resolves to the matched files, after all matched files have had the
* replacements applied.
*/
applyAndSaveRecursively(options?: ApplyAndSaveRecursivelyOptions): Promise<string[]>;
/**
* Apply the replacements to the content of the given file and save it asynchronously.
* @param file - The HTML file to apply the replacements to.
* @returns A promise, which resolves after the file has had the replacements applied.
*/
applyAndSaveTo(file: string): Promise<void>;
/**
* Apply the replacements to the content of the given file and return the resulting content
* as a promise.
* @param file - The HTML file to apply the replacements to.
* @returns A promise, which resolves to the file content with the replacements applied.
*/
applyTo(file: string): Promise<string>;
/**
* Generates the IIFE which the renders the populated environment variables.
*/
generateIIFE(): string;
/**
* Generates an object, with the environment variable names being the key and
* the actual values being the values.
*/
populateVariables(): {
[variable: string]: any;
};
/**
* Search for variables in the received file content. Should return an array of found
* variable names.
* @param fileContent - The file content that should be searched.
*/
protected abstract discoverVariables(fileContent: string): string[];
/**
* Render the IIFE
*/
protected abstract renderIIFE(environmentVariables: {
[variable: string]: any;
}): string;
}
/**
* The init command to initialize a project with angular-server-side-configuration.
*
* @public
*/
export declare class InitCommand extends CommandBase {
private _options;
private _packagePath;
private _environmentFile;
private _directory;
constructor(_options: {
directory?: string;
environmentFile?: string;
npm?: boolean;
yarn?: boolean;
});
protected _execute(): Promise<void>;
private _validateOptions;
private _initEnvironmentFile;
private _installPackage;
private _options;
private _packagePath;
private _environmentFile;
private _directory;
constructor(_options: {
directory?: string;
environmentFile?: string;
npm?: boolean;
yarn?: boolean;
processEnv?: boolean;
ngEnv?: boolean;
});
protected _execute(): Promise<void>;
private _validateOptions;
private _initEnvironmentFile;
private _installPackage;
}
/**
* The insert command to insert environment variables into a file.
*
* @public
*/
export declare class InsertCommand extends CommandBase {
private _options;
private _configuration;
constructor(_options: {
search?: boolean;
dry?: boolean;
directory?: string;
env?: string[];
placeholder?: string;
head?: boolean;
});
protected _execute(): Promise<void>;
private _validateConfig;
private _dryMessage;
private _configureDirectory;
private _searchEnvironmentVariables;
private _addEnvironmentVariablesFromCommandLine;
private _configureReplacement;
private _logPopulatedEnvironmentVariables;
private _insertEnvironmentVariables;
private _options;
private _configuration;
constructor(_options: {
search?: boolean;
dry?: boolean;
directory?: string;
env?: string[];
placeholder?: string;
head?: boolean;
processEnv?: boolean;
ngEnv?: boolean;
});
protected _execute(): Promise<void>;
private _validateConfig;
private _dryMessage;
private _configureDirectory;
private _searchEnvironmentVariables;
private _addEnvironmentVariablesFromCommandLine;
private _configureReplacement;
private _logPopulatedEnvironmentVariables;
private _insertEnvironmentVariables;
}
export declare function deprecated(message: string): MethodDecorator;
export declare function walk(root: string, filePattern: RegExp): string[];
/**
* Discover and apply configuration.
* Discover and apply configuration via environment variables discovered via NG_ENV usage.
*
* @public
*/
export declare abstract class Configuration {
readonly variables: string[];
/**
* The directory. Defaults to current working directory.
*/
directory: string;
/**
* The default pattern for files to have the environment variables inserted into.
*/
readonly defaultInsertionFilePattern: RegExp;
/**
* An array of replacement functions.
*/
readonly replacements: Array<(fileContent: string, fileName: string) => string>;
/**
* @param variables Optional array of environment variable names to populate.
*/
constructor(variables?: string[]);
/**
* Set the directory, where the files to be configured reside in.
* Default is current working directory.
* @param directory The directory to work in.
* @returns This instance.
*/
setDirectory(directory: string): this;
/**
* Searches for environment variable declarations in
* files matched by file pattern, starting from given directory.
*
* @param options Optional options for searching environment variables.
* @param options.directory The root directory from which to search.
* @param options.filePattern The file pattern in which environment
* variables should be searched (Defaults to /.js$/).
* @returns This instance.
*/
searchEnvironmentVariables(options?: {
directory?: string;
filePattern?: RegExp;
}): this;
/**
* Replace the base href attribute for the file received through
* applyTo, applyAndSaveTo or applyAndSaveRecursively.
*
* @param newBaseHref The new base href.
* @returns This instance.
*/
replaceBaseHref(newBaseHref: string): this;
/**
* Replace the html lang attribute for the file received through
* applyTo, applyAndSaveTo or applyAndSaveRecursively.
*
* @param newHtmlLang The new base href.
* @returns This instance.
*/
replaceHtmlLang(newHtmlLang: string): this;
/**
* Replace the attribute value of a tag for the file received through
* applyTo, applyAndSaveTo or applyAndSaveRecursively.
*
* @param tag The tag, whose attribute value should be replaced.
* @param attribute The attribute, whose value should be replaced.
* @param newValue The new attribute value.
* @returns This instance.
*/
replaceTagAttribute(tag: string, attribute: string, newValue: string): this;
/**
* Add a replacement for the file received through applyTo, applyAndSaveTo or applyAndSaveRecursively.
*
* @param regex A RegExp object or literal. The match or matches are replaced with replaceValue.
* @param replaceValue The value that replaces the substring matched by the regex parameter.
* @returns This instance.
*/
regexReplace(regex: RegExp, replaceValue: string): this;
/**
* Replace the placeholder with the populated variables wrapped in an IIFE inside a script tag.
* @param placeholder The placeholder to replace with the populated variables.
* (Defaults to <!--CONFIG-->.)
* @returns This instance.
*/
insertVariables(placeholder?: string | RegExp): this;
/**
* Insert the populated variables (wrapped in an IIFE inside a script tag) into the head tag.
* Appends variables to title tag, or if not found, at the end of the head tag.
* @returns This instance.
*/
insertVariablesIntoHead(): this;
/**
* Add a replacement function for the file received through applyTo, applyAndSaveTo or
* applyAndSaveRecursively. The function receives the file content and the file name as
* parameters and returns the file content with the replacement applied.
*
* @param replacement The replacement function.
* @returns This instance.
*/
replace(replacement: (fileContent: string, fileName: string) => string): this;
/**
* Apply the replacements to the content of the matched files and save them asynchronously.
* @param options Optional options for applying replacements.
* @param options.directory The root directory from which to search files.
* (Defaults to instance directory.)
* @param options.filePattern The file pattern in which the configuration should be inserted
* (Defaults to /index.html$/).
* @returns A promise, which resolves to the matched files, after all matched files have had the
* replacements applied.
*/
applyAndSaveRecursively(options?: {
directory?: string;
filePattern?: RegExp;
}): Promise<string[]>;
/**
* Apply the replacements to the content of the given file and save it asynchronously.
* @param file The HTML file to apply the replacements to.
* @returns A promise, which resolves after the file has had the replacements applied.
*/
applyAndSaveTo(file: string): Promise<void>;
/**
* Apply the replacements to the content of the given file and return the resulting content
* as a promise.
* @param file The HTML file to apply the replacements to.
* @returns A promise, which resolves to the file content with the replacements applied.
*/
applyTo(file: string): Promise<string>;
/**
* Generates the IIFE which the renders the populated environment variables.
*/
generateIIFE(): string;
/**
* Generates an object, with the environment variable names being the key and
* the actual values being the values.
*/
populateVariables(): {
[variable: string]: any;
};
/**
* Search for variables in the received file content. Should return an array of found
* variable names.
* @param fileContent The file content that should be searched.
*/
protected abstract discoverVariables(fileContent: string): string[];
/**
* Render the IIFE
*/
protected abstract renderIIFE(environmentVariables: {
[variable: string]: any;
}): string;
export declare class NgEnvConfiguration extends Configuration {
protected discoverVariables(fileContent: string): string[];
protected renderIIFE(environmentVariables: {
[variable: string]: any;
}): string;
}
/**
* Discover and apply configuration via environment variables.
* @deprecated Use ProcessEnvConfiguration instead.
* Discover and apply configuration via environment variables discovered via process.env usage.
*
* @public
*/
export declare class EnvironmentVariablesConfiguration extends Configuration {
private environmentVariablesDiscoveryFunction;
/**
* @param variables Optional array of environment variable names to populate.
* @param replacements Optional array of replacement functions.
*/
constructor(variables?: string[], replacements?: Array<(fileContent: string, fileName: string) => string>);
/**
* Searches for environment variable declarations in
* files matched by file pattern, starting from given directory.
*
* @param directory The root directory from which to search.
* @param options Optional options for searching environment variables.
* @param options.filePattern The file pattern in which environment
* variables should be searched (Defaults to /.js$/).
* @param options.environmentVariablesDiscovery The function to discover
* environment variables in the matched files
* (Defaults to process.env.VARIABLE => VARIABLE).
* @deprecated Static searchEnvironmentVariables is deprecated. Use the instance method instead.
*/
static searchEnvironmentVariables(directory: string, options?: {
filePattern?: RegExp;
environmentVariablesDiscovery?: (fileContent: string) => string[];
}): EnvironmentVariablesConfiguration;
/**
* Searches for environment variable declarations in
* files matched by file pattern, starting from given directory.
*
* @param options Optional options for searching environment variables.
* @param options.directory The root directory from which to search.
* @param options.filePattern The file pattern in which environment
* variables should be searched (Defaults to /.js$/).
* @param options.environmentVariablesDiscovery The function to discover
* environment variables in the matched files
* (Defaults to process.env.VARIABLE => VARIABLE).
* @returns This instance.
*/
searchEnvironmentVariables(options?: {
directory?: string;
filePattern?: RegExp;
environmentVariablesDiscovery?: (fileContent: string) => string[];
}): this;
/**
* Inserts the discovered enviornment variables as an IIFE
* wrapped in a script tag into the matched files and applies added replacements.
*
* @param root The root directory from which to search insertion files.
* @param options Optional options for insertion.
* @param options.filePattern The file pattern in which the configuration should be inserted
* (Defaults to /index.html$/).
* @param options.insertionRegex The replacement pattern, where the configuration should
* be inserted (Defaults to /<!--\s*CONFIG\s*-->/).
* @returns A promise, which resolves after the environment variables have been
* inserted into all matched files. The promise resolves to an array of the matched files.
* @deprecated Use insertVariables or insertVariablesIntoHead and applyAndSaveRecursively instead.
*/
insertAndSaveRecursively(root: string, options?: {
filePattern?: RegExp;
insertionRegex?: RegExp;
}): Promise<string[]>;
/**
* Inserts the discovered environment variables as an IIFE
* wrapped in a script tag into the specified file and applies added replacements.
*
* @param file The file into which the environment variables should be inserted.
* @param options Optional options for insertion.
* @param options.insertionRegex The replacement pattern, where the configuration should
* be inserted (Defaults to /<!--\s*CONFIG\s*-->/).
* @returns A promise, which resolves after the enivornment variables have been saved to the
* given file.
* @deprecated Use insertVariables or insertVariablesIntoHead and applyAndSaveTo instead.
*/
insertAndSave(file: string, options?: {
insertionRegex?: RegExp;
}): Promise<void>;
/**
* Inserts the discovered environment variables as an IIFE wrapped in a script tag
* into the specified file content and applies added replacements without saving the file.
*
* @param file The file to be read.
* @param options Optional options for insertion.
* @param options.insertionRegex The replacement pattern, where the configuration should
* be inserted (Defaults to /<!--\s*CONFIG\s*-->/).
* @returns A promise, which resolves to the file content with the environment variables inserted.
* @deprecated Use insertVariables or insertVariablesIntoHead and applyTo instead.
*/
apply(file: string, options?: {
insertionRegex?: RegExp;
}): Promise<string>;
protected discoverVariables(fileContent: string): string[];
protected renderIIFE(environmentVariables: {
[variable: string]: any;
}): string;
export declare class ProcessEnvConfiguration extends Configuration {
protected discoverVariables(fileContent: string): string[];
protected renderIIFE(environmentVariables: {
[variable: string]: any;
}): string;
}
/**
* Discover and apply configuration via environment variables discovered via process.env usage.
* Options for searchEnvironmentVariables.
*
* @public
*/
export declare class ProcessEnvConfiguration extends Configuration {
protected discoverVariables(fileContent: string): string[];
protected renderIIFE(environmentVariables: {
[variable: string]: any;
}): string;
}
export declare interface SearchEnvironmentVariablesOptions {
/**
* The root directory from which to search.
*/
directory?: string;
/**
* The file pattern in which environment variables should be searched (Defaults to /.js$/).
*/
filePattern?: RegExp;
}
/**
* Return all files matching the given pattern.
* @param root - The root directory.
* @param filePattern - The file pattern to match files against.
*
* @public
*/
export declare function walk(root: string, filePattern: RegExp): string[];
/**
* The wrap-aot command to retain angular-server-side-configuration variables through AoT.
*
* @public
*/
export declare class WrapAotCommand extends CommandBase {
private _options;
private readonly _environmentFile;
private readonly _dist;
private _tokenCounter;
constructor(_options: {
ngCommands: string[];
directory: string;
environmentFile?: string;
dist?: string;
processEnv?: boolean;
ngEnv?: boolean;
});
protected _execute(): Promise<void>;
private _validateOptions;
private _createReplacements;
protected _loadTypescript(): Promise<{
createSourceFile: typeof import("typescript").createSourceFile;
ScriptTarget: typeof import("typescript").ScriptTarget;
SyntaxKind: typeof import("typescript").SyntaxKind;
}>;
private _resolveReplacements;
private _findUsages;
private _applyReplacements;
private _resolveExpression;
protected _spawnCommand(): Promise<void>;
private _revertReplacements;
}
export { }
{
"name": "angular-server-side-configuration",
"version": "1.3.0",
"version": "2.0.0-beta.0",
"description": "Configure an angular application on the server",
"main": "./main.js",
"module": "./index.js",
"types": "./index.d.ts",
"typings": "./index.d.ts",
"tsdoc": {
"tsdocFlavor": "AEDoc"
},
"bin": {

@@ -12,7 +15,8 @@ "ngssc": "./bin/ngssc"

"scripts": {
"clean": "rimraf .rpt2_cache coverage index.d.ts index.js main.js",
"build:ts": "rollup -c rollup.config.js",
"build:dts": "dts-bundle-generator -o index.d.ts ./src/index.ts",
"build:docs": "typedoc --theme markdown --out documentation --mode modules --exclude **/*.spec.ts src",
"build": "npm run build:ts && npm run build:dts",
"clean:build": "rimraf .rpt2_cache dist typings",
"clean": "npm run clean:build && rimraf coverage index.d.ts index.js main.js",
"build:rollup": "rollup -c rollup.config.js",
"build:typings": "api-extractor run",
"build:docs": "api-documenter markdown --input-folder dist --output-folder documentation",
"build": "npm run clean && npm run build:rollup && npm run build:typings && npm run build:docs && npm run clean:build",
"pretest": "npm run clean",

@@ -42,6 +46,5 @@ "test": "jest -i",

"homepage": "https://github.com/kyubisation/angular-server-side-configuration#readme",
"dependencies": {
"esm": "^3.2.14"
},
"devDependencies": {
"@microsoft/api-documenter": "^7.0.30",
"@microsoft/api-extractor": "^7.0.23",
"@types/cross-spawn": "^6.0.0",

@@ -53,3 +56,2 @@ "@types/jest": "^24.0.11",

"cross-spawn": "^6.0.5",
"dts-bundle-generator": "^2.1.0",
"jest": "^24.3.1",

@@ -65,4 +67,2 @@ "rimraf": "^2.6.3",

"tslint": "^5.13.1",
"typedoc": "^0.14.2",
"typedoc-plugin-markdown": "^1.1.27",
"typescript": "^3.3.3333"

@@ -69,0 +69,0 @@ },

@@ -8,3 +8,2 @@ # angular-server-side-configuration

[Documentation](https://github.com/kyubisation/angular-server-side-configuration/blob/master/documentation/README.md)

@@ -28,3 +27,4 @@ Configure an angular application at runtime on the server via environment variables.

With `ngssc wrap-aot ng build ...` it is however possible to retain the configuration, by replacing
With `ngssc wrap-aot ng build ...` (or `ngssc wrap-aot --ng-env ng build ...` for NG_ENV)
it is however possible to retain the configuration, by replacing
the environment variables with tokens during the AoT build and reverting afterwards. (See [CLI wrap-aot](#wrap-aot))

@@ -38,2 +38,5 @@

### environment.prod.ts
angular-server-side-configuration supports two variants for using environment variables: process.env.* or NG_ENV.*
#### process.env.*
Use process.env.NAME in your environment.prod.ts, where NAME is the

@@ -51,2 +54,17 @@ environment variable that should be used.

#### NG_ENV.*
Import NG_ENV from `angular-server-side-configuration/ng-env`
(or `angular-server-side-configuration/ng4-env` for Angular 4 or 5)
and use NG_ENV.NAME in your environment.prod.ts, where NAME is the
environment variable that should be used.
```typescript
import { NG_ENV } from 'angular-server-side-configuration/ng-env';
export const environment = {
production: NG_ENV.PROD !== 'false',
apiAddress: NG_ENV.API_ADDRESS || 'https://example-api.com'
};
```
### index.html (Optional)

@@ -81,2 +99,9 @@ Add `<!--CONFIG-->` to index.html. This will be replaced by the configuration script tag.

Or if NG_ENV was used:
```bash
npm install -g angular-server-side-configuration
ngssc insert /path/to/angular/files --ng-env --search
```
## CLI

@@ -102,2 +127,4 @@ angular-server-side-configuration provides a CLI.

| `--dry` | Perform the insert without actually inserting the variables |
| `--process-env` | Use process.env for insertion (Default) |
| `--ng-env` | Use NG_ENV for insertion |
| `-h, --help` | output usage information |

@@ -115,2 +142,4 @@

| `--yarn` | Install angular-service-side-configuration via yarn |
| `--process-env` | Initialize with process.env variant (Default) |
| `--ng-env` | Initialize with NG_ENV variant |
| `-h, --help` | output usage information |

@@ -128,24 +157,11 @@

| `--dist` | The output path of the ng build (Defaults to dist/**) |
| `--process-env` | Use process.env variant (Default) |
| `--ng-env` | Use NG_ENV variant |
| `-h, --help` | output usage information |
## Native CLI
If node.js cannot be used on the target system, it is also possible to compile ngssc to a native CLI with tools like [pkg](https://www.npmjs.com/package/pkg) or [nexe](https://www.npmjs.com/package/nexe).
## API Documentation
Create a file named ngssc.js:
```javascript
require('angular-server-side-configuration').cli().parse(process.argv);
```
[API Documentation](https://github.com/kyubisation/angular-server-side-configuration/blob/master/documentation/angular-server-side-configuration.md)
And then use pkg or nexe to build the native ngssc CLI:
```
npm install pkg -g
pkg ngssc.js
```
```
npm install nexe -g
nexe ngssc.js --target os-of-target-system
```
## License
Apache License, Version 2.0

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display