Exemple #1
0
 test(testName, () => {
   new PolymerCli(['help', '--verbose']);
   let logger = logging.getLogger('TEST_LOGGER');
   // tslint:disable-next-line: no-any
   assert.equal((logger as any)['level'], 'debug');
   new PolymerCli(['help', '--quiet']);
   logger = logging.getLogger('TEST_LOGGER');
   // tslint:disable-next-line: no-any
   assert.equal((logger as any)['level'], 'error');
 });
Exemple #2
0
 test(testName, () => {
   const logger = logging.getLogger('TEST_LOGGER');
   new PolymerCli(['help', '--verbose']);
   assert.equal((logger as any)['level'], 'debug');
   new PolymerCli(['help', '--quiet']);
   assert.equal((logger as any)['level'], 'error');
 });
Exemple #3
0
/*
 * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
 * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
 * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
 * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
 * Code distributed by Google as part of the polymer project is also
 * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
 */

import * as fs from 'fs';
import {Github} from '../github/github';
import * as path from 'path';
import {Base} from 'yeoman-generator';
import * as logging from 'plylog';

let logger = logging.getLogger('cli.init');

export interface GithubGeneratorOptions {
  requestApi?;
  githubApi?;
  githubToken?;
  owner: string;
  repo: string;
}

export function createGithubGenerator(githubOptions: GithubGeneratorOptions) {
  let requestApi = githubOptions.requestApi;
  let githubApi = githubOptions.githubApi;
  let githubToken = githubOptions.githubToken;
  let owner = githubOptions.owner;
  let repo = githubOptions.repo;
Exemple #4
0
 * http://polymer.github.io/PATENTS.txt
 */

import * as chalk from 'chalk';
import * as fs from 'fs';
import * as logging from 'plylog';

import findup = require('findup-sync');
import * as YeomanEnvironment from 'yeoman-environment';
import {createApplicationGenerator} from '../init/application/application';
import {createElementGenerator} from '../init/element/element';
import {createGithubGenerator} from '../init/github';
import Generator = require('yeoman-generator');
import {prompt} from '../util';

const logger = logging.getLogger('init');

interface GeneratorDescription {
  name: string;
  value: string;
  short: string;
}

interface GeneratorInfo {
  id: string;
  description: string;
  generator: typeof Generator;
}

const localGenerators: {[name: string]: GeneratorInfo} = {
  'polymer-2-element': {
 * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
 * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
 * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
 * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
 * Code distributed by Google as part of the polymer project is also
 * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
 */

import {Transform} from 'stream';
import * as uglify from 'uglify-js';
import * as logging from 'plylog';
import File = require('vinyl');

import {FileCB} from './streams';

let logger = logging.getLogger('cli.build.uglify');
const UglifyOptions: uglify.MinifyOptions = { fromString: true };

export class UglifyTransform extends Transform {

  constructor() {
    super({objectMode: true});
  }

  _transform(file: File, encoding: string, callback: FileCB): void {
    if (file.contents && file.path.endsWith('.js')) {
      try {
        let contents = file.contents.toString();
        contents = uglify.minify(contents, UglifyOptions).code;
        file.contents = new Buffer(contents);
      } catch (err) {
 * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
 * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
 * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
 * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
 * Code distributed by Google as part of the polymer project is also
 * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
 */

import {writeFile} from 'fs';
import * as path from 'path';
import * as logging from 'plylog';
import {PolymerProject} from './polymer-project';
import {DepsIndex} from './analyzer';
import {SWConfig, generate as swPrecacheGenerate} from 'sw-precache';

let logger = logging.getLogger('polymer-build.service-worker');

export interface AddServiceWorkerOptions {
  project: PolymerProject;
  buildRoot: string;
  bundled?: boolean;
  serviceWorkerPath?: string;
  swConfig?: SWConfig;
}

/**
 * Returns an array of file paths for the service worker to precache, based on
 * the information provided in the DepsIndex object.
 */
function getPrecachedAssets(depsIndex: DepsIndex, project: PolymerProject): string[] {
  let precachedAssets = new Set<string>(project.analyzer.allFragments);
 * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
 * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
 * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
 * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
 * Code distributed by Google as part of the polymer project is also
 * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
 */

import * as dom5 from 'dom5';
import * as path from 'path';
import * as logging from 'plylog';
import {Transform} from 'stream';
import File = require('vinyl');
import {StreamAnalyzer, DepsIndex} from 'polymer-build';

let logger = logging.getLogger('cli.build.prefech');

export class PrefetchTransform extends Transform {
  root: string;
  entrypoint: string;
  shell: string;
  fragments: string[];
  allFragments: string[];
  fileMap: Map<string, File>;
  analyzer: StreamAnalyzer;

  constructor(
    /**
     * Root of the dependencies.
     * Will be stripped when making links
     */
Exemple #8
0
 * subject to an additional IP rights grant found at
 * http://polymer.github.io/PATENTS.txt
 */

import * as bower from 'bower';
import {read as readBowerJson} from 'bower-json';
import * as child_process from 'child_process';
import * as path from 'path';
import * as logging from 'plylog';

import defaultBowerConfig = require('bower/lib/config');
import BowerLogger = require('bower-logger');
import StandardRenderer = require('bower/lib/renderers/StandardRenderer');
import BowerProject = require('bower/lib/core/Project');

const logger = logging.getLogger('cli.install');

async function exec(command: string, opts: child_process.ExecOptions) {
  return new Promise<[string, string]>((resolve, reject) => {
    child_process.exec(command, opts, (err, stdout, stderr) => {
      err ? reject(err) : resolve([stdout, stderr]);
    });
  });
}

type JsonValue = string|number|boolean|null|JsonObject|JsonArray;

interface JsonObject {
  [key: string]: JsonValue;
}
Exemple #9
0
/**
 * @license
 * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
 * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
 * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
 * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
 * Code distributed by Google as part of the polymer project is also
 * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
 */


import * as fs from 'fs';
import * as logging from 'plylog';
import {SWConfig} from 'polymer-build';

let logger = logging.getLogger('cli.build.sw-precache');

export function parsePreCacheConfig(configFile: string): Promise<SWConfig> {
  return new Promise<SWConfig>((resolve, reject) => {
    fs.stat(configFile, (err) => {
      let config: SWConfig;
      // only log if the config file exists at all
      if (!err) {
        try {
          config = require(configFile);
        } catch (e) {
          logger.warn(`${configFile} file was found but could not be loaded`, {err});
        }
      }
      resolve(config);
    });
Exemple #10
0
import {JsCompileTarget, ModuleResolutionStrategy} from 'polymer-project-config';
import {Transform} from 'stream';
import * as vinyl from 'vinyl';

import matcher = require('matcher');

import {jsTransform} from './js-transform';
import {htmlTransform} from './html-transform';
import {isHtmlSplitterFile} from './html-splitter';

// TODO(fks) 09-22-2016: Latest npm type declaration resolves to a non-module
// entity. Upgrade to proper JS import once compatible .d.ts file is released,
// or consider writing a custom declaration in the `custom_typings/` folder.
import File = require('vinyl');

const logger = logging.getLogger('cli.build.optimize-streams');

export type FileCB = (error?: Error, file?: File) => void;
export type CSSOptimizeOptions = {
  stripWhitespace?: boolean;
};
export interface OptimizeOptions {
  html?: {
    minify?: boolean|{exclude?: string[]},
  };
  css?: {
    minify?: boolean|{exclude?: string[]},
  };
  js?: JsOptimizeOptions;
  entrypointPath?: string;
  rootDir?: string;