How to use the just-task.resolveCwd function in just-task

To help you get started, we’ve selected a few just-task 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 microsoft / just / packages / just-stack-web-lib / src / copy.ts View on Github external
function expandSourcePath(pattern) {
  if (!pattern) {
    return null;
  }

  // just returns the relative paths
  if (pattern.startsWith('.')) {
    return pattern;
  }

  // tries to resolve the packages, handling scoped packages
  const splitPattern = pattern.split('/');
  const packageName = pattern[0] == '@' ? `${splitPattern[0]}/${splitPattern[1]}` : splitPattern[0];

  try {
    const resolvedPackageJson = resolveCwd(`${packageName}/package.json`);

    if (!resolvedPackageJson) {
      // returns pattern if the packageName didn't contain a package.json (not really a package)
      return pattern;
    }

    return pattern.replace(packageName, path.dirname(resolvedPackageJson));
  } catch (e) {
    console.error(e);
  }
}
github microsoft / just / packages / just-scripts / src / tasks / tscTask.ts View on Github external
export function tscTask(options: TscTaskOptions): TaskFunction {
  const tsConfigFile = resolveCwd('./tsconfig.json');
  const tscCmd = resolve('typescript/lib/tsc.js');

  if (!tscCmd) {
    throw new Error('cannot find tsc');
  }

  return function tsc() {
    // Read from options argument, if not there try the tsConfigFile found in root, if not then skip and use no config
    options.project = (options && options.project) || tsConfigFile || undefined;

    if (options.project && fs.existsSync(options.project as string)) {
      logger.info(`Running ${tscCmd} with ${options.project}`);

      const args = Object.keys(options).reduce(
        (args, option) => {
          if (typeof options[option] === 'string') {
github microsoft / just / packages / just-task-preset / src / outdatedTask.ts View on Github external
return async function outdated() {
    logger.info(`Fetching Outdated Dependency Versions`);

    if (options.versionSpec) {
      const versionInfo = await fetchVersions(options.versionSpec);
      const updateVersions = getUpdateVersions(options.versionSpec, versionInfo);
      const packageJsonFile = resolveCwd('./package.json', path.dirname(resolve('./just-task.js')!));

      console.log(packageJsonFile);

      if (packageJsonFile) {
        const packageJson = JSON.parse(fs.readFileSync(packageJsonFile).toString());

        if (Object.keys(updateVersions).length > 0) {
          Object.keys(updateVersions).forEach(name => {
            if (packageJson.devDependencies && packageJson.devDependencies[name]) {
              packageJson.devDependencies[name] = getPackageVersionSpec(packageJson.devDependencies[name], updateVersions[name]);
              logger.info(`  ${chalk.cyan(name)} updated to '${chalk.yellow(updateVersions[name])}' (devDependencies)`);
            } else {
              packageJson.dependencies = packageJson.dependencies || {};

              console.log(packageJson);
github microsoft / just / packages / just-scripts / src / tasks / eslintTask.ts View on Github external
return function eslint() {
    const { files, configPath, ignorePath, fix, extensions, noEslintRc, maxWarnings, resolvePluginsPath } = options;
    const eslintCmd = resolve('eslint/bin/eslint.js');
    const eslintConfigPath = configPath || resolveCwd('.eslintrc');
    if (eslintCmd && eslintConfigPath && fs.existsSync(eslintConfigPath)) {
      const eslintIgnorePath = ignorePath || resolveCwd('.eslintignore');

      const eslintArgs = [
        eslintCmd,
        ...(files ? files : ['.']),
        ...['--ext', extensions ? extensions : '.js,.jsx,.ts,.tsx'],
        ...(noEslintRc ? '--no-eslintrc' : []),
        ...(eslintConfigPath ? ['--config', eslintConfigPath] : []),
        ...(eslintIgnorePath ? ['--ignore-path', eslintIgnorePath] : []),
        ...(resolvePluginsPath ? ['--resolve-plugins-relative-to', resolvePluginsPath] : []),
        ...(fix ? ['--fix'] : []),
        ...(maxWarnings !== undefined ? ['--max-warnings', `${maxWarnings}`] : []),
        '--color'
      ];

      logger.info(encodeArgs(eslintArgs).join(' '));
      return spawn(process.execPath, eslintArgs, { stdio: 'inherit' });
github microsoft / just / packages / just-scripts / src / tasks / sassTask.ts View on Github external
function requireResolvePackageUrl(packageUrl: string) {
  const fullName = packageUrl + (packageUrl.endsWith('.scss') ? '' : '.scss');
  return resolveCwd(fullName) || resolveCwd(path.join(path.dirname(fullName), `_${path.basename(fullName)}`));
}
github microsoft / just / packages / just-scripts / src / tasks / jestTask.ts View on Github external
export function jestTask(options: JestTaskOptions = {}): TaskFunction {
  const jestConfigFile = resolveCwd('./jest.config.js');

  return function jest() {
    const jestCmd = resolve('jest/bin/jest.js');
    const configFile = options.config || jestConfigFile;

    if (configFile && jestCmd && existsSync(configFile)) {
      logger.info(`Running Jest`);
      const cmd = process.execPath;
      const args = [
        ...(options.nodeArgs || []),
        jestCmd,
        '--config',
        configFile,
        ...(options.passWithNoTests ? ['--passWithNoTests'] : []),
        ...(options.colors !== false && supportsColor.stdout ? ['--colors'] : []),
        ...(options.runInBand ? ['--runInBand'] : []),
github microsoft / just / packages / just-scripts / src / tasks / webpackTask.ts View on Github external
export function webpackDevServerTask(options: WebpackTaskOptions = {}) {
  const configPath = resolveCwd((options && options.config) || 'webpack.serve.config.js');
  const devServerCmd = resolve('webpack-dev-server/bin/webpack-dev-server.js');

  return function webpackDevServer() {
    if (devServerCmd && configPath && fs.existsSync(configPath)) {
      const mode = options.mode || 'development';
      const args = [...(options.nodeArgs || []), devServerCmd, '--config', configPath, '--open', '--mode', mode];

      logger.info(devServerCmd, encodeArgs(args).join(' '));
      return spawn(process.execPath, args, { stdio: 'inherit' });
    } else {
      logger.warn('no webpack.serve.config.js configuration found, skipping');
      return Promise.resolve();
    }
  };
}
github microsoft / just / packages / just-scripts / src / tasks / eslintTask.ts View on Github external
return function eslint() {
    const { files, configPath, ignorePath, fix, extensions, noEslintRc, maxWarnings, resolvePluginsPath } = options;
    const eslintCmd = resolve('eslint/bin/eslint.js');
    const eslintConfigPath = configPath || resolveCwd('.eslintrc');
    if (eslintCmd && eslintConfigPath && fs.existsSync(eslintConfigPath)) {
      const eslintIgnorePath = ignorePath || resolveCwd('.eslintignore');

      const eslintArgs = [
        eslintCmd,
        ...(files ? files : ['.']),
        ...['--ext', extensions ? extensions : '.js,.jsx,.ts,.tsx'],
        ...(noEslintRc ? '--no-eslintrc' : []),
        ...(eslintConfigPath ? ['--config', eslintConfigPath] : []),
        ...(eslintIgnorePath ? ['--ignore-path', eslintIgnorePath] : []),
        ...(resolvePluginsPath ? ['--resolve-plugins-relative-to', resolvePluginsPath] : []),
        ...(fix ? ['--fix'] : []),
        ...(maxWarnings !== undefined ? ['--max-warnings', `${maxWarnings}`] : []),
        '--color'
      ];