How to use @aurelia/plugin-conventions - 10 common examples

To help you get started, we’ve selected a few @aurelia/plugin-conventions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aurelia / aurelia / packages / plugin-gulp / src / index.ts View on Github external
export function plugin(
  options: IOptionalPreprocessOptions,
  _preprocess = preprocess // for testing
) {
  const allOptions = preprocessOptions(options);
  return new Transform({
    objectMode: true,
    transform: function(file: Vinyl, enc, cb) {
      if (file.isStream()) {
        this.emit('error', new Error('@aurelia/plugin-gulp: Streaming is not supported'));
      } else if (file.isBuffer()) {
        // Rewrite foo.html to foo.html.js
        const result = _preprocess(
          {
            path: file.relative,
            contents: file.contents.toString(),
            base: file.base
          },
          allOptions
        );
github aurelia / aurelia / packages / plugin-gulp / dist / esnext / index.js View on Github external
export function plugin(options, _preprocess = preprocess // for testing
) {
    const allOptions = preprocessOptions(options);
    return new Transform({
        objectMode: true,
        transform: function (file, enc, cb) {
            if (file.isStream()) {
                this.emit('error', new Error('@aurelia/plugin-gulp: Streaming is not supported'));
            }
            else if (file.isBuffer()) {
                // Rewrite foo.html to foo.html.js
                const result = _preprocess({
                    path: file.relative,
                    contents: file.contents.toString(),
                    base: file.base
                }, allOptions);
                if (result) {
                    if (allOptions.templateExtensions.includes(file.extname)) {
                        // Rewrite foo.html to foo.html.js, or foo.md to foo.md.js
github aurelia / aurelia / packages / webpack-loader / src / index.ts View on Github external
export function loader(
  this: webpack.loader.LoaderContext,
  contents: string,
  _preprocess = preprocess // for testing
) {
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions, @typescript-eslint/strict-boolean-expressions
  this.cacheable && this.cacheable();
  const cb = this.async() as webpack.loader.loaderCallback;
  const options = getOptions(this) as IOptionalPreprocessOptions;

  const filePath = this.resourcePath;

  try {
    const result = _preprocess(
      { path: filePath, contents },
      preprocessOptions(options || {})
    );
    // webpack uses source-map 0.6.1 typings for RawSourceMap which
    // contains typing error version: string (should be number).
    // use result.map as any to bypass the typing issue.
    if (result) {
      cb(null, result.code, result.map as any);
      return;
    }

    // bypassed
    cb(null, contents);
  } catch (e) {
    cb(e);
  }
}
github aurelia / aurelia / packages / webpack-loader / dist / umd / index.js View on Github external
function loader(contents, _preprocess = plugin_conventions_1.preprocess // for testing
    ) {
        // eslint-disable-next-line @typescript-eslint/no-unused-expressions, @typescript-eslint/strict-boolean-expressions
        this.cacheable && this.cacheable();
        const cb = this.async();
        const options = loader_utils_1.getOptions(this);
        const filePath = this.resourcePath;
        try {
            const result = _preprocess({ path: filePath, contents }, plugin_conventions_1.preprocessOptions(options || {}));
            // webpack uses source-map 0.6.1 typings for RawSourceMap which
            // contains typing error version: string (should be number).
            // use result.map as any to bypass the typing issue.
            if (result) {
                cb(null, result.code, result.map);
                return;
            }
            // bypassed
            cb(null, contents);
        }
        catch (e) {
            cb(e);
        }
    }
    exports.loader = loader;
github aurelia / aurelia / packages / webpack-loader / dist / esnext / index.js View on Github external
export function loader(contents, _preprocess = preprocess // for testing
) {
    // eslint-disable-next-line @typescript-eslint/no-unused-expressions, @typescript-eslint/strict-boolean-expressions
    this.cacheable && this.cacheable();
    const cb = this.async();
    const options = getOptions(this);
    const filePath = this.resourcePath;
    try {
        const result = _preprocess({ path: filePath, contents }, preprocessOptions(options || {}));
        // webpack uses source-map 0.6.1 typings for RawSourceMap which
        // contains typing error version: string (should be number).
        // use result.map as any to bypass the typing issue.
        if (result) {
            cb(null, result.code, result.map);
            return;
        }
        // bypassed
        cb(null, contents);
    }
    catch (e) {
        cb(e);
    }
}
//# sourceMappingURL=index.js.map
github aurelia / aurelia / packages / __tests__ / plugin-conventions / preprocess-resource.spec.ts View on Github external
it('injects valueConverter decorator for non-kebab case file name', function () {
    const code = `export class FooBarValueConverter {}\n`;
    const expected = `import { valueConverter } from '@aurelia/runtime';
@valueConverter('fooBar')
export class FooBarValueConverter {}
`;
    const result = preprocessResource(
      {
        path: path.join('bar', 'FooBar.js'),
        contents: code,
        filePair: 'FooBar.html'
      },
      preprocessOptions()
    );
    assert.equal(result.code, expected);
  });
github aurelia / aurelia / packages / __tests__ / plugin-conventions / options.spec.ts View on Github external
it('merges optional extensions', function () {
    assert.deepEqual(
      preprocessOptions({
        cssExtensions: ['.css', '.some'],
        jsExtensions: ['.mjs'],
        templateExtensions: ['.markdown']
      }),
      {
        cssExtensions: ['.css', '.less', '.sass', '.scss', '.some', '.styl'],
        jsExtensions: ['.coffee', '.js', '.jsx', '.mjs', '.ts', '.tsx'],
        templateExtensions: ['.haml', '.html', '.jade', '.markdown', '.md', '.pug', '.slim', '.slm'],
        stringModuleWrap: undefined
      }
    );
  });
github aurelia / aurelia / packages / __tests__ / plugin-conventions / name-convention.spec.ts View on Github external
it('gets value converter like resource', function() {
    assert.deepEqual(nameConvention('FooBarValueConverter'), {
      name: 'fooBar',
      type: 'valueConverter'
    });

    assert.deepEqual(nameConvention('Foo1Bar23ValueConverter'), {
      name: 'foo1Bar23',
      type: 'valueConverter'
    });
  });
github aurelia / aurelia / packages / __tests__ / plugin-conventions / name-convention.spec.ts View on Github external
it('gets custom attribute like resource', function() {
    assert.deepEqual(nameConvention('FooBarCustomAttribute'), {
      name: 'foo-bar',
      type: 'customAttribute'
    });

    assert.deepEqual(nameConvention('Foo1BarCustomAttribute'), {
      name: 'foo1-bar',
      type: 'customAttribute'
    });
  });
github aurelia / aurelia / packages / __tests__ / plugin-conventions / name-convention.spec.ts View on Github external
it('gets custom element like resource', function() {
    assert.deepEqual(nameConvention('FooBar'), {
      name: 'foo-bar',
      type: 'customElement'
    });

    assert.deepEqual(nameConvention('FooBar123'), {
      name: 'foo-bar123',
      type: 'customElement'
    });
  });

@aurelia/plugin-conventions

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/) [![CircleCI](https://circleci.com/

MIT
Latest version published 2 months ago

Package Health Score

84 / 100
Full package analysis