Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
)
);
// ensure supportFile points to updates
const cypressConfigPath = `/apps/${options.target}-e2e/cypress.json`;
const cypressConfig = getJsonFromFile(tree, cypressConfigPath);
// console.log('cypressConfig:', cypressConfig);
// plugin path is always defined so ensure support matches
const pluginsFilePath = cypressConfig.pluginsFile;
// console.log('pluginsFilePath:', pluginsFilePath);
const outputPath = pluginsFilePath.split('plugins/')[0];
cypressConfig.supportFile = `${outputPath}support/index.js`;
// console.log('cypressConfig.supportFile:', cypressConfig.supportFile);
helperChains.push(updateJsonFile(tree, cypressConfigPath, cypressConfig));
// Add applitools modules
const packageJson = getJsonFromFile(tree, 'package.json');
packageJson.devDependencies = packageJson.devDependencies || {};
packageJson.devDependencies['@applitools/eyes-cypress'] = '^3.7.1';
helperChains.push(updateJsonFile(tree, 'package.json', packageJson));
// update sample test
helperChains.push(
createOrUpdate(
tree,
`/apps/${options.target}-e2e/src/integration/app.spec.ts`,
updateSampleTest()
)
);
};
}
return (tree: Tree, context: SchematicContext) => {
const configPath = getWorkspacePath(tree);
const nxConfigPath = `nx.json`;
const workspaceJson = getJsonFromFile(tree, configPath);
const nxJson = getJsonFromFile(tree, nxConfigPath);
const prefix = getPrefix();
// console.log('prefix:', prefix);
// update libs and xplat config
if (workspaceJson && workspaceJson.projects) {
workspaceJson.projects['libs'] = {
root: 'libs',
sourceRoot: 'libs',
projectType: 'library',
prefix: prefix,
architect: {
test: {
builder: '@angular-devkit/build-angular:karma',
options: {
main: 'testing/test.libs.ts',
if (dir.indexOf('nativescript-') === 0) {
const appDir = `${appsDir.path}/${dir}`;
// console.log('appDir:', appDir);
createOrUpdate(tree, `${appDir}/webpack.config.js`, webpackConfig);
createOrUpdate(
tree,
`${appDir}/app/app.module.ngfactory.d.ts`,
ngAppFactory
);
// update {N} app deps
const packagePath = `${appDir}/package.json`;
const packageJson = getJsonFromFile(tree, packagePath);
if (packageJson) {
packageJson.dependencies = packageJson.dependencies || {};
packageJson.devDependencies = packageJson.devDependencies || {};
packageJson.devDependencies = {
...packageJson.devDependencies,
'@angular/compiler-cli':
'file:../../node_modules/@angular/compiler-cli',
'@angular/language-service':
'file:../../node_modules/@angular/language-service',
'@ngtools/webpack': '6.1.0-beta.1',
'babel-traverse': '6.26.0',
'babel-types': '6.26.0',
babylon: '6.18.0',
'clean-webpack-plugin': '~0.1.19',
codelyzer: 'file:../../node_modules/codelyzer',
function updateIonicApps(tree: Tree, context: SchematicContext) {
const appsDir = tree.getDir('apps');
const appFolders = appsDir.subdirs;
// update Ionic apps and configs
for (const dir of appFolders) {
// console.log(dir);
if (dir.indexOf('ionic-') === 0) {
const appDir = `${appsDir.path}/${dir}`;
// console.log('appDir:', appDir);
// update Ionic app deps
const packagePath = `${appDir}/package.json`;
const packageJson = getJsonFromFile(tree, packagePath);
if (packageJson) {
packageJson.dependencies = packageJson.dependencies || {};
packageJson.dependencies = {
...packageJson.dependencies,
'@capacitor/android': '^1.0.0-beta.3',
'@capacitor/cli': '^1.0.0-beta.3',
'@capacitor/core': '^1.0.0-beta.3',
'@capacitor/ios': '^1.0.0-beta.3'
};
packageJson.devDependencies = packageJson.devDependencies || {};
packageJson.devDependencies = {
...packageJson.devDependencies,
'@angular-devkit/architect': '0.7.2',
'@angular-devkit/build-angular': '0.7.2',
'@angular-devkit/core': '0.7.2',
function updateNativeScriptApps(tree: Tree, context: SchematicContext) {
const angularConfigPath = `angular.json`;
const nxConfigPath = `nx.json`;
const angularJson = getJsonFromFile(tree, angularConfigPath);
const nxJson = getJsonFromFile(tree, nxConfigPath);
const prefix = getPrefix(tree);
const npmScope = nxJson.npmScope;
const appsDir = tree.getDir('apps');
const appFolders = appsDir.subdirs;
// console.log("npmScope:", npmScope);
// console.log("prefix:", prefix);
// update libs and xplat config
if (angularJson && angularJson.projects) {
angularJson.projects['libs'] = {
root: 'libs',
sourceRoot: 'libs',
projectType: 'library',
prefix: prefix,
// console.log('webpackConfigPath:', webpackConfigPath);
const webpackConfig = fs.readFileSync(webpackConfigPath, 'UTF-8');
// update {N} apps and configs
for (const dir of appFolders) {
// console.log(dir);
if (dir.indexOf('nativescript-') === 0) {
const appDir = `${appsDir.path}/${dir}`;
// console.log('appDir:', appDir);
createOrUpdate(tree, `${appDir}/webpack.config.js`, webpackConfig);
// update {N} app deps
const packagePath = `${appDir}/package.json`;
const packageJson = getJsonFromFile(tree, packagePath);
if (packageJson) {
packageJson.dependencies = packageJson.dependencies || {};
packageJson.devDependencies = packageJson.devDependencies || {};
packageJson.devDependencies = {
...packageJson.devDependencies,
'@angular/compiler-cli': '~6.1.1',
'nativescript-dev-webpack': '~0.15.0',
'@ngtools/webpack': '~6.1.1'
};
// console.log('path:',path);
// console.log('packageJson overwrite:', JSON.stringify(packageJson));
tree = updateJsonFile(tree, packagePath, packageJson);
}
}
// update {N} apps and configs
for (const dir of appFolders) {
// console.log(dir);
if (dir.indexOf('nativescript-') === 0) {
const appDir = `${appsDir.path}/${dir}`;
// console.log('appDir:', appDir);
createOrUpdate(tree, `${appDir}/webpack.config.js`, webpackConfig);
createOrUpdate(tree, `${appDir}/app/main.ts`, mainFile);
// update {N} app deps
const packagePath = `${appDir}/package.json`;
const packageJson = getJsonFromFile(tree, packagePath);
if (packageJson) {
packageJson.dependencies = packageJson.dependencies || {};
packageJson.devDependencies = packageJson.devDependencies || {};
packageJson.devDependencies = {
...packageJson.devDependencies,
'@angular/compiler-cli': '~7.0.0',
'@ngtools/webpack': '~7.0.0',
'nativescript-dev-webpack': '~0.18.0'
};
// console.log('path:',path);
// console.log('packageJson overwrite:', JSON.stringify(packageJson));
tree = updateJsonFile(tree, packagePath, packageJson);
}
}
createOrUpdate(tree, `${appDir}/webpack.config.js`, getWebpackConfig());
createOrUpdate(
tree,
`${appDir}/tools/xplat-before-watch.js`,
getxPlatBeforeWatch(npmScope)
);
createOrUpdate(
tree,
`${appDir}/tools/xplat-postinstall.js`,
getxPlatPostinstall()
);
// update {N} app deps
const packagePath = `${appDir}/package.json`;
const packageJson = getJsonFromFile(tree, packagePath);
if (packageJson) {
packageJson.scripts = {
...packageJson.scripts,
postinstall: 'node ./tools/xplat-postinstall.js'
};
packageJson.dependencies = packageJson.dependencies || {};
packageJson.devDependencies = packageJson.devDependencies || {};
packageJson.devDependencies = {
...packageJson.devDependencies,
'@ngtools/webpack': '~6.0.3',
'clean-webpack-plugin': '~0.1.19',
'copy-webpack-plugin': '~4.5.1',
'css-loader': '~0.28.11',
'extract-text-webpack-plugin': '~3.0.2',
'nativescript-css-loader': '~0.26.0',
return (tree: Tree) => {
const platformApp = options.name.replace('-', '.');
let fullTargetAppName = options.target;
let targetAppScript = fullTargetAppName.replace('-', '.');
const packageConfig = getJsonFromFile(tree, 'package.json');
const scripts = packageConfig.scripts || {};
const postinstall = 'electron-rebuild install-app-deps';
if (scripts.postinstall) {
// add to the end of already existing postinstall
scripts['postinstall'] = `${scripts.postinstall} && ${postinstall}`;
} else {
scripts['postinstall'] = postinstall;
}
scripts['postinstall.electron'] = 'node tools/electron/postinstall';
scripts['postinstall.web'] = 'node tools/web/postinstall';
scripts[
`build.${platformApp}`
] = `npm run prepare.${platformApp} && ng build ${options.name} --prod --base-href ./`;
scripts[
`build.${platformApp}.local`
] = `npm run build.${platformApp} && electron dist/apps/${options.name}`;
return (tree: Tree) => {
const packagePath = 'package.json';
const packageJson: {
devDependencies: { [packageName: string]: string };
} = getJsonFromFile(tree, packagePath);
if (!packageJson) {
return tree;
}
packageJson.devDependencies = {
...(packageJson.devDependencies || {}),
nativescript: nsCoreVersion
};
return updateJsonFile(tree, packagePath, packageJson);
};
}