Add base application project yarn release file (#16238)

As title
This commit is contained in:
martmull
2025-12-02 13:10:50 +01:00
committed by GitHub
parent 5d4170d4c3
commit 6ea817dd6c
12 changed files with 352 additions and 97 deletions
@@ -13,27 +13,19 @@ export const copyBaseApplicationProject = async ({
appDescription: string;
appDirectory: string;
}) => {
await fs.copy(join(__dirname, '../constants/base-application'), appDirectory);
await createPackageJson({ appName, appDirectory });
await createGitignore(appDirectory);
await createYarnLock(appDirectory);
await createYarnRc(appDirectory);
await createNvmRc(appDirectory);
await createTsConfig(appDirectory);
await createApplicationConfig({
displayName: appDisplayName,
description: appDescription,
appDirectory,
});
await createReadmeContent({
displayName: appDisplayName,
appDescription,
appDirectory,
});
};
const createYarnLock = async (appDirectory: string) => {
@@ -43,55 +35,45 @@ const createYarnLock = async (appDirectory: string) => {
await fs.writeFile(join(appDirectory, 'yarn.lock'), yarnLockContent);
};
const createGitignore = async (appDirectory: string) => {
const gitignoreContent = `# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
const createYarnRc = async (appDirectory: string) => {
const yarnRcContent = `nodeLinker: node-modules
# dependencies
/node_modules
/.pnp
.pnp.*
.yarn
# codegen
generated
# testing
/coverage
# dev
/dist/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*
# env files (can opt-in for committing if needed)
.env*
# typescript
*.tsbuildinfo
`;
await fs.writeFile(join(appDirectory, '.yarnrc.yml'), yarnRcContent);
};
const createNvmRc = async (appDirectory: string) => {
const nvmRcContent = `24.5.0
`;
await fs.writeFile(join(appDirectory, '.nvmrc'), nvmRcContent);
};
const createTsConfig = async (appDirectory: string) => {
const tsConfigJson = {
compileOnSave: false,
compilerOptions: {
sourceMap: true,
declaration: true,
outDir: './dist',
rootDir: '.',
moduleResolution: 'node',
allowSyntheticDefaultImports: true,
emitDecoratorMetadata: true,
experimentalDecorators: true,
importHelpers: true,
allowUnreachableCode: false,
strictNullChecks: true,
alwaysStrict: true,
noImplicitAny: true,
strictBindCallApply: false,
target: 'es2018',
module: 'esnext',
lib: ['es2020', 'dom'],
skipLibCheck: true,
skipDefaultLibCheck: true,
resolveJsonModule: true,
},
exclude: ['node_modules', 'dist', '**/*.test.ts', '**/*.spec.ts'],
};
await fs.writeFile(
join(appDirectory, 'tsconfig.json'),
JSON.stringify(tsConfigJson, null, 2),
'utf8',
);
await fs.writeFile(join(appDirectory, '.gitignore'), gitignoreContent);
};
const createApplicationConfig = async ({
@@ -126,7 +108,7 @@ const createPackageJson = async ({
}) => {
const packageJson = {
name: appName,
version: '0.0.1',
version: '0.1.0',
license: 'MIT',
engines: {
node: '^24.5.0',
@@ -157,20 +139,3 @@ const createPackageJson = async ({
'utf8',
);
};
const createReadmeContent = async ({
displayName,
appDescription,
appDirectory,
}: {
displayName: string;
appDescription: string;
appDirectory: string;
}) => {
const readmeContent = `# ${displayName}
${appDescription}
`;
await fs.writeFile(join(appDirectory, 'README.md'), readmeContent);
};
@@ -0,0 +1,13 @@
import chalk from 'chalk';
import { promisify } from 'util';
import { exec } from 'child_process';
const execPromise = promisify(exec);
export const install = async (root: string) => {
try {
await execPromise('yarn', { cwd: root });
} catch (error: any) {
console.error(chalk.red('yarn install failed:'), error.stdout);
}
};
@@ -0,0 +1,70 @@
import * as fs from 'fs-extra';
import { join } from 'path';
import { promisify } from 'util';
import { exec } from 'child_process';
const execPromise = promisify(exec);
const isInGitRepository = async (root: string): Promise<boolean> => {
try {
await execPromise('git rev-parse --is-inside-work-tree', { cwd: root });
return true;
} catch {
// Empty catch block
}
return false;
};
const isInMercurialRepository = async (root: string): Promise<boolean> => {
try {
await execPromise('hg --cwd . root', { cwd: root });
return true;
} catch {
// Empty catch block
}
return false;
};
const isDefaultBranchSet = async (root: string): Promise<boolean> => {
try {
await execPromise('git config init.defaultBranch', { cwd: root });
return true;
} catch {
// Empty catch block
}
return false;
};
export const tryGitInit = async (root: string): Promise<boolean> => {
try {
await execPromise('git --version', { cwd: root });
if (
(await isInGitRepository(root)) ||
(await isInMercurialRepository(root))
) {
return false;
}
await execPromise('git init', { cwd: root });
try {
if (!(await isDefaultBranchSet(root))) {
await execPromise('git checkout -b main', { cwd: root });
}
await execPromise('git add -A', { cwd: root });
await execPromise(
'git commit -m "Initial commit from Create Twenty App"',
{
cwd: root,
},
);
return true;
} catch {
fs.rm(join(root, '.git'), { recursive: true, force: true });
return false;
}
} catch {
return false;
}
};