-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move license and readme templates to preset-common
- Loading branch information
Showing
18 changed files
with
491 additions
and
15 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"generators": { | ||
"common-template": { | ||
"factory": "./src/generators/common-template/common-template-generator", | ||
"schema": "./src/generators/common-template/common-template-schema.json", | ||
"description": "common-template generator" | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -46,5 +46,6 @@ | |
"name": "Bram Borggreve", | ||
"url": "https://github.com/beeman" | ||
} | ||
] | ||
], | ||
"generators": "./generators.json" | ||
} |
269 changes: 269 additions & 0 deletions
269
...ommon/src/generators/common-template/__snapshots__/common-template-generator.spec.ts.snap
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,269 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`common-template generator should generate files for { template: 'license', anchor: 'counter' } template with %s anchor 1`] = ` | ||
{ | ||
"LICENSE": { | ||
"content": [ | ||
"MIT License", | ||
"Copyright (c) 2023 test", | ||
"Permission is hereby granted, free of charge, to any person obtaining a copy", | ||
"of this software and associated documentation files (the "Software"), to deal", | ||
"in the Software without restriction, including without limitation the rights", | ||
"to use, copy, modify, merge, publish, distribute, sublicense, and/or sell", | ||
"copies of the Software, and to permit persons to whom the Software is", | ||
"furnished to do so, subject to the following conditions:", | ||
"The above copyright notice and this permission notice shall be included in all", | ||
"copies or substantial portions of the Software.", | ||
"THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR", | ||
"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,", | ||
"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE", | ||
"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER", | ||
"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,", | ||
"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE", | ||
"SOFTWARE.", | ||
], | ||
"isBinary": false, | ||
"path": "test/LICENSE", | ||
}, | ||
} | ||
`; | ||
|
||
exports[`common-template generator should generate files for { template: 'license', anchor: 'hello-world' } template with %s anchor 1`] = ` | ||
{ | ||
"LICENSE": { | ||
"content": [ | ||
"MIT License", | ||
"Copyright (c) 2023 test", | ||
"Permission is hereby granted, free of charge, to any person obtaining a copy", | ||
"of this software and associated documentation files (the "Software"), to deal", | ||
"in the Software without restriction, including without limitation the rights", | ||
"to use, copy, modify, merge, publish, distribute, sublicense, and/or sell", | ||
"copies of the Software, and to permit persons to whom the Software is", | ||
"furnished to do so, subject to the following conditions:", | ||
"The above copyright notice and this permission notice shall be included in all", | ||
"copies or substantial portions of the Software.", | ||
"THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR", | ||
"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,", | ||
"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE", | ||
"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER", | ||
"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,", | ||
"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE", | ||
"SOFTWARE.", | ||
], | ||
"isBinary": false, | ||
"path": "test/LICENSE", | ||
}, | ||
} | ||
`; | ||
|
||
exports[`common-template generator should generate files for { template: 'license', anchor: 'none' } template with %s anchor 1`] = ` | ||
{ | ||
"LICENSE": { | ||
"content": [ | ||
"MIT License", | ||
"Copyright (c) 2023 test", | ||
"Permission is hereby granted, free of charge, to any person obtaining a copy", | ||
"of this software and associated documentation files (the "Software"), to deal", | ||
"in the Software without restriction, including without limitation the rights", | ||
"to use, copy, modify, merge, publish, distribute, sublicense, and/or sell", | ||
"copies of the Software, and to permit persons to whom the Software is", | ||
"furnished to do so, subject to the following conditions:", | ||
"The above copyright notice and this permission notice shall be included in all", | ||
"copies or substantial portions of the Software.", | ||
"THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR", | ||
"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,", | ||
"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE", | ||
"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER", | ||
"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,", | ||
"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE", | ||
"SOFTWARE.", | ||
], | ||
"isBinary": false, | ||
"path": "test/LICENSE", | ||
}, | ||
} | ||
`; | ||
|
||
exports[`common-template generator should generate files for { template: 'readme', anchor: 'counter' } template with %s anchor 1`] = ` | ||
{ | ||
"README.md": { | ||
"content": [ | ||
"# test", | ||
"This project is generated with the [create-solana-dapp](https://github.com/solana-developers/create-solana-dapp) generator.", | ||
"## Getting Started", | ||
"### Prerequisites", | ||
"- Node v18.18.0 or higher", | ||
"- Rust v1.70.0 or higher", | ||
"- Anchor CLI 0.29.0 or higher", | ||
"- Solana CLI 1.17.0 or higher", | ||
"### Installation", | ||
"#### Clone the repo", | ||
"\`\`\`shell", | ||
"git clone <repo-url>", | ||
"cd <repo-name>", | ||
"\`\`\`", | ||
"#### Install Dependencies", | ||
"\`\`\`shell", | ||
"yarn install", | ||
"\`\`\`", | ||
"#### Start the web app", | ||
"\`\`\`", | ||
"yarn dev", | ||
"\`\`\`", | ||
"## Apps", | ||
"### anchor", | ||
"This is a Solana program written in Rust using the Anchor framework.", | ||
"#### Commands", | ||
"You can use any normal anchor commands. Either move to the \`anchor\` directory and run the \`anchor\` command or prefix the command with \`yarn\`, eg: \`yarn anchor\`.", | ||
"#### Sync the program id:", | ||
"Running this command will create a new keypair in the \`anchor/target/deploy\` directory and save the address to the Anchor config file and update the \`declare_id!\` macro in the \`./src/lib.rs\` file of the program.", | ||
"You will manually need to update the constant in \`anchor/lib/counter-exports.ts\` to match the new program id.", | ||
"\`\`\`shell", | ||
"yarn anchor keys sync", | ||
"\`\`\`", | ||
"#### Build the program:", | ||
"\`\`\`shell", | ||
"yarn anchor-build", | ||
"\`\`\`", | ||
"#### Start the test validator with the program deployed:", | ||
"\`\`\`shell", | ||
"yarn anchor-localnet", | ||
"\`\`\`", | ||
"#### Run the tests", | ||
"\`\`\`shell", | ||
"yarn anchor-test", | ||
"\`\`\`", | ||
"#### Deploy to Devnet", | ||
"\`\`\`shell", | ||
"yarn anchor deploy --provider.cluster devnet", | ||
"\`\`\`", | ||
"### web", | ||
"This is a React app that uses the Anchor generated client to interact with the Solana program.", | ||
"#### Commands", | ||
"Start the web app", | ||
"\`\`\`shell", | ||
"yarn dev", | ||
"\`\`\`", | ||
"Build the web app", | ||
"\`\`\`shell", | ||
"yarn build", | ||
"\`\`\`", | ||
], | ||
"isBinary": false, | ||
"path": "test/README.md", | ||
}, | ||
} | ||
`; | ||
|
||
exports[`common-template generator should generate files for { template: 'readme', anchor: 'hello-world' } template with %s anchor 1`] = ` | ||
{ | ||
"README.md": { | ||
"content": [ | ||
"# test", | ||
"This project is generated with the [create-solana-dapp](https://github.com/solana-developers/create-solana-dapp) generator.", | ||
"## Getting Started", | ||
"### Prerequisites", | ||
"- Node v18.18.0 or higher", | ||
"- Rust v1.70.0 or higher", | ||
"- Anchor CLI 0.29.0 or higher", | ||
"- Solana CLI 1.17.0 or higher", | ||
"### Installation", | ||
"#### Clone the repo", | ||
"\`\`\`shell", | ||
"git clone <repo-url>", | ||
"cd <repo-name>", | ||
"\`\`\`", | ||
"#### Install Dependencies", | ||
"\`\`\`shell", | ||
"yarn install", | ||
"\`\`\`", | ||
"#### Start the web app", | ||
"\`\`\`", | ||
"yarn dev", | ||
"\`\`\`", | ||
"## Apps", | ||
"### anchor", | ||
"This is a Solana program written in Rust using the Anchor framework.", | ||
"#### Commands", | ||
"You can use any normal anchor commands. Either move to the \`anchor\` directory and run the \`anchor\` command or prefix the command with \`yarn\`, eg: \`yarn anchor\`.", | ||
"#### Sync the program id:", | ||
"Running this command will create a new keypair in the \`anchor/target/deploy\` directory and save the address to the Anchor config file and update the \`declare_id!\` macro in the \`./src/lib.rs\` file of the program.", | ||
"You will manually need to update the constant in \`anchor/lib/hello-world-exports.ts\` to match the new program id.", | ||
"\`\`\`shell", | ||
"yarn anchor keys sync", | ||
"\`\`\`", | ||
"#### Build the program:", | ||
"\`\`\`shell", | ||
"yarn anchor-build", | ||
"\`\`\`", | ||
"#### Start the test validator with the program deployed:", | ||
"\`\`\`shell", | ||
"yarn anchor-localnet", | ||
"\`\`\`", | ||
"#### Run the tests", | ||
"\`\`\`shell", | ||
"yarn anchor-test", | ||
"\`\`\`", | ||
"#### Deploy to Devnet", | ||
"\`\`\`shell", | ||
"yarn anchor deploy --provider.cluster devnet", | ||
"\`\`\`", | ||
"### web", | ||
"This is a React app that uses the Anchor generated client to interact with the Solana program.", | ||
"#### Commands", | ||
"Start the web app", | ||
"\`\`\`shell", | ||
"yarn dev", | ||
"\`\`\`", | ||
"Build the web app", | ||
"\`\`\`shell", | ||
"yarn build", | ||
"\`\`\`", | ||
], | ||
"isBinary": false, | ||
"path": "test/README.md", | ||
}, | ||
} | ||
`; | ||
|
||
exports[`common-template generator should generate files for { template: 'readme', anchor: 'none' } template with %s anchor 1`] = ` | ||
{ | ||
"README.md": { | ||
"content": [ | ||
"# test", | ||
"This project is generated with the [create-solana-dapp](https://github.com/solana-developers/create-solana-dapp) generator.", | ||
"## Getting Started", | ||
"### Prerequisites", | ||
"- Node v18.18.0 or higher", | ||
"### Installation", | ||
"#### Clone the repo", | ||
"\`\`\`shell", | ||
"git clone <repo-url>", | ||
"cd <repo-name>", | ||
"\`\`\`", | ||
"#### Install Dependencies", | ||
"\`\`\`shell", | ||
"yarn install", | ||
"\`\`\`", | ||
"#### Start the web app", | ||
"\`\`\`", | ||
"yarn dev", | ||
"\`\`\`", | ||
"## Apps", | ||
"### web", | ||
"This is a React app.", | ||
"#### Commands", | ||
"Start the web app", | ||
"\`\`\`shell", | ||
"yarn dev", | ||
"\`\`\`", | ||
"Build the web app", | ||
"\`\`\`shell", | ||
"yarn build", | ||
"\`\`\`", | ||
], | ||
"isBinary": false, | ||
"path": "test/README.md", | ||
}, | ||
} | ||
`; |
34 changes: 34 additions & 0 deletions
34
packages/preset-common/src/generators/common-template/common-template-generator.spec.ts
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,34 @@ | ||
import { Tree } from '@nx/devkit' | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing' | ||
import { getRecursiveFileContents } from '../../utils/get-recursive-file-contents' | ||
import { commonTemplateGenerator } from './common-template-generator' | ||
import { CommonTemplateSchema } from './common-template-schema' | ||
|
||
describe('common-template generator', () => { | ||
let tree: Tree | ||
const options: CommonTemplateSchema = { | ||
name: 'test', | ||
template: 'license', | ||
directory: 'test', | ||
anchor: 'none', | ||
anchorName: 'anchor', | ||
npmScope: 'test', | ||
webName: 'test', | ||
} | ||
const templates: CommonTemplateSchema['template'][] = ['license', 'readme'] | ||
const anchor: CommonTemplateSchema['anchor'][] = ['none', 'counter', 'hello-world'] | ||
|
||
const matrix = templates.map((template) => anchor.map((anchor) => ({ template, anchor }))).flat() | ||
process.env['USER'] = 'test' | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace() | ||
}) | ||
|
||
it.each(matrix)('should generate files for %s template with %s anchor', async ({ template, anchor }) => { | ||
await commonTemplateGenerator(tree, { ...options, template, anchor }) | ||
|
||
const contents = getRecursiveFileContents(tree, options.directory) | ||
expect(contents).toMatchSnapshot() | ||
}) | ||
}) |
22 changes: 22 additions & 0 deletions
22
packages/preset-common/src/generators/common-template/common-template-generator.ts
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,22 @@ | ||
import { generateFiles, Tree } from '@nx/devkit' | ||
import * as path from 'path' | ||
import { genericSubstitutions } from '../../utils/generic-substitutions' | ||
import { CommonTemplateSchema } from './common-template-schema' | ||
|
||
export async function commonTemplateGenerator(tree: Tree, options: CommonTemplateSchema, templatePath: string = '') { | ||
const substitutions = genericSubstitutions({ | ||
anchor: options.anchor, | ||
anchorName: options.anchorName, | ||
licenseAuthor: options.licenseAuthor, | ||
name: options.webName, | ||
npmScope: options.npmScope, | ||
preset: options.preset, | ||
}) | ||
generateFiles(tree, path.join(__dirname, 'files', options.template, templatePath), options.directory, { | ||
...options, | ||
...substitutions, | ||
fileNameUnderscore: substitutions.fileName.replace(/-/g, '_'), | ||
}) | ||
} | ||
|
||
export default commonTemplateGenerator |
Oops, something went wrong.