Skip to content

Commit

Permalink
fix: conditionally add LICENSE and README to workspace root (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman authored Feb 23, 2024
1 parent de559a4 commit e79508e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 91 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import {
addDependenciesToPackageJson,
formatFiles,
getProjects,
installPackagesTask,
Tree,
updateJson,
} from '@nx/devkit'
import { addDependenciesToPackageJson, getProjects, installPackagesTask, Tree } from '@nx/devkit'
import { getNpmScope } from '@nx/js/src/utils/package-json/get-npm-scope'
import { anchorApplicationGenerator } from '@solana-developers/preset-anchor'
import { applicationCleanup, commonTemplateGenerator, packageVersion } from '@solana-developers/preset-common'
import { applicationCleanup, packageVersion } from '@solana-developers/preset-common'
import {
applicationTailwindConfig,
features,
generateReactCommonFiles,
reactApplicationDependencies,
reactApplicationRunScripts,
ReactFeature,
reactFeatureGenerator,
reactTemplateGenerator,
Expand Down Expand Up @@ -156,44 +149,7 @@ export default function Page() {
},`
tree.write(nextConfigPath, nextConfig.replace(needle, `${needle}\n${snippet}`))

updateJson(tree, 'package.json', (json) => {
json.scripts = {
...json.scripts,
...reactApplicationRunScripts({
anchor: options.anchor,
anchorName: options.anchorName,
webName: options.webName,
}),
}
return json
})

// Generate the readme files
await commonTemplateGenerator(tree, {
name: options.webName,
npmScope,
template: 'readme',
anchor: options.anchor,
anchorName: options.anchorName,
webName: options.webName,
directory: '.',
})

// Generate the license files
await commonTemplateGenerator(tree, {
name: options.webName,
npmScope,
template: 'license',
anchor: options.anchor,
anchorName: options.anchorName,
webName: options.webName,
directory: '.',
})

// Format the files.
if (!options.skipFormat) {
await formatFiles(tree)
}
await generateReactCommonFiles(tree, options, npmScope)

// Install the packages on exit.
return () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { formatFiles, getProjects, installPackagesTask, Tree, updateJson } from '@nx/devkit'
import { getProjects, installPackagesTask, Tree } from '@nx/devkit'
import { getNpmScope } from '@nx/js/src/utils/package-json/get-npm-scope'
import { anchorApplicationGenerator } from '@solana-developers/preset-anchor'
import { applicationCleanup, commonTemplateGenerator } from '@solana-developers/preset-common'
import { applicationCleanup } from '@solana-developers/preset-common'
import { join } from 'path'
import {
applicationTailwindConfig,
generateReactApplication,
generateReactCommonFiles,
NormalizedReactApplicationSchema,
normalizeReactApplicationSchema,
reactApplicationDependencies,
reactApplicationRunScripts,
walletAdapterDependencies,
} from '../../utils'
import { reactTemplateGenerator } from '../react-template/react-template-generator'
import { features, ReactFeature, reactFeatureGenerator } from '../react-feature'
import { reactTemplateGenerator } from '../react-template/react-template-generator'
import { ReactApplicationSchema } from './react-application-schema'

export async function reactApplicationGenerator(tree: Tree, rawOptions: ReactApplicationSchema) {
Expand Down Expand Up @@ -88,45 +88,7 @@ export async function reactApplicationGenerator(tree: Tree, rawOptions: ReactApp
feature,
})
}

updateJson(tree, 'package.json', (json) => {
json.scripts = {
...json.scripts,
...reactApplicationRunScripts({
anchor: options.anchor,
anchorName: options.anchorName,
webName: options.webName,
}),
}
return json
})

// Generate the readme files
await commonTemplateGenerator(tree, {
name: options.webName,
npmScope,
template: 'readme',
anchor: options.anchor,
anchorName: options.anchorName,
webName: options.webName,
directory: '.',
})

// Generate the license files
await commonTemplateGenerator(tree, {
name: options.webName,
npmScope,
template: 'license',
anchor: options.anchor,
anchorName: options.anchorName,
webName: options.webName,
directory: '.',
})

// Format the files.
if (!options.skipFormat) {
await formatFiles(tree)
}
await generateReactCommonFiles(tree, options, npmScope)

// Install the packages on exit.
return () => {
Expand Down
53 changes: 53 additions & 0 deletions packages/preset-react/src/utils/generate-react-common-files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { formatFiles, Tree, updateJson } from '@nx/devkit'
import { commonTemplateGenerator } from '@solana-developers/preset-common'
import { NormalizedReactApplicationSchema } from './normalize-react-application-schema'
import { reactApplicationRunScripts } from './react-application-run-scripts'

export async function generateReactCommonFiles(
tree: Tree,
options: NormalizedReactApplicationSchema,
npmScope: string,
) {
updateJson(tree, 'package.json', (json) => {
json.scripts = {
...json.scripts,
...reactApplicationRunScripts({
anchor: options.anchor,
anchorName: options.anchorName,
webName: options.webName,
}),
}
return json
})

if (!tree.exists('README.md')) {
// Generate the readme files
await commonTemplateGenerator(tree, {
name: options.webName,
npmScope,
template: 'readme',
anchor: options.anchor,
anchorName: options.anchorName,
webName: options.webName,
directory: '.',
})
}

if (!tree.exists('LICENSE') && !tree.exists('LICENSE.md')) {
// Generate the license files
await commonTemplateGenerator(tree, {
name: options.webName,
npmScope,
template: 'license',
anchor: options.anchor,
anchorName: options.anchorName,
webName: options.webName,
directory: '.',
})
}

// Format the files.
if (!options.skipFormat) {
await formatFiles(tree)
}
}
1 change: 1 addition & 0 deletions packages/preset-react/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './application-tailwind-config'
export * from './generate-react-common-files'
export * from './generate-react-application'
export * from './get-ui-dependencies'
export * from './normalize-react-application-schema'
Expand Down

0 comments on commit e79508e

Please sign in to comment.