Skip to content

Commit

Permalink
Integration scaffolder
Browse files Browse the repository at this point in the history
  • Loading branch information
Kurt Medley committed May 25, 2024
1 parent 7ea79fc commit c95ef1d
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 9 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
- run: npm ci
- run: npm run test:integration
- run: npm run build
- run: ls -lart
- run: node dist/test/integration/scaffold.mjs
- run: ls -lart
26 changes: 21 additions & 5 deletions src/api.mts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,15 @@ async function install(PACKAGE_WORKING_DIR: string) {
*
* @param {*} param0
*/
export async function createPackage({ answers }: { answers: Answer }) {
export async function createPackage({
answers,
isInstall = true,
isRun = true,
}: {
answers: Answer;
isInstall?: boolean;
isRun?: boolean;
}) {
// First, determine if we're creating a namespaced directory for the
// package. If not, scaffold out the package contents directly in the cwd
const { namespacedDir = true, packageName, packageTemplate } = answers || {};
Expand Down Expand Up @@ -192,8 +200,12 @@ export async function createPackage({ answers }: { answers: Answer }) {
camelComponentName,
} as GenerateData,
});
await install(PACKAGE_WORKING_DIR);
await runComponent(PACKAGE_WORKING_DIR);
if (isInstall) {
await install(PACKAGE_WORKING_DIR);
}
if (isRun) {
await runComponent(PACKAGE_WORKING_DIR);
}
} else if (packageTemplate === TemplateTypes.VANILLA) {
await generate({
walkPath: TemplatePaths.VANILLA,
Expand All @@ -202,14 +214,18 @@ export async function createPackage({ answers }: { answers: Answer }) {

data: { ...CONFIG, ...answers } as GenerateData,
});
await install(PACKAGE_WORKING_DIR);
if (isInstall) {
await install(PACKAGE_WORKING_DIR);
}
} else if (packageTemplate === TemplateTypes.MICROSITE) {
await generate({
walkPath: TemplatePaths.MICROSITE,
packageTemplate,
packageWorkingDir: PACKAGE_WORKING_DIR,
data: { ...CONFIG, ...answers } as GenerateData,
});
await install(PACKAGE_WORKING_DIR);
if (isInstall) {
await install(PACKAGE_WORKING_DIR);
}
}
}
1 change: 0 additions & 1 deletion src/scaffold.mts

This file was deleted.

39 changes: 39 additions & 0 deletions src/test/integration/scaffold.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { access, rm } from 'node:fs/promises';
import { resolve } from 'node:path';
import LoggerFactory from '../../logger.mjs';
import { Answer } from '../../types/index.mjs';
import { TemplateTypes } from '../../util.mjs';
import { createPackage } from '../../api.mjs';

const logger = LoggerFactory({ label: '/test/integration.test.mts' });

async function exists(filePath: string) {
try {
await access(filePath);
return true;
} catch (error) {
return false;
}
}

(async () => {
const packageName = 'integration-test-vue';
const scaffoldedPath = resolve(process.cwd(), packageName);
if (await exists(scaffoldedPath)) {
logger.info(`Removing ${scaffoldedPath}`);
await rm(scaffoldedPath, { recursive: true, force: true });
}

const answers: Answer = {
packageName,
packageDescription: 'This is a test vue component',
packageAuthor: 'rei',
packageOwnerTeamId: 'testTeamId',
packageTemplate: TemplateTypes.VUE,
packageUsesDataDog: false,
namespacedDir: true,
};

logger.info(`Executing createPackage from integration test`);
await createPackage({ answers, isInstall: false, isRun: false });
})();
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"noFallthroughCasesInSwitch": true,
"resolveJsonModule": true
},
"include": ["src", "types", "vitest.config.mts"]
"include": ["src", "types"]
}
9 changes: 8 additions & 1 deletion vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ export default defineConfig({
provider: 'v8',
reporter: ['text', 'json-summary', 'html'],
all: true,
exclude: ['test', 'dist', '**/*.d.mts', 'src/bin/*.mts', 'src/api.mts'],
exclude: [
'test',
'dist',
'**/*.d.mts',
'src/bin/*.mts',
'src/api.mts',
'src/test/integration/scaffold.mts',
],
include: ['src', 'test'],
clean: true,
thresholds: {
Expand Down

0 comments on commit c95ef1d

Please sign in to comment.