本文整理汇总了TypeScript中@angular-devkit/core.normalize函数的典型用法代码示例。如果您正苦于以下问题:TypeScript normalize函数的具体用法?TypeScript normalize怎么用?TypeScript normalize使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了normalize函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('can create the proper recorder (bom)', () => {
const eBom = new SimpleFileEntry(normalize('/some/path'), Buffer.from('\uFEFFhello'));
expect(UpdateRecorderBase.createFromFileEntry(eBom) instanceof UpdateRecorderBase).toBe(true);
expect(UpdateRecorderBase.createFromFileEntry(eBom) instanceof UpdateRecorderBom).toBe(true);
});
示例2: describe
describe('Browser Builder scripts array', () => {
const outputPath = normalize('dist');
const scripts: { [path: string]: string } = {
'src/input-script.js': 'console.log(\'input-script\'); var number = 1+1;',
'src/zinput-script.js': 'console.log(\'zinput-script\');',
'src/finput-script.js': 'console.log(\'finput-script\');',
'src/uinput-script.js': 'console.log(\'uinput-script\');',
'src/binput-script.js': 'console.log(\'binput-script\');',
'src/ainput-script.js': 'console.log(\'ainput-script\');',
'src/cinput-script.js': 'console.log(\'cinput-script\');',
'src/lazy-script.js': 'console.log(\'lazy-script\');',
'src/pre-rename-script.js': 'console.log(\'pre-rename-script\');',
'src/pre-rename-lazy-script.js': 'console.log(\'pre-rename-lazy-script\');',
};
const getScriptsOption = () => [
'src/input-script.js',
'src/zinput-script.js',
'src/finput-script.js',
'src/uinput-script.js',
'src/binput-script.js',
'src/ainput-script.js',
'src/cinput-script.js',
{ input: 'src/lazy-script.js', bundleName: 'lazy-script', lazy: true },
{ input: 'src/pre-rename-script.js', bundleName: 'renamed-script' },
{ input: 'src/pre-rename-lazy-script.js', bundleName: 'renamed-lazy-script', lazy: true },
];
beforeEach(done => host.initialize().toPromise().then(done, done.fail));
afterEach(done => host.restore().toPromise().then(done, done.fail));
it('works', (done) => {
const matches: { [path: string]: string } = {
'./dist/scripts.js': 'input-script',
'./dist/lazy-script.js': 'lazy-script',
'./dist/renamed-script.js': 'pre-rename-script',
'./dist/renamed-lazy-script.js': 'pre-rename-lazy-script',
'./dist/main.js': 'input-script',
'./dist/index.html': '<script type="text/javascript" src="runtime.js"></script>'
+ '<script type="text/javascript" src="polyfills.js"></script>'
+ '<script type="text/javascript" src="scripts.js"></script>'
+ '<script type="text/javascript" src="renamed-script.js"></script>'
+ '<script type="text/javascript" src="vendor.js"></script>'
+ '<script type="text/javascript" src="main.js"></script>',
};
host.writeMultipleFiles(scripts);
host.appendToFile('src/main.ts', '\nimport \'./input-script.js\';');
// Remove styles so we don't have to account for them in the index.html order check.
const overrides = {
styles: [],
scripts: getScriptsOption(),
};
runTargetSpec(host, browserTargetSpec, overrides).pipe(
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
tap(() => Object.keys(matches).forEach(fileName => {
const content = virtualFs.fileBufferToString(host.scopedSync().read(normalize(fileName)));
expect(content).toMatch(matches[fileName]);
})),
).toPromise().then(done, done.fail);
});
it('uglifies, uses sourcemaps, and adds hashes', (done) => {
host.writeMultipleFiles(scripts);
const overrides = {
optimization: true,
sourceMap: true,
outputHashing: 'all',
scripts: getScriptsOption(),
};
runTargetSpec(host, browserTargetSpec, overrides, DefaultTimeout * 2).pipe(
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
tap(() => {
const scriptsBundle = host.fileMatchExists(outputPath, /scripts\.[0-9a-f]{20}\.js/);
expect(scriptsBundle).toBeTruthy();
const fileName = join(outputPath, scriptsBundle as PathFragment);
const content = virtualFs.fileBufferToString(host.scopedSync().read(normalize(fileName)));
expect(content).toMatch('var number=2;');
expect(host.fileMatchExists(outputPath, /scripts\.[0-9a-f]{20}\.js\.map/))
.toBeTruthy();
expect(host.fileMatchExists(outputPath, /renamed-script\.[0-9a-f]{20}\.js/))
.toBeTruthy();
expect(host.fileMatchExists(outputPath, /renamed-script\.[0-9a-f]{20}\.js\.map/))
.toBeTruthy();
expect(host.fileMatchExists(outputPath, /scripts\.[0-9a-f]{20}\.js/)).toBeTruthy();
expect(host.scopedSync().exists(normalize('dist/lazy-script.js'))).toBe(true);
expect(host.scopedSync().exists(normalize('dist/lazy-script.js.map'))).toBe(true);
expect(host.scopedSync().exists(normalize('dist/renamed-lazy-script.js'))).toBe(true);
expect(host.scopedSync().exists(normalize('dist/renamed-lazy-script.js.map')))
.toBe(true);
}),
).toPromise().then(done, done.fail);
});
it('preserves script order', (done) => {
host.writeMultipleFiles(scripts);
//.........这里部分代码省略.........
示例3: tap
tap(() => {
const fileName = 'dist/index.html';
const content = virtualFs.fileBufferToString(host.scopedSync().read(normalize(fileName)));
expect(content).toMatch(/Welcome to app!/);
}),
示例4: expect
.then(() => {
const tmpFiles = outputHost.files.sort();
expect(tmpFiles as string[]).toEqual(files);
expect(outputHost.sync.read(normalize('/test')).toString())
.toBe('testing testing 1 2');
})
示例5: _mapAssets
.map((app, idx) => {
const defaultAppName = idx === 0 ? defaultAppNamePrefix : `${defaultAppNamePrefix}${idx}`;
const name = app.name || defaultAppName;
const outDir = app.outDir || defaults.outDir;
const appRoot = app.root || defaults.appRoot;
function _mapAssets(asset: string | JsonObject) {
if (typeof asset === 'string') {
return normalize(appRoot + '/' + asset);
} else {
if (asset.allowOutsideOutDir) {
logger.warn(tags.oneLine`
Asset with input '${asset.input}' was not migrated because it
uses the 'allowOutsideOutDir' option which is not supported in Angular CLI 6.
`);
return null;
} else if (asset.output) {
return {
glob: asset.glob,
input: normalize(appRoot + '/' + asset.input),
output: normalize('/' + asset.output as string),
};
} else {
return {
glob: asset.glob,
input: normalize(appRoot + '/' + asset.input),
output: '/',
};
}
}
}
function _buildConfigurations(): JsonObject {
const source = app.environmentSource;
const environments = app.environments;
const serviceWorker = app.serviceWorker;
const productionPartial = {
optimization: true,
outputHashing: 'all',
sourceMap: false,
extractCss: true,
namedChunks: false,
aot: true,
extractLicenses: true,
vendorChunk: false,
buildOptimizer: true,
...(serviceWorker ? {serviceWorker: true, ngswConfigPath: 'src/ngsw-config.json'} : {}),
...(app.budgets ? { budgets: app.budgets as JsonArray} : {}),
};
if (!environments) {
return { production: productionPartial };
}
const configurations = Object.keys(environments).reduce((acc, environment) => {
if (source === environments[environment]) {
return acc;
}
let isProduction = false;
const environmentContent = tree.read(app.root + '/' + environments[environment]);
if (environmentContent) {
isProduction = !!environmentContent.toString('utf-8')
// Allow for `production: true` or `production = true`. Best we can do to guess.
.match(/production['"]?\s*[:=]\s*true/);
}
let configurationName;
// We used to use `prod` by default as the key, instead we now use the full word.
// Try not to override the production key if it's there.
if (environment == 'prod' && !environments['production'] && isProduction) {
configurationName = 'production';
} else {
configurationName = environment;
}
acc[configurationName] = {
...(isProduction ? productionPartial : {}),
fileReplacements: [
{
replace: `${app.root}/${source}`,
with: `${app.root}/${environments[environment]}`,
},
],
};
return acc;
}, {} as JsonObject);
if (!configurations['production']) {
configurations['production'] = { ...productionPartial };
}
return configurations;
}
function _serveConfigurations(): JsonObject {
//.........这里部分代码省略.........
示例6: normalize
/**
* @license
* Copyright Akveo. All Rights Reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/
import { dirname, fragment, join, normalize, Path, PathFragment, strings } from '@angular-devkit/core';
import { DirEntry, Tree } from '@angular-devkit/schematics';
export const PREFIX = '';
export const FEATURE_MODULE_EXT = '.module.ts';
export const ROUTING_MODULE_EXT = '-routing.module.ts';
export const PLAYGROUND_PATH: Path = normalize('/src/playground/');
export const PLAYGROUND_ROUTING_MODULE_PATH: Path = join(PLAYGROUND_PATH, `playground${ROUTING_MODULE_EXT}`);
export const LAYOUT_DIR_NAME = 'with-layout';
export const LAYOUT_DIR_PATH = join(PLAYGROUND_PATH, LAYOUT_DIR_NAME);
export const LAYOUT_MODULE_PATH = join(LAYOUT_DIR_PATH, `${LAYOUT_DIR_NAME}${FEATURE_MODULE_EXT}`);
export const LAYOUT_ROUTING_MODULE_PATH = join(LAYOUT_DIR_PATH, `${LAYOUT_DIR_NAME}${ROUTING_MODULE_EXT}`);
export const LAYOUT_MODULE_CLASS = 'WithLayoutModule';
export const LAYOUT_COMPONENT_CLASS = 'PlaygroundLayoutComponent';
export const NO_LAYOUT_DIR_NAME = 'without-layout';
export const NO_LAYOUT_DIR_PATH = join(PLAYGROUND_PATH, NO_LAYOUT_DIR_NAME);
export const NO_LAYOUT_MODULE_PATH = join(NO_LAYOUT_DIR_PATH, `${NO_LAYOUT_DIR_NAME}${FEATURE_MODULE_EXT}`);
export const NO_LAYOUT_ROUTING_MODULE_PATH = join(NO_LAYOUT_DIR_PATH, `${NO_LAYOUT_DIR_NAME}${ROUTING_MODULE_EXT}`);
export const NO_LAYOUT_MODULE_CLASS = 'WithoutLayoutModule';
export const NO_LAYOUT_COMPONENT_CLASS = 'PlaygroundBaseComponent';
export const INCLUDE_DIRS: string[] = [ LAYOUT_DIR_PATH, NO_LAYOUT_DIR_PATH ];
示例7: it
it('supports isFile / isDirectory', () => {
const host = new SyncDelegateHost(new SimpleMemoryHost());
const buffer = stringToFileBuffer('hello');
host.write(normalize('/sub/file1'), buffer);
host.write(normalize('/sub/file2'), buffer);
host.write(normalize('/sub/sub1/file3'), buffer);
host.write(normalize('/file4'), buffer);
expect(host.isFile(normalize('/sub'))).toBe(false);
expect(host.isFile(normalize('/sub1'))).toBe(false);
expect(host.isDirectory(normalize('/'))).toBe(true);
expect(host.isDirectory(normalize('/sub'))).toBe(true);
expect(host.isDirectory(normalize('/sub/sub1'))).toBe(true);
expect(host.isDirectory(normalize('/sub/file1'))).toBe(false);
expect(host.isDirectory(normalize('/sub/sub1/file3'))).toBe(false);
});
示例8: tap
tap(() => {
expect(host.scopedSync().exists(normalize('./dist/folder/asset.txt'))).toBe(true);
expect(host.scopedSync().exists(normalize('./dist/folder/asset-ignored.txt'))).toBe(false);
expect(host.scopedSync().exists(normalize('./dist/folder/.gitkeep'))).toBe(false);
}),