Skip to content

Commit

Permalink
fix: 🐛 various fixes for rsync deployed
Browse files Browse the repository at this point in the history
things might still not be broken, but build is fixed now
  • Loading branch information
klaascuvelier committed Sep 13, 2023
1 parent 859b443 commit ad07eda
Show file tree
Hide file tree
Showing 10 changed files with 8,188 additions and 171 deletions.
8,222 changes: 8,106 additions & 116 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,17 @@
"tslib": "^2.0.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^16.2.1",
"@commitlint/cli": "^17.7.1",
"@commitlint/config-conventional": "^17.7.0",
"@commitlint/config-nx-scopes": "^17.6.4",
"@commitlint/cz-commitlint": "^17.7.1",
"@nx/eslint-plugin": "16.8.1",
"@nx/jest": "16.8.1",
"@nx/js": "16.8.1",
"@nx/linter": "16.8.1",
"@nx/node": "16.8.1",
"@nx/workspace": "16.8.1",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/release-notes-generator": "^10.0.3",
"@serverless-stack/cli": "^1.18.4",
Expand All @@ -53,7 +60,7 @@
"git-cz": "^4.8.0",
"glob": "^7.2.0",
"husky": "^8.0.0",
"jest": "29.4.3",
"jest": "29.7.0",
"lint-staged": "^14.0.1",
"nx": "16.8.1",
"nx-cloud": "16.4.0",
Expand All @@ -62,13 +69,7 @@
"ts-jest": "29.1.1",
"ts-node": "10.9.1",
"typescript": "5.1.6",
"wrangler": "^2.0.7",
"@nx/workspace": "16.8.1",
"@nx/js": "16.8.1",
"@nx/eslint-plugin": "16.8.1",
"@nx/linter": "16.8.1",
"@nx/jest": "16.8.1",
"@nx/node": "16.8.1"
"wrangler": "^2.0.7"
},
"config": {
"commitizen": {
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-cloudflare-wrangler/src/executors/wrangler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
readProjectConfiguration,
workspaceRoot,
} from '@nx/devkit';
import { FsTree } from '@nx/tao/src/shared/tree';
import { execSync } from 'child_process';
import { FsTree } from 'nx/src/generators/tree';
import { PagesDeployExecutorSchema } from './pages/deploy/schema';
import { WorkerDeployExecutorSchema } from './workers/deploy/schema';
import { WorkerServeExecutorSchema } from './workers/serve/schema';
Expand Down
3 changes: 2 additions & 1 deletion packages/nx-deno-deploy/src/executors/deploy/executor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ExecutorContext, readProjectConfiguration } from '@nx/devkit';
import { FsTree } from '@nx/tao/src/shared/tree';
import { FsTree } from 'nx/src/generators/tree';

import { deployProject } from '../../lib/deploy-ctl';
import { DeployExecutorSchema } from './schema';

Expand Down
2 changes: 1 addition & 1 deletion packages/nx-deno-deploy/src/executors/lint/executor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExecutorContext, readProjectConfiguration } from '@nx/devkit';
import { FsTree } from '@nx/tao/src/shared/tree';
import { FsTree } from 'nx/src/generators/tree';
import { lintProject } from '../../lib/deploy-ctl';

export default async function lintExecutor(
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-deno-deploy/src/executors/serve/executor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExecutorContext, readProjectConfiguration } from '@nx/devkit';
import { FsTree } from '@nx/tao/src/shared/tree';
import { FsTree } from 'nx/src/generators/tree';
import { runProject } from '../../lib/deploy-ctl';

export default async function serveExecutor(
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-deno-deploy/src/executors/test/executor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExecutorContext, readProjectConfiguration } from '@nx/devkit';
import { FsTree } from '@nx/tao/src/shared/tree';
import { FsTree } from 'nx/src/generators/tree';
import { testProject } from '../../lib/deploy-ctl';

export default async function testExecutor(
Expand Down
3 changes: 3 additions & 0 deletions packages/nx-rsync-deployer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
"deploy",
"rsync"
],
"peerDependencies": {
"@angular-devkit/build-angular": "^16.2.1"
},
"builders": "builders.json"
}
103 changes: 62 additions & 41 deletions packages/nx-rsync-deployer/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
import { createBuilder } from '@angular-devkit/architect';
import { ExecutorContext, readProjectConfiguration } from '@nx/devkit';
import { execSync, spawn } from 'child_process';
import { projects as angularProjects } from '../../../angular.json';
import { properties as schemaProperties } from './schema.json';

const NxBuilder = createBuilder(async (builderConfig, context) => {
const { project } = context.target;
import { FsTree } from 'nx/src/generators/tree';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { properties: schemaProperties } = require('./schema.json');

export type RsyncDeployExecutorSchema = {
noBuild: boolean;
outputPath: string;
deployIdentifier: string;
previewUrl: string;
rsyncTarget: string;
rsyncUser: string;
rsyncHost: string;
preDeploy: string[];
postDeploy: string[];
};

export default async function runExecutor(
options: RsyncDeployExecutorSchema,
context: ExecutorContext
) {
const projectName = context.projectName;
const {
deployIdentifier,
previewUrl,
Expand All @@ -13,16 +30,17 @@ const NxBuilder = createBuilder(async (builderConfig, context) => {
rsyncHost,
preDeploy,
postDeploy,
} = extractConfig(builderConfig);
} = extractConfig(options);

const projectInfo = angularProjects[project];
const buildOutputPath = projectInfo.architect.build.options.outputPath;
const tree = new FsTree(process.cwd(), false);
const projectInfo = readProjectConfiguration(tree, projectName);
const buildOutputPath = projectInfo.targets['build'].options.outputPath;
const deployUrl =
previewUrl.replace('$deployIdentifier', deployIdentifier) +
(previewUrl.endsWith('/') ? '' : '/');

if (builderConfig.noBuild) {
context.logger.info(`📦 Skipping build`);
if (options.noBuild) {
console.info(`📦 Skipping build`);
} else {
if (!context.target) {
throw new Error('Cannot build the application without a target');
Expand All @@ -34,36 +52,37 @@ const NxBuilder = createBuilder(async (builderConfig, context) => {
);
}

const configuration = builderConfig.configuration || 'production';
const configuration = 'production';
const overrides = {
baseHref: deployUrl,
deployUrl: deployUrl,
};

context.logger.info(
`📦 Building "${context.target.project}". Configuration: "${configuration}". ${deployIdentifier}`
);

const build = await context.scheduleTarget(
{
target: 'build',
project: context.target.project || '',
configuration,
},
overrides
console.info(
`📦 Building "${projectName}". Configuration: "${configuration}". ${deployIdentifier}`
);

const buildResult = await build.result;

if (buildResult.success !== true) {
context.logger.error(`❌ Application build failed`);
return {
error: `❌ Application build failed`,
success: false,
};
}

context.logger.info(`✔ Build Completed`);
console.warn(`Building not implemented`);

// const build = await executeBrowserBuilder({} as unknown as BrowserBuilderSchema, context);
//
// const build = await context.scheduleTarget(
// {
// target: 'build',
// project: context.target.project || '',
// configuration,
// },
// overrides
// );
//
// if (buildResult.success !== true) {
// console.error(`❌ Application build failed`);
// return {
// error: `❌ Application build failed`,
// success: false,
// };
// }
// context.logger.info(`✔ Build Completed`);
}

return deploy(
Expand All @@ -77,11 +96,14 @@ const NxBuilder = createBuilder(async (builderConfig, context) => {
postDeploy
)
.then(() => {
context.logger.info(`✔ Deploy Completed: ${deployUrl}`);
console.info(`✔ Deploy Completed: ${deployUrl}`);
return { success: true };
})
.catch((error) => ({ success: false }));
});
.catch((error) => {
console.error(error);
return { success: false };
});
}

function extractConfig(config) {
const deployIdentifier = normalizeText(
Expand All @@ -107,10 +129,11 @@ function extractConfig(config) {
schemaProperties.rsyncHost.default
);
const previewUrl = withFallback(config.previewUrl, null);
const preDeploy = withFallback(config.preDeploy, [])
const preDeploy = (config.preDeploy ?? [])
.map(addPrePostDeployReplacements)
.join(`,`);
const postDeploy = withFallback(config.postDeploy, [])

const postDeploy = (config.postDeploy ?? [])
.map(addPrePostDeployReplacements)
.join(`,`);

Expand Down Expand Up @@ -235,5 +258,3 @@ function deploy(
});
});
}

exports.default = NxBuilder;
3 changes: 2 additions & 1 deletion packages/nx-sst/src/executors/sst.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ExecutorContext, readProjectConfiguration } from '@nx/devkit';
import { FsTree } from '@nx/tao/src/shared/tree';

import { execSync } from 'child_process';
import { FsTree } from 'nx/src/generators/tree';
import { ServeExecutorSchema } from './serve/schema';

export type sstCommand = 'start' | 'test' | 'deploy' | 'remove';
Expand Down

0 comments on commit ad07eda

Please sign in to comment.