Ejemplo n.º 1
0
export default
function loadPatterns(): TestPattern[] {
  const yamlGlob = path.join(__dirname, "../../../src/test/patterns/**/*.yml");
  const yamlPaths: string[] = glob.sync(yamlGlob);
  return yamlPaths
    .map(path => yaml.safeLoad(fs.readFileSync(path, "utf8")))
    .reduce((x, y) => x.concat(y));
}
Ejemplo n.º 2
0
export async function getGrapherExportsByUrl(): Promise<{ get: (grapherUrl: string) => ChartExportMeta }> {
    // Index the files to see what we have available, using the most recent version
    // if multiple exports exist
    const files = glob.sync(`${BAKED_SITE_DIR}/exports/*.svg`)
    const exportsByKey = new Map()
    for (const filepath of files) {
        const filename = path.basename(filepath)
        const [key, version, dims] = filename.split("_")
        const versionNumber = parseInt(version.split('v')[1])
        const [width, height] = dims.split("x")

        const current = exportsByKey.get(key)
        if (!current || current.version < versionNumber) {
            exportsByKey.set(key, {
                key: key,
                svgUrl: `${BAKED_BASE_URL}/exports/${filename}`,
                version: versionNumber,
                width: parseInt(width),
                height: parseInt(height)
            })
        }
    }

    return {
        get(grapherUrl: string) {
            return exportsByKey.get(grapherUrlToFilekey(grapherUrl))
        }
    }
}
Ejemplo n.º 3
0
export function findLazyModules(projectRoot: any): {[key: string]: string} {
  const result: {[key: string]: string} = {};
  glob.sync(path.join(projectRoot, '/**/*.ts'))
    .forEach(tsPath => {
      findLoadChildren(tsPath).forEach(moduleName => {
        let fileName = moduleName.startsWith('.')
          ? path.resolve(path.dirname(tsPath), moduleName) + '.ts'
          : path.resolve(projectRoot, moduleName) + '.ts';

        if (fs.existsSync(fileName)) {
          // Put the moduleName as relative to the main.ts.
          result[moduleName] = fileName;
        } else {
          try {
            let res = resolve.sync(moduleName, { basedir: projectRoot });
            if (res) {
              result[moduleName] = res;
            }
          } catch (e) {
          }
        }
      });
    });
  return result;
}
Ejemplo n.º 4
0
describe('Error Test', () => {
  var errorFileNames = glob.sync('./test/fixtures/typings/errors/**/*.ts');

  errorFileNames.forEach((errorFileName) => {
    context(errorFileName.replace('./test/fixtures/typings/errors/', ''), () => {
      var plugin = typhen.loadPlugin('./test/fixtures/plugin/typhen-test', {
        author: 'shiwano'
      });

      before((done) => {
        rimraf('./.tmp/generated', done);
      });

      it('should raise error', (done) => {
        typhen.run({
          plugin: plugin,
          src: errorFileName,
          dest: '.tmp/generated'
        }).catch(e => {
          done();
        });
      });

      it('should not generate anything', (done) => {
        glob('./.tmp/generated/**/*.md', (err, fileNames) => {
          assert(fileNames.length === 0);
          done();
        });
      });
    });
  });
});
Ejemplo n.º 5
0
export function copyFiles(fromPath: string, fileGlob: string, outDir: string) {
  glob(fileGlob, { cwd: fromPath }).forEach(filePath => {
    const fileDestPath = join(outDir, filePath);
    mkdirpSync(dirname(fileDestPath));
    copySync(join(fromPath, filePath), fileDestPath);
  });
}
Ejemplo n.º 6
0
describe("react-icon-loader", async () => {
  const svgFiles = glob.sync("node_modules/material-design-icons/action/svg/design/*48px.svg");

  for (const file of svgFiles) {
    test(`cli ${file}`, async () => {
      await cli(file);
    });
  }

  test("compile", async () => {
    const tsFiles = glob.sync("node_modules/material-design-icons/action/svg/design/*.ts");
    expect(tsFiles).toHaveLength(svgFiles.length);
    const tsRes = await exec(`./node_modules/.bin/tsc ${tsFiles.join(" ")}`);
    expect(tsRes.stderr).toHaveLength(0);
  });

  test("exec", async () => {
    const jsFiles = glob.sync("node_modules/material-design-icons/action/svg/design/*.js");
    expect(jsFiles).toHaveLength(svgFiles.length);
    for (const file of jsFiles) {
      const nodeRes = await exec(`node ${file}`);
      expect(nodeRes.stderr).toHaveLength(0);
    }
  });
});
export function markdownFilesInDir(dirName: string): AbsoluteFilePath[] {
  const files = glob.sync(`${dirName}/**/*.md`)
  return files
    .filter(file => !file.includes('node_modules'))
    .sort()
    .map(file => new AbsoluteFilePath(file))
}
Ejemplo n.º 8
0
const findCoverFile = (dirname: string): string => {
  const preferredFilenames = [
    'cover.jpg',
    'cover.jpeg',
    'folder.jpg',
    'folder.jpeg',
    'front.jpg',
    'front.jpeg'
  ];

  const filepaths = glob.sync('**/*.{jpeg,jpg}', { cwd: dirname });

  let found;

  for (const filepath of filepaths) {
    const base = path.basename(filepath).toLowerCase();
    if (preferredFilenames.indexOf(path.basename(base)) > -1) {
      found = filepath;
    }

    if (found) {
      continue;
    }

    found = filepath;
  }

  if (found) {
    const resolved = path.resolve(dirname, found);
    log.debug('Found cover art file: %s', resolved);
    return resolved;
  }

  return '';
};
Ejemplo n.º 9
0
describe('full repo', () => {
	if (!fs.existsSync(repoDir)) {
		return;
	}

	let files = glob.sync('types/*/index.d.ts', {
		cwd: repoDir
	});

	files.sort();

	files.forEach((file) => {
		let targetPath = path.join(repoDir, file);

		it(file, () => {
			let sourceData = fs.readFileSync(targetPath, {encoding: 'utf8'});
			let result = DH.parse(sourceData);
			if (!result.success) {
				if (DH.isPartial(sourceData)) {
					return;
				}
				console.log(DH.utils.linkPos(targetPath, result.line, result.column));
				console.log('\n' + result.details + '\n');
			}
			assert.isTrue(result.success, result.message);
		});
	});
});
Ejemplo n.º 10
0
        >((agg, thresholdGroup) => {
          const absoluteThresholdGroup = path.resolve(thresholdGroup);

          // The threshold group might be a path:

          if (file.indexOf(absoluteThresholdGroup) === 0) {
            groupTypeByThresholdGroup[thresholdGroup] =
              THRESHOLD_GROUP_TYPES.PATH;
            return agg.concat([[file, thresholdGroup]]);
          }

          // If the threshold group is not a path it might be a glob:

          // Note: glob.sync is slow. By memoizing the files matching each glob
          // (rather than recalculating it for each covered file) we save a tonne
          // of execution time.
          if (filesByGlob[absoluteThresholdGroup] === undefined) {
            filesByGlob[absoluteThresholdGroup] = glob
              .sync(absoluteThresholdGroup)
              .map(filePath => path.resolve(filePath));
          }

          if (filesByGlob[absoluteThresholdGroup].indexOf(file) > -1) {
            groupTypeByThresholdGroup[thresholdGroup] =
              THRESHOLD_GROUP_TYPES.GLOB;
            return agg.concat([[file, thresholdGroup]]);
          }

          return agg;
        }, []);