Skip to content

Commit

Permalink
feat(core): introduce nx import
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Aug 2, 2024
1 parent 2111841 commit 6e5743d
Show file tree
Hide file tree
Showing 10 changed files with 815 additions and 26 deletions.
41 changes: 41 additions & 0 deletions e2e/nx/src/import.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {
checkFilesExist,
cleanupProject,
newProject,
runCLI,
} from '@nx/e2e/utils';

describe('Nx Import', () => {
let proj: string;
beforeAll(
() =>
(proj = newProject({
packages: ['@nx/vue'],
unsetProjectNameAndRootFormat: false,
}))
);
afterAll(() => cleanupProject());

it('should be able to import a vite app', () => {
const remote = 'https://github.com/FrozenPandaz/nx-examples.git';
const ref = 'vue';
const source = '.';
const directory = 'projects/vue-app';
runCLI(
`import ${remote} ${directory} --ref ${ref} --source ${source} --no-interactive`
);

checkFilesExist(
'projects/vue-app/.gitignore',
'projects/vue-app/package.json',
'projects/vue-app/index.html',
'projects/vue-app/vite.config.ts',
'projects/vue-app/e2e/tsconfig.json',
'projects/vue-app/e2e/vue.spec.ts',
'projects/vue-app/src/main.ts',
'projects/vue-app/src/App.vue',
'projects/vue-app/public/favicon.ico'
);
runCLI(`build created-vue-app`);
});
});
44 changes: 44 additions & 0 deletions packages/nx/src/command-line/import/command-object.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Arguments, CommandModule, MiddlewareFunction } from 'yargs';
import { linkToNxDevAndExamples } from '../yargs-utils/documentation';
import { withVerbose } from '../yargs-utils/shared-options';
import { handleErrors } from '../../utils/params';
import type { ImportOptions } from './import';

export const yargsImportCommand: CommandModule = {
command: 'import [sourceRemoteUrl] [destination]',
describe: false,
builder: (yargs) =>
linkToNxDevAndExamples(
withVerbose(
yargs
.positional('sourceRemoteUrl', {
type: 'string',
description: 'The remote URL of the source to import',
})
.positional('destination', {
type: 'string',
description:
'The directory in the current workspace to import into',
})
.option('source', {
type: 'string',
description:
'The directory in the source repository to import from',
})
.option('ref', {
type: 'string',
description: 'The branch from the source repository to import',
})
),
'import'
),
handler: async (args) => {
const exitCode = await handleErrors(
(args.verbose as boolean) ?? process.env.NX_VERBOSE_LOGGING === 'true',
async () => {
return (await import('./import')).importHandler(args as any);
}
);
process.exit(exitCode);
},
};
Loading

0 comments on commit 6e5743d

Please sign in to comment.