-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(configuration): rename templates and basic workspaces support
Import files for build-tool configurations. release-npm
- Loading branch information
Showing
16 changed files
with
147 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
import type { Template } from '../types' | ||
import { fileExtension, state } from '../state' | ||
|
||
export const templates: Template<object> = {} // Has no templates, highly customizable. | ||
export const extension = (path: string) => ({ extends: path }) | ||
|
||
export function createFile() { | ||
return { | ||
name: 'playwright.config.ts', | ||
contents: `import { defineConfig } from '@playwright/test' | ||
import { playwright } from './configuration.ts' | ||
export function createFile(configuration: object | string) { | ||
let contents = `import { playwright } from './configuration.${fileExtension()}' | ||
export default defineConfig(playwright)`, | ||
export default playwright` | ||
|
||
if (typeof configuration === 'object' && state.language === 'json') { | ||
contents = `export default ${JSON.stringify(configuration, null, 2)}` | ||
} | ||
|
||
return { name: `playwright.config.${fileExtension()}`, contents } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,32 @@ | ||
#!/usr/bin/env bun | ||
import Bun from 'bun' | ||
import { configurations } from './configuration' | ||
import { findConfiguration, log, root, writeGitIgnore } from './helper' | ||
import { findConfiguration, getWorkspaces, log, writeGitIgnore } from './helper' | ||
import { parse } from './parse' | ||
import { state } from './state' | ||
import { reset, root, state } from './state' | ||
|
||
const ignores: string[] = [] | ||
async function configureProject() { | ||
const ignores: string[] = [] | ||
|
||
await findConfiguration() | ||
await findConfiguration() | ||
|
||
for (const { name, alias, configuration } of configurations) { | ||
const value = state.options[name] ?? (alias && state.options[alias]) | ||
if (!value) continue | ||
const file = await parse(value, configuration) | ||
if (!file) continue | ||
await Bun.write(root(file.name), file.contents) | ||
ignores.push(file.name) | ||
} | ||
for (const { name, alias, configuration } of configurations) { | ||
const value = state.options[name] ?? (alias && state.options[alias]) | ||
if (!value) continue | ||
const file = await parse(value, configuration) | ||
if (!file) continue | ||
await Bun.write(root(file.name), file.contents) | ||
ignores.push(file.name) | ||
} | ||
|
||
const gitUserConfigured = await writeGitIgnore(ignores) | ||
|
||
const gitUserConfigured = await writeGitIgnore(ignores) | ||
if (!gitUserConfigured && ignores.length === 0) { | ||
log('No configuration to add', 'warning') | ||
} | ||
} | ||
|
||
if (!gitUserConfigured && ignores.length === 0) { | ||
log('No configuration to add', 'warning') | ||
for (const workspace of await getWorkspaces()) { | ||
reset(workspace) | ||
await configureProject() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
import { join } from 'node:path' | ||
import type { State } from './types' | ||
|
||
export const state: State = { | ||
options: {}, | ||
language: 'json', | ||
packageJson: { name: 'missing-package-name' }, | ||
directory: '/', | ||
root: true, | ||
} | ||
|
||
export const fileExtension = () => (state.language === 'javascript' ? 'js' : 'ts') | ||
|
||
export const root = (file: string) => | ||
process.cwd().includes('node_modules') ? join(process.cwd(), '../..', state.directory, file) : join(process.cwd(), state.directory, file) | ||
|
||
export const reset = ({ path, root }: { path: string; root: boolean }) => { | ||
state.options = {} | ||
state.language = 'json' | ||
state.packageJson = { name: 'missing-package-name' } | ||
state.directory = path | ||
state.root = root | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "demo-react", | ||
"configuration": { | ||
"typescript": "plugin", | ||
"vite": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "workspaces", | ||
"workspaces": [ | ||
"demo/*", | ||
"plugin" | ||
], | ||
"configuration": { | ||
"typescript": "plugin" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "plugin", | ||
"configuration": { | ||
"typescript": "plugin" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters