Skip to content

Commit

Permalink
feat(platform): allow nx-plugin to be packaged with @analogjs/platform (
Browse files Browse the repository at this point in the history
  • Loading branch information
goetzrobin authored Mar 31, 2023
1 parent 5a24010 commit c842919
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 30 deletions.
4 changes: 2 additions & 2 deletions apps/nx-plugin-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"e2e": {
"executor": "@nrwl/nx-plugin:e2e",
"options": {
"target": "nx-plugin:build",
"target": "platform:build",
"jestConfig": "apps/nx-plugin-e2e/jest.config.ts",
"coverageDirectory": "../../coverage/apps/nx-plugin-e2e"
}
}
},
"tags": [],
"implicitDependencies": ["nx-plugin"]
"implicitDependencies": ["platform"]
}
21 changes: 11 additions & 10 deletions apps/nx-plugin-e2e/tests/nx-plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ describe('nx-plugin e2e', () => {
// consumes 1 workspace. The tests should each operate
// on a unique project in the workspace, such that they
// are not dependent on one another.
beforeAll(() => {
ensureNxProject('@analogjs/nx', 'dist/packages/nx-plugin');
beforeAll(async () => {
ensureNxProject(
'@analogjs/vite-plugin-angular',
'node_modules/@analogjs/vite-plugin-angular'
);
ensureNxProject('@analogjs/platform', 'node_modules/@analogjs/platform');
});

afterAll(() => {
Expand All @@ -25,18 +29,15 @@ describe('nx-plugin e2e', () => {

it('should create hello-world', async () => {
const project = uniq('hello-world');
await runNxCommandAsync(`generate @analogjs/nx:app ${project}`);
const result = await runNxCommandAsync(`build ${project}`);
expect(result.stdout).toContain(
'Successfully ran target build for project'
);
await runNxCommandAsync(`generate @analogjs/platform:app ${project}`);
expect(() => checkFilesExist(`apps/${project}/index.html`)).not.toThrow();
}, 120000);

describe('--directory', () => {
it('should create src in the specified directory', async () => {
const project = uniq('hello-world');
await runNxCommandAsync(
`generate @analogjs/nx:app ${project} --directory subdir`
`generate @analogjs/platform:app ${project} --directory subdir`
);
expect(() =>
checkFilesExist(`apps/subdir/${project}/index.html`)
Expand All @@ -48,10 +49,10 @@ describe('nx-plugin e2e', () => {
it('should add tags to the project', async () => {
const projectName = uniq('hello-world');
await runNxCommandAsync(
`generate @analogjs/nx:app ${projectName} --tags e2etag,e2ePackage`
`generate @analogjs/platform:app ${projectName} --tags analog,analogApplication`
);
const project = readJson(`apps/${projectName}/project.json`);
expect(project.tags).toEqual(['e2etag', 'e2ePackage']);
expect(project.tags).toEqual(['analog', 'analogApplication']);
}, 120000);
});
});
2 changes: 1 addition & 1 deletion packages/nx-plugin/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"schematics": {
"app": {
"factory": "./src/generators/app/generator",
"factory": "./src/generators/app/compat",
"schema": "./src/generators/app/schema.json",
"description": "Add Angular Three with proper packages and config"
}
Expand Down
6 changes: 2 additions & 4 deletions packages/nx-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"name": "@analogjs/nx",
"version": "0.0.1-alpha.0",
"main": "src/index.js",
"generators": "./generators.json",
"schematics": "./generators.json"
"version": "0.0.1",
"main": "src/index.js"
}
2 changes: 1 addition & 1 deletion packages/nx-plugin/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"executor": "@nrwl/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/nx-plugin",
"outputPath": "node_modules/@analogjs/platform/src/lib/nx-plugin",
"main": "packages/nx-plugin/src/index.ts",
"tsConfig": "packages/nx-plugin/tsconfig.lib.json",
"assets": [
Expand Down
4 changes: 4 additions & 0 deletions packages/nx-plugin/src/generators/app/compat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { convertNxGenerator } from '@nrwl/devkit';
import generator from './generator';

export default convertNxGenerator(generator);
14 changes: 6 additions & 8 deletions packages/nx-plugin/src/generators/app/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
formatFiles,
generateFiles,
getWorkspaceLayout,
installPackagesTask,
names,
offsetFromRoot as determineOffsetFromRoot,
stripIndents,
Expand All @@ -12,7 +13,6 @@ import * as path from 'path';
import { AnalogNxApplicationGeneratorOptions } from './schema';
import { lt, major } from 'semver';
import { getInstalledAngularVersion } from '../../utils/version-utils';
import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial';
import { addAnalogProjectConfig } from './lib/add-analog-project-config';
import {
V15_ANALOG_JS_CONTENT,
Expand Down Expand Up @@ -113,12 +113,7 @@ async function addDependencies(tree: Tree, majorAngularVersion: number) {
vitest: majorAngularVersion === 15 ? V15_VITEST : V16_VITEST,
};

const installDependencies = addDependenciesToPackageJson(
tree,
dependencies,
devDependencies
);
await runTasksInSerial(installDependencies);
addDependenciesToPackageJson(tree, dependencies, devDependencies);
}

function addFiles(
Expand All @@ -128,7 +123,6 @@ function addFiles(
) {
const templateOptions = {
...options,
offsetFromRoot: options.offsetFromRoot,
template: '',
};
generateFiles(
Expand Down Expand Up @@ -169,4 +163,8 @@ export default async function (
if (!normalizedOptions.skipFormat) {
await formatFiles(tree);
}

return () => {
installPackagesTask(tree);
};
}
4 changes: 3 additions & 1 deletion packages/platform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@
"dependencies": {
"nitropack": "^1.0.0",
"@analogjs/vite-plugin-angular": "latest"
}
},
"generators": "./src/lib/nx-plugin/generators.json",
"schematics": "./src/lib/nx-plugin/generators.json"
}
15 changes: 13 additions & 2 deletions packages/platform/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"sourceRoot": "packages/platform/src",
"projectType": "library",
"targets": {
"build": {
"build-package": {
"executor": "@nrwl/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
Expand All @@ -27,6 +27,16 @@
},
"defaultConfiguration": "production"
},
"build": {
"executor": "nx:run-commands",
"options": {
"commands": [
"yarn nx build-package platform",
"yarn nx build nx-plugin"
],
"parallel": false
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
Expand All @@ -39,5 +49,6 @@
"executor": "@nrwl/vite:test"
}
},
"tags": []
"tags": [],
"implicitDependencies": ["vite-plugin-angular"]
}
7 changes: 6 additions & 1 deletion packages/platform/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
"inlineSourceMap": true,
"sourceMap": false,
"declaration": true,
"types": []
"types": [],
"paths": {
"@analogjs/vite-plugin-angular": [
"./node_modules/@analogjs/vite-plugin-angular"
]
}
},
"include": ["**/*.ts"],
"exclude": [
Expand Down

0 comments on commit c842919

Please sign in to comment.