|  | 
|  | 1 | +import { appendFile } from 'node:fs/promises'; | 
|  | 2 | +import { getGlobalVariable } from '../../utils/env'; | 
|  | 3 | +import { getActivePackageManager, installWorkspacePackages } from '../../utils/packages'; | 
|  | 4 | +import { ng } from '../../utils/process'; | 
|  | 5 | +import { isPrereleaseCli, updateJsonFile } from '../../utils/project'; | 
|  | 6 | +import { expectToFail } from '../../utils/utils'; | 
|  | 7 | + | 
|  | 8 | +const snapshots = require('../../ng-snapshot/package.json'); | 
|  | 9 | + | 
|  | 10 | +export default async function () { | 
|  | 11 | +  const isPrerelease = await isPrereleaseCli(); | 
|  | 12 | +  let tag = isPrerelease ? '@next' : ''; | 
|  | 13 | +  if (getActivePackageManager() === 'npm') { | 
|  | 14 | +    await appendFile('.npmrc', '\nlegacy-peer-deps=true'); | 
|  | 15 | +  } | 
|  | 16 | + | 
|  | 17 | +  await ng('add', `@angular/material${tag}`, '--skip-confirmation'); | 
|  | 18 | + | 
|  | 19 | +  const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots']; | 
|  | 20 | +  if (isSnapshotBuild) { | 
|  | 21 | +    await updateJsonFile('package.json', (packageJson) => { | 
|  | 22 | +      const dependencies = packageJson['dependencies']; | 
|  | 23 | +      // Angular material adds dependencies on other Angular packages | 
|  | 24 | +      // Iterate over all of the packages to update them to the snapshot version. | 
|  | 25 | +      for (const [name, version] of Object.entries(snapshots.dependencies)) { | 
|  | 26 | +        if (name in dependencies) { | 
|  | 27 | +          dependencies[name] = version; | 
|  | 28 | +        } | 
|  | 29 | +      } | 
|  | 30 | +    }); | 
|  | 31 | +    await installWorkspacePackages(); | 
|  | 32 | +  } | 
|  | 33 | + | 
|  | 34 | +  const args: string[] = [ | 
|  | 35 | +    'generate', | 
|  | 36 | +    '@angular/material:theme-color', | 
|  | 37 | +    '--primary-color=#0641e6', | 
|  | 38 | +    '--tertiary-color=#994aff', | 
|  | 39 | +    '--neutral-color=#313138', | 
|  | 40 | +    '--error-color=#eb5757', | 
|  | 41 | +    '--secondary-color=#009096', | 
|  | 42 | +    '--neutral-variant-color=#b2b2b8', | 
|  | 43 | +  ]; | 
|  | 44 | + | 
|  | 45 | +  await ng(...args); | 
|  | 46 | + | 
|  | 47 | +  // Should fail as file exists | 
|  | 48 | +  await expectToFail(() => ng(...args)); | 
|  | 49 | + | 
|  | 50 | +  await ng(...args, '--force'); | 
|  | 51 | +} | 
0 commit comments