Skip to content

Commit

Permalink
Automatically add boilerplate.schema.json to .gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
vilicvane committed Oct 16, 2023
1 parent 13e909b commit 3c2ff69
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 36 deletions.
46 changes: 34 additions & 12 deletions general/src/composables/prettierignore.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import * as FS from 'fs/promises';
import * as Path from 'path';

import {composable, text} from '@magicspace/core';

import type {ResolvedOptions} from '../library/index.js';
Expand All @@ -7,19 +10,38 @@ const PACKAGE_MANAGER_IGNORE_ENTRIES_DICT = {
yarn: undefined,
};

export default composable<ResolvedOptions>(({packageManager}) => {
const packageManagerIgnoreEntries =
PACKAGE_MANAGER_IGNORE_ENTRIES_DICT[packageManager];
const BOILERPLATE_SCHEMA_FILE_NAME = 'boilerplate.schema.json';

export default composable<ResolvedOptions>(
async ({packageManager, magicspaceDir}) => {
const packageManagerIgnoreEntries =
PACKAGE_MANAGER_IGNORE_ENTRIES_DICT[packageManager];

if (!packageManagerIgnoreEntries) {
return undefined;
}

if (!packageManagerIgnoreEntries) {
return undefined;
}
const boilerplateSchemaExists = await FS.stat(
Path.join(magicspaceDir, BOILERPLATE_SCHEMA_FILE_NAME),
).then(
stats => stats.isFile(),
() => false,
);

return text(
'.prettierignore',
content => `${content}\
return text('.prettierignore', content => {
if (boilerplateSchemaExists) {
content += `\
# Magicspace
${BOILERPLATE_SCHEMA_FILE_NAME}
`;
}

content += `\
# Package Manager
${packageManagerIgnoreEntries.join('\n')}
`,
);
});
`;

return content;
});
},
);
28 changes: 17 additions & 11 deletions general/src/library/boilerplate.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import * as Path from 'path';

import type {BoilerplateBuilderContext} from '@magicspace/core';
import {boilerplate, composables, x} from '@magicspace/core';
import _ from 'lodash';

export default boilerplate<Options>(async options => {
export default boilerplate<Options>(async (options, context) => {
return {
composables: await composables(
{
root: Path.join(__dirname, '../composables'),
pattern: '(?!@)*.js',
},
resolveOptions(options),
resolveOptions(options, context),
),
scripts: {
postgenerate: 'prettier --write .',
Expand Down Expand Up @@ -112,7 +113,7 @@ export interface ResolvedPackageOptions extends PackageOptions {
packageJSONPath: string;
}

export interface ResolvedOptions extends Options {
export interface ResolvedOptions extends Options, BoilerplateBuilderContext {
defaultBranch: string;
packageManager: 'pnpm' | 'yarn';
packagesDir: string | undefined;
Expand All @@ -123,15 +124,19 @@ export interface ResolvedOptions extends Options {

export function resolveOptions<TOptions extends Options>(
options: TOptions,
context: BoilerplateBuilderContext,
): TOptions & ResolvedOptions;
export function resolveOptions({
name,
defaultBranch = 'main',
packageManager = 'yarn',
packagesDir,
packages,
...rest
}: Options): ResolvedOptions {
export function resolveOptions(
{
name,
defaultBranch = 'main',
packageManager = 'yarn',
packagesDir,
packages,
...rest
}: Options,
context: BoilerplateBuilderContext,
): ResolvedOptions {
let resolvedPackages: ResolvedPackageOptions[];

if (packages || packagesDir !== undefined) {
Expand Down Expand Up @@ -179,6 +184,7 @@ export function resolveOptions({
resolvedPackages,
packageOptions => packageOptions.alias ?? '',
),
...context,
...rest,
};
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"test": "yarn lint-prettier && yarn build && yarn lint"
},
"dependencies": {
"@magicspace/core": "^0.3.0-alpha.5",
"@magicspace/utils": "^0.3.0-alpha.1",
"@magicspace/core": "^0.3.3",
"@magicspace/utils": "^0.3.0",
"lodash": "^4.17.20",
"npm-which": "^3.0.1",
"prettier": "^3.0.3",
Expand Down
22 changes: 11 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@
wrap-ansi "^8.1.0"
wrap-ansi-cjs "npm:wrap-ansi@^7.0.0"

"@magicspace/core@^0.3.0-alpha.5":
version "0.3.0-alpha.5"
resolved "https://registry.yarnpkg.com/@magicspace/core/-/core-0.3.0-alpha.5.tgz#f845f9aaef4622ea457ccc674cd8349e7b5cc67e"
integrity sha512-oL0+OyxvzjWLNVyZJuIgej+6mbY8ubdv2zYEBxs43cSmo5oKKgtRPLV0TppVsBe7U4P2+JTM4gD5W/rIw3GbFw==
"@magicspace/core@^0.3.3":
version "0.3.3"
resolved "https://registry.yarnpkg.com/@magicspace/core/-/core-0.3.3.tgz#4f2a7393567e7092159ad63a15e57761109336bd"
integrity sha512-HKL+AY7A9fP2JIke7h+s9Po8qrZ92X7cBI/zxtHANXv13nFktrgK+Wp+J7F/QBwBW1VjJn1jeRNBvd25DBETzg==
dependencies:
"@magicspace/utils" "^0.3.0-alpha.1"
"@magicspace/utils" "^0.3.0"
enhanced-resolve "^5.12.0"
fast-glob "^3.2.12"
fs-extra "^11.1.0"
Expand All @@ -98,21 +98,21 @@
npm-path "^2.0.4"
tmp "^0.2.1"
tslang "^0.1.27"
tslib "^2.5.0"
tslib "^2.6.2"
x-value "^0.1.8"
yaml "^2.2.1"

"@magicspace/utils@^0.3.0-alpha.1":
version "0.3.0-alpha.1"
resolved "https://registry.yarnpkg.com/@magicspace/utils/-/utils-0.3.0-alpha.1.tgz#a7b35fcef7d2f341d0f78ff4c9ec4b068723942e"
integrity sha512-G/ZJ6fRyi7vMSGmXDDi6WPLSOR4NEtRU992Y/PC8c/zn3pTRvFA7R4UTWK9Bz8l7cXYVUkyMg047PVFnTUCKyA==
"@magicspace/utils@^0.3.0":
version "0.3.0"
resolved "https://registry.yarnpkg.com/@magicspace/utils/-/utils-0.3.0.tgz#2b68f4fb2598cad645660597974af670ec44d702"
integrity sha512-w353jez9X2p3dKXQOjhxOIwzV+VgDhRk0NaKoXjSfCI0mSYF/LRSWILcr35A1r3DNf7cosYAZYNvVfmyJtgWKg==
dependencies:
chalk "4"
latest-version "5"
lodash "^4.17.21"
micromatch "^4.0.5"
tslang "^0.1.27"
tslib "^2.5.0"
tslib "^2.6.2"

"@mufan/eslint-plugin@^0.2.1":
version "0.2.1"
Expand Down

0 comments on commit 3c2ff69

Please sign in to comment.