diff --git a/jest.config.js b/jest.config.js index 32a0d75..70071f8 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,6 +1,3 @@ -module.exports = { - projects: [ - '/packages/plugin-tools', - '/e2e/plugin-tools-e2e', - ], -}; +const { getJestProjects } = require('@nrwl/jest'); + +module.exports = { projects: [...getJestProjects(), '/e2e/plugin-tools-e2e'] }; diff --git a/package.json b/package.json index 50239d1..29b53be 100644 --- a/package.json +++ b/package.json @@ -35,19 +35,19 @@ "tslib": "^2.0.0" }, "devDependencies": { - "@nrwl/cli": "12.5.9", - "@nrwl/devkit": "12.5.9", - "@nrwl/eslint-plugin-nx": "12.5.9", - "@nrwl/jest": "12.5.9", - "@nrwl/linter": "12.5.9", - "@nrwl/node": "12.5.9", - "@nrwl/nx-plugin": "12.5.9", - "@nrwl/tao": "12.5.9", - "@nrwl/workspace": "12.5.9", + "@nrwl/cli": "12.6.6", + "@nrwl/devkit": "12.6.6", + "@nrwl/eslint-plugin-nx": "12.6.6", + "@nrwl/jest": "12.6.6", + "@nrwl/linter": "12.6.6", + "@nrwl/node": "12.6.6", + "@nrwl/nx-plugin": "12.6.6", + "@nrwl/tao": "12.6.6", + "@nrwl/workspace": "12.6.6", "@types/jest": "26.0.8", "@types/node": "14.14.33", - "@typescript-eslint/eslint-plugin": "4.19.0", - "@typescript-eslint/parser": "4.19.0", + "@typescript-eslint/eslint-plugin": "4.28.5", + "@typescript-eslint/parser": "4.28.5", "conventional-changelog-cli": "~2.1.0", "dotenv": "8.2.0", "eslint": "7.22.0", @@ -61,7 +61,7 @@ "ts-jest": "27.0.3", "ts-node": "~9.1.1", "tslib": "^2.0.0", - "typescript": "~4.2.4" + "typescript": "4.3.5" }, "lint-staged": { "**/*.{js,ts,scss,json,html}": [ diff --git a/packages/plugin-tools/migrations.json b/packages/plugin-tools/migrations.json index f1e1966..118f6d1 100644 --- a/packages/plugin-tools/migrations.json +++ b/packages/plugin-tools/migrations.json @@ -1,19 +1,28 @@ { "schematics": { "update-to-1.0.6": { + "cli": "nx", "version": "1.0.6", "description": "Migrate tools to 1.0.6", "factory": "./src/migrations/update-1-0-6/update-1-0-6" }, "update-to-1.1.0": { + "cli": "nx", "version": "1.1.0", "description": "Migrate tools to 1.1.0", "factory": "./src/migrations/update-1-1-0/update-1-1-0" }, "update-to-2.0.0": { + "cli": "nx", "version": "2.0.0", "description": "Migrate tools to 2.0.0", "factory": "./src/migrations/update-2-0-0/update-2-0-0" + }, + "update-to-2.1.0": { + "cli": "nx", + "version": "2.1.0", + "description": "Migrate tools to 2.1.0", + "factory": "./src/migrations/update-2-1-0/update-2-1-0" } } } diff --git a/packages/plugin-tools/package.json b/packages/plugin-tools/package.json index 6b9c671..0ee2ccc 100644 --- a/packages/plugin-tools/package.json +++ b/packages/plugin-tools/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/plugin-tools", - "version": "2.0.7", + "version": "2.1.0", "description": "NativeScript plugin tooling for workspaces", "homepage": "https://nativescript.org", "repository": { @@ -29,30 +29,29 @@ "dependencies": { "xml2js": "~0.4.23", "@nativescript/nx": "^2.0.0", - "@nrwl/devkit": "12.5.9", - "@nrwl/eslint-plugin-nx": "12.5.9", - "@nrwl/jest": "12.5.9", - "@nrwl/node": "12.5.9", - "@nrwl/workspace": "12.5.9", + "@nrwl/devkit": "12.6.6", + "@nrwl/eslint-plugin-nx": "12.6.6", + "@nrwl/jest": "12.6.6", + "@nrwl/node": "12.6.6", + "@nrwl/workspace": "12.6.6", "@nstudio/focus": "^12.5.0", "@nstudio/nps-i": "^1.1.0", - "@types/jest": "~26.0.10", - "@types/node": "14.14.37", - "dotenv": "~8.2.0", + "@types/jest": "26.0.8", + "@types/node": "14.14.33", + "dotenv": "8.2.0", "husky": "^5.1.3", - "jest": "~26.5.2", + "jest": "27.0.3", "jsonc-parser": "3.0.0", "lint-staged": "^11.0.0", "nativescript-permissions": "^1.3.9", "nativescript-theme-core": "~1.0.4", "sass": "^1.35.0", "parse-version-string": "^1.0.1", - "prettier": "~2.3.0", + "prettier": "^2.3.0", "pretty-data": "^0.40.0", "rimraf": "^3.0.2", "ts-jest": "27.0.3", "ts-node": "~9.1.0", - "ts-patch": "^1.3.0", - "tslint": "~6.1.2" + "ts-patch": "^1.3.0" } } diff --git a/packages/plugin-tools/src/generators/add-angular/files/index.ts__tmpl__ b/packages/plugin-tools/src/generators/add-angular/files/index.ts__tmpl__ index c9063af..df9ea8a 100644 --- a/packages/plugin-tools/src/generators/add-angular/files/index.ts__tmpl__ +++ b/packages/plugin-tools/src/generators/add-angular/files/index.ts__tmpl__ @@ -1,6 +1,6 @@ import { NgModule } from '@angular/core'; import { registerElement } from '@nativescript/angular'; -import { <%= stringUtils.classify(name) %> } from '<%= npmScope %>/<%= name %>'; +import { <%= stringUtils.classify(name) %> } from '<%= npmPackageName %>'; @NgModule() export class NativeScript<%= stringUtils.classify(name) %>Module {} diff --git a/packages/plugin-tools/src/generators/add-angular/files/package.json b/packages/plugin-tools/src/generators/add-angular/files/package.json index ca7957c..380241f 100644 --- a/packages/plugin-tools/src/generators/add-angular/files/package.json +++ b/packages/plugin-tools/src/generators/add-angular/files/package.json @@ -1,12 +1,12 @@ { - "name": "<%= nxNpmScope %>-<%= name %>-angular", + "name": "<%= npmPackageName %>-angular", "ngPackage": { "lib": { "entryFile": "index.ts", "umdModuleIds": { "@nativescript/core": "ns-core", "@nativescript/angular": "ns-angular", - "<%= npmScope %>/<%= name %>": "ns-<%= name %>" + "<%= npmPackageName %>": "ns-<%= name %>" } }, "allowedNonPeerDependencies": [ diff --git a/packages/plugin-tools/src/generators/add-angular/files/tsconfig.angular.json b/packages/plugin-tools/src/generators/add-angular/files/tsconfig.angular.json index a3c8a0f..64fa5d3 100644 --- a/packages/plugin-tools/src/generators/add-angular/files/tsconfig.angular.json +++ b/packages/plugin-tools/src/generators/add-angular/files/tsconfig.angular.json @@ -4,7 +4,7 @@ "types": ["node"], "baseUrl": ".", "paths": { - "<%= npmScope %>/<%= name %>": ["../../../dist/packages/<%= name %>"] + "<%= npmPackageName %>": ["../../../dist/packages/<%= name %>"] } } } diff --git a/packages/plugin-tools/src/generators/add-angular/index.ts b/packages/plugin-tools/src/generators/add-angular/index.ts index ba141bd..52e5aa0 100644 --- a/packages/plugin-tools/src/generators/add-angular/index.ts +++ b/packages/plugin-tools/src/generators/add-angular/index.ts @@ -1,19 +1,23 @@ -import { generateFiles, joinPathFragments, Tree } from '@nrwl/devkit'; +import { generateFiles, joinPathFragments, readJson, Tree } from '@nrwl/devkit'; import { stringUtils } from '@nrwl/workspace'; import { prerun, getNpmScope, getNxNpmScope } from '../../utils'; import { Schema } from './schema'; let name: string; +let npmPackageName: string; export default async function (tree: Tree, schema: Schema) { name = stringUtils.dasherize(schema.name.toLowerCase()); prerun(tree); addAngularFiles(tree); - console.log(`Angular support added for "${getNpmScope()}/${name}". Continue developing the Angular support in the packages/${name}/angular folder.`); + console.log(`Angular support added for "${npmPackageName}". Continue developing the Angular support in the packages/${name}/angular folder.`); } function addAngularFiles(tree: Tree) { console.log(`Adding Angular support to ${name}...`); - generateFiles(tree, joinPathFragments(__dirname, 'files'), `./packages/${name}/angular`, { name, npmScope: getNpmScope(), nxNpmScope: getNxNpmScope(), stringUtils, tmpl: '', dot: '.' }); + const packageJson = readJson(tree, `packages/${name}/package.json`); + npmPackageName = packageJson.name; + + generateFiles(tree, joinPathFragments(__dirname, 'files'), `./packages/${name}/angular`, { name, npmPackageName, npmScope: getNpmScope(), nxNpmScope: getNxNpmScope(), stringUtils, tmpl: '', dot: '.' }); } diff --git a/packages/plugin-tools/src/generators/add-package/files/README.md b/packages/plugin-tools/src/generators/add-package/files/README.md index 2f5fa7d..51444fc 100644 --- a/packages/plugin-tools/src/generators/add-package/files/README.md +++ b/packages/plugin-tools/src/generators/add-package/files/README.md @@ -1,7 +1,7 @@ -# <%= npmScope %>/<%= name %> +# <%= npmPackageName %> ```javascript -ns plugin add <%= npmScope %>/<%= name %> +ns plugin add <%= npmPackageName %> ``` ## Usage diff --git a/packages/plugin-tools/src/generators/add-package/files/package.json b/packages/plugin-tools/src/generators/add-package/files/package.json index 76d8f62..0ecfc08 100644 --- a/packages/plugin-tools/src/generators/add-package/files/package.json +++ b/packages/plugin-tools/src/generators/add-package/files/package.json @@ -1,5 +1,5 @@ { - "name": "<%= npmScope %>/<%= name %>", + "name": "<%= npmPackageName %>", "version": "1.0.0", "description": "Add a plugin description", "main": "index", diff --git a/packages/plugin-tools/src/generators/add-package/index.ts b/packages/plugin-tools/src/generators/add-package/index.ts index a116453..250b2a7 100644 --- a/packages/plugin-tools/src/generators/add-package/index.ts +++ b/packages/plugin-tools/src/generators/add-package/index.ts @@ -5,9 +5,11 @@ import syncPackagesWithDemos from '../sync-packages-with-demos'; import { Schema } from './schema'; let name: string; +let npmPackageName: string; export default async function (tree: Tree, schema: Schema) { name = stringUtils.dasherize(schema.name); prerun(tree); + npmPackageName = schema.isScoped ? `${getNpmScope()}/${name}` : name; addPackageFiles(tree); addProjectToNxJsonInTree(name, {}); updateWorkspaceConfig(tree); @@ -22,11 +24,11 @@ export default async function (tree: Tree, schema: Schema) { true ); - console.log(`"${getNpmScope()}/${name}" created and added to all demo apps. Ready to develop!`); + console.log(`"${npmPackageName}" created and added to all demo apps. Ready to develop!`); } function addPackageFiles(tree: Tree) { - generateFiles(tree, joinPathFragments(__dirname, 'files'), `./packages/${name}`, { name, npmScope: getNpmScope(), stringUtils, tmpl: '', dot: '.' }); + generateFiles(tree, joinPathFragments(__dirname, 'files'), `./packages/${name}`, { name, npmPackageName, npmScope: getNpmScope(), stringUtils, tmpl: '', dot: '.' }); } function updateWorkspaceConfig(tree: Tree) { @@ -103,11 +105,11 @@ function updateWorkspaceScripts(tree: Tree) { const buildSectionIndex = workspaceScripts.indexOf(`'build-all':`); const buildStart = workspaceScripts.substring(0, buildSectionIndex); const buildEnd = workspaceScripts.substring(buildSectionIndex, workspaceScripts.length); - const newBuild = `// ${getNpmScope()}/${name} + const newBuild = `// ${npmPackageName} '${name}': { build: { script: 'nx run ${name}:build.all', - description: '${getNpmScope()}/${name}: Build', + description: '${npmPackageName}: Build', }, }, `; @@ -119,7 +121,7 @@ function updateWorkspaceScripts(tree: Tree) { const focusEnd = workspaceScripts.substring(focusSectionIndex, workspaceScripts.length); const newFocus = `'${name}': { script: 'nx run ${name}:focus', - description: 'Focus on ${getNpmScope()}/${name}', + description: 'Focus on ${npmPackageName}', }, `; workspaceScripts = `${focusStart}${newFocus} ${focusEnd}`; diff --git a/packages/plugin-tools/src/generators/add-package/schema.d.ts b/packages/plugin-tools/src/generators/add-package/schema.d.ts index 995dbae..e300faa 100644 --- a/packages/plugin-tools/src/generators/add-package/schema.d.ts +++ b/packages/plugin-tools/src/generators/add-package/schema.d.ts @@ -1,3 +1,4 @@ export interface Schema { name: string; + isScoped?: boolean; } diff --git a/packages/plugin-tools/src/generators/add-package/schema.json b/packages/plugin-tools/src/generators/add-package/schema.json index 78bc8e0..b80b28f 100644 --- a/packages/plugin-tools/src/generators/add-package/schema.json +++ b/packages/plugin-tools/src/generators/add-package/schema.json @@ -13,6 +13,12 @@ "index": 0 }, "x-prompt": "What should the new package be named?" + }, + "isScoped": { + "type": "boolean", + "default": true, + "description": "Whether the new package should be scoped to the npm scope of the workspace or not.", + "x-prompt": "Should it use the npm scope of the workspace? 'Y' is the most common. This is the difference between, for example @nativescript/camera vs. nativescript-camera. If you choose 'N' here, be sure you have specified the full npm name you would like to use during publishing." } }, "required": ["name"] diff --git a/packages/plugin-tools/src/generators/config/schema.json b/packages/plugin-tools/src/generators/config/schema.json index 6734e24..928e8d2 100644 --- a/packages/plugin-tools/src/generators/config/schema.json +++ b/packages/plugin-tools/src/generators/config/schema.json @@ -12,7 +12,7 @@ "$source": "argv", "index": 0 }, - "x-prompt": "What npm scope would you like to use for this workspace?" + "x-prompt": "What npm scope would you like to use for this workspace? This will become the default npm scope of the workspace however you can add packages that are non-scoped at anytime via 'npm run add'" } } } diff --git a/packages/plugin-tools/src/generators/focus-packages/index.ts b/packages/plugin-tools/src/generators/focus-packages/index.ts index a1715b0..3fcb8b3 100644 --- a/packages/plugin-tools/src/generators/focus-packages/index.ts +++ b/packages/plugin-tools/src/generators/focus-packages/index.ts @@ -1,4 +1,4 @@ -import { sanitizeCollectionArgs, getDemoTypeFromName, updateDemoDependencies, setPackageNamesToUpdate, getAllPackages, resetIndexForDemoType, getPluginDemoPath, updateDemoSharedIndex, getNpmScope, prerun } from '../../utils'; +import { sanitizeCollectionArgs, getDemoTypeFromName, updateDemoDependencies, setPackageNamesToUpdate, getAllPackages, resetIndexForDemoType, getPluginDemoPath, updateDemoSharedIndex, getNpmScope, prerun, getNpmPackageNames } from '../../utils'; import { Schema } from './schema'; import { wrapAngularDevkitSchematic } from '@nrwl/devkit/ngcli-adapter'; import { Tree } from '@nrwl/devkit'; @@ -14,17 +14,16 @@ export default async function (tree: Tree, schema: Schema) { await nstudioFocus(tree, { name: schema.name, }); + setPackageNamesToUpdate(focusPackages); + allPackages = getAllPackages(tree); + const npmPackageNames = getNpmPackageNames(); + // console.log('allPackages:', allPackages); // Isolate code in demo apps by default based on focus if (!schema.ignoreDemos) { - setPackageNamesToUpdate(focusPackages); - allPackages = getAllPackages(tree); - // console.log('allPackages:', allPackages); - // adjust demo shared index for focusing updateDemoSharedIndex(tree, allPackages, focusPackages); // apps - const appFolders = tree.children('apps'); for (const dir of appFolders) { // console.log(`demoAppRoot: ${demoAppRoot}`); @@ -72,7 +71,7 @@ export default async function (tree: Tree, schema: Schema) { } const isFocusing = focusPackages && focusPackages.length > 0; - const focusTargets = (focusPackages && focusPackages.length ? focusPackages : allPackages).map((n) => `\n${getNpmScope()}/${n}`).join(''); + const focusTargets = (focusPackages && focusPackages.length ? focusPackages : allPackages).map((n) => `\n${npmPackageNames[n]}`).join(''); console.log(`${isFocusing ? 'Focusing workspace on:' : 'Resetting workspace for:'}\n${focusTargets}\n\n`); if (!schema.ignoreDemos) { console.log(` > NOTE: Clean the demo app you plan to test with before running now that the demo code has been updated.\n`); diff --git a/packages/plugin-tools/src/generators/remove-package/index.ts b/packages/plugin-tools/src/generators/remove-package/index.ts index 028fa0d..cb8a21f 100644 --- a/packages/plugin-tools/src/generators/remove-package/index.ts +++ b/packages/plugin-tools/src/generators/remove-package/index.ts @@ -1,31 +1,39 @@ -import { Tree, removeProjectConfiguration, updateJson, readProjectConfiguration, updateProjectConfiguration } from '@nrwl/devkit'; +import { Tree, removeProjectConfiguration, updateJson, readProjectConfiguration, updateProjectConfiguration, readJson } from '@nrwl/devkit'; import { stringUtils } from '@nrwl/workspace'; -import { prerun, getNpmScope, getDemoTypes, getDemoAppRoot, getPluginDemoPath, SupportedDemoType, checkPackages, getDemoIndexPathForType, getPackageNamesToUpdate, getPathToPackageForDemo, updateReadMe } from '../../utils'; +import { prerun, getNpmScope, getDemoTypes, getDemoAppRoot, getPluginDemoPath, SupportedDemoType, checkPackages, getDemoIndexPathForType, getPackageNamesToUpdate, getPathToPackageForDemo, updateReadMe, getNpmPackageNames } from '../../utils'; import { Schema } from './schema'; let name: string; +let npmPackageName: string; export default function (tree: Tree, schema: Schema) { name = stringUtils.dasherize(schema.name); prerun(tree); - removePackage(tree); - - removeProjectConfiguration(tree, name); - removeFromBuildAll(tree); - - updateReadMe(tree, getUpdatedPackages(tree)); - - for (const t of getDemoTypes()) { - const demoAppRoot = getDemoAppRoot(t); - removeDemoFiles(tree, t, demoAppRoot); - removeFromDemoIndex(tree, t, demoAppRoot); - updateDemoDependencies(tree, demoAppRoot); + const packagePath = `packages/${name}/package.json`; + if (tree.exists(packagePath)) { + const packageJson = readJson(tree, packagePath); + npmPackageName = packageJson.name; + removePackage(tree); + + removeProjectConfiguration(tree, name); + removeFromBuildAll(tree); + + updateReadMe(tree, getUpdatedPackages(tree)); + + for (const t of getDemoTypes()) { + const demoAppRoot = getDemoAppRoot(t); + removeDemoFiles(tree, t, demoAppRoot); + removeFromDemoIndex(tree, t, demoAppRoot); + updateDemoDependencies(tree, demoAppRoot); + } + + removeSharedDemoFiles(tree); + updateDemoSharedIndex(tree); + + console.log(`"${npmPackageName}" removed from 'packages' and removed from all demo apps.`); + } else { + console.error(`Nothing found at 'packages/${name}/package.json' to remove.`) } - - removeSharedDemoFiles(tree); - updateDemoSharedIndex(tree); - - console.log(`"${getNpmScope()}/${name}" removed from 'packages' and removed from all demo apps.`); } function removePackage(tree: Tree) { @@ -165,7 +173,7 @@ export function updateDemoDependencies(tree: Tree, demoAppRoot: string) { updateJson(tree, packagePath, (json) => { json.dependencies = json.dependencies || {}; - delete json.dependencies[`${getNpmScope()}/${name}`]; + delete json.dependencies[npmPackageName]; return json; }); } diff --git a/packages/plugin-tools/src/generators/sync-packages-with-demos/files_angular/__name__.component.ts__tmpl__ b/packages/plugin-tools/src/generators/sync-packages-with-demos/files_angular/__name__.component.ts__tmpl__ index e657dd8..535f789 100644 --- a/packages/plugin-tools/src/generators/sync-packages-with-demos/files_angular/__name__.component.ts__tmpl__ +++ b/packages/plugin-tools/src/generators/sync-packages-with-demos/files_angular/__name__.component.ts__tmpl__ @@ -1,6 +1,6 @@ import { Component, NgZone } from '@angular/core'; import { DemoShared<%= stringUtils.classify(name) %> } from '@demo/shared'; -import { } from '<%= npmScope %>/<%= name %>'; +import { } from '<%= npmPackageName %>'; @Component({ selector: 'demo-<%= name %>', diff --git a/packages/plugin-tools/src/generators/sync-packages-with-demos/files_demo_shared/__name__/index.ts__tmpl__ b/packages/plugin-tools/src/generators/sync-packages-with-demos/files_demo_shared/__name__/index.ts__tmpl__ index 9182852..a5f71ea 100644 --- a/packages/plugin-tools/src/generators/sync-packages-with-demos/files_demo_shared/__name__/index.ts__tmpl__ +++ b/packages/plugin-tools/src/generators/sync-packages-with-demos/files_demo_shared/__name__/index.ts__tmpl__ @@ -1,5 +1,5 @@ import { DemoSharedBase } from '../utils'; -import { } from '<%= npmScope %>/<%= name %>'; +import { } from '<%= npmPackageName %>'; export class DemoShared<%= stringUtils.classify(name) %> extends DemoSharedBase { diff --git a/packages/plugin-tools/src/generators/sync-packages-with-demos/files_react/__name__.tsx__tmpl__ b/packages/plugin-tools/src/generators/sync-packages-with-demos/files_react/__name__.tsx__tmpl__ index 1cc9ad9..b6ee9c3 100644 --- a/packages/plugin-tools/src/generators/sync-packages-with-demos/files_react/__name__.tsx__tmpl__ +++ b/packages/plugin-tools/src/generators/sync-packages-with-demos/files_react/__name__.tsx__tmpl__ @@ -2,7 +2,7 @@ import * as React from "react"; import { Dialogs } from '@nativescript/core'; import { StyleSheet } from "react-nativescript"; import { DemoShared<%= stringUtils.classify(name) %> } from '@demo/shared'; -import { } from '<%= npmScope %>/<%= name %>'; +import { } from '<%= npmPackageName %>'; export function HomeScreen() { return ( diff --git a/packages/plugin-tools/src/generators/sync-packages-with-demos/files_svelte/__name__.svelte__tmpl__ b/packages/plugin-tools/src/generators/sync-packages-with-demos/files_svelte/__name__.svelte__tmpl__ index 440c11b..9ddfa5b 100644 --- a/packages/plugin-tools/src/generators/sync-packages-with-demos/files_svelte/__name__.svelte__tmpl__ +++ b/packages/plugin-tools/src/generators/sync-packages-with-demos/files_svelte/__name__.svelte__tmpl__ @@ -7,7 +7,7 @@ diff --git a/packages/plugin-tools/src/generators/sync-packages-with-demos/files_vue/__name__.vue__tmpl__ b/packages/plugin-tools/src/generators/sync-packages-with-demos/files_vue/__name__.vue__tmpl__ index 50e934b..4a83e26 100644 --- a/packages/plugin-tools/src/generators/sync-packages-with-demos/files_vue/__name__.vue__tmpl__ +++ b/packages/plugin-tools/src/generators/sync-packages-with-demos/files_vue/__name__.vue__tmpl__ @@ -13,7 +13,7 @@