Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
module.exports = {
projects: [
'<rootDir>/packages/plugin-tools',
'<rootDir>/e2e/plugin-tools-e2e',
],
};
const { getJestProjects } = require('@nrwl/jest');

module.exports = { projects: [...getJestProjects(), '<rootDir>/e2e/plugin-tools-e2e'] };
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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}": [
Expand Down
9 changes: 9 additions & 0 deletions packages/plugin-tools/migrations.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Expand Down
25 changes: 12 additions & 13 deletions packages/plugin-tools/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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 {}
Expand Down
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"types": ["node"],
"baseUrl": ".",
"paths": {
"<%= npmScope %>/<%= name %>": ["../../../dist/packages/<%= name %>"]
"<%= npmPackageName %>": ["../../../dist/packages/<%= name %>"]
}
}
}
10 changes: 7 additions & 3 deletions packages/plugin-tools/src/generators/add-angular/index.ts
Original file line number Diff line number Diff line change
@@ -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: '.' });
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# <%= npmScope %>/<%= name %>
# <%= npmPackageName %>

```javascript
ns plugin add <%= npmScope %>/<%= name %>
ns plugin add <%= npmPackageName %>
```

## Usage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "<%= npmScope %>/<%= name %>",
"name": "<%= npmPackageName %>",
"version": "1.0.0",
"description": "Add a plugin description",
"main": "index",
Expand Down
12 changes: 7 additions & 5 deletions packages/plugin-tools/src/generators/add-package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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',
},
},
`;
Expand All @@ -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}`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export interface Schema {
name: string;
isScoped?: boolean;
}
6 changes: 6 additions & 0 deletions packages/plugin-tools/src/generators/add-package/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-tools/src/generators/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
}
}
}
13 changes: 6 additions & 7 deletions packages/plugin-tools/src/generators/focus-packages/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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}`);
Expand Down Expand Up @@ -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`);
Expand Down
48 changes: 28 additions & 20 deletions packages/plugin-tools/src/generators/remove-package/index.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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;
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 %>',
Expand Down
Loading