Skip to content

Commit

Permalink
feat: add packages preset
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Dec 1, 2023
1 parent 8839f40 commit e9801bd
Show file tree
Hide file tree
Showing 50 changed files with 790 additions and 640 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"scripts": {
"generate-features": "nx g @pubkey-ui/generators:features --directory apps/web/src/app/features",
"generate-core-components": "nx g @pubkey-ui/generators:components --directory packages/core/src/lib --prefix ui",
"local-registry": "nx run @pubkey-ui/source:local-registry",
"prelocal-publish": "ts-node tools/scripts/ensure-local-registry.ts",
"local-publish": "nx run-many --targets publish --tag local --ver ",
"sync-schemas": "ts-node ./tools/scripts/sync-schemas.ts"
},
"private": true,
Expand All @@ -18,9 +21,12 @@
"@mantine/notifications": "^7.2.2",
"@mantine/spotlight": "^7.2.2",
"@nx/devkit": "17.1.3",
"@nx/linter": "^17.1.3",
"@solana-developers/preset-anchor": "2.0.0-beta.2",
"@swc/helpers": "~0.5.2",
"@tabler/icons-react": "^2.42.0",
"core-js": "^3.33.3",
"create-nx-workspace": "17.1.3",
"dayjs": "^1.11.10",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
25 changes: 25 additions & 0 deletions packages/create-pubkey-ui-app/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": "error"
}
}
]
}
11 changes: 11 additions & 0 deletions packages/create-pubkey-ui-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# create-pubkey-ui-app

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build create-pubkey-ui-app` to build the library.

## Running unit tests

Run `nx test create-pubkey-ui-app` to execute the unit tests via [Jest](https://jestjs.io).
28 changes: 28 additions & 0 deletions packages/create-pubkey-ui-app/bin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env node

import { createWorkspace } from 'create-nx-workspace'

async function main() {
const name = process.argv[2] // TODO: use libraries like yargs or enquirer to set your workspace name
if (!name) {
throw new Error('Please provide a name for the workspace')
}

console.log(`Creating the workspace: ${name}`)

// This assumes "@pubkey-ui/generators" and "create-pubkey-ui-app" are at the same version
// eslint-disable-next-line @typescript-eslint/no-var-requires
const presetVersion = require('../package.json').version

// TODO: update below to customize the workspace
const { directory } = await createWorkspace(`@pubkey-ui/generators@${presetVersion}`, {
name,
nxCloud: false,
packageManager: 'npm',
webName: 'web',
})

console.log(`Successfully created the workspace: ${directory}.`)
}

main()
10 changes: 10 additions & 0 deletions packages/create-pubkey-ui-app/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable */
export default {
displayName: 'create-pubkey-ui-app',
preset: '../../jest.preset.js',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/packages/create-pubkey-ui-app',
}
13 changes: 13 additions & 0 deletions packages/create-pubkey-ui-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "create-pubkey-ui-app",
"version": "0.0.1",
"dependencies": {
"create-nx-workspace": "17.1.3"
},
"type": "commonjs",
"main": "./src/index.js",
"typings": "./src/index.d.ts",
"bin": {
"create-pubkey-ui-app": "./bin/index.js"
}
}
38 changes: 38 additions & 0 deletions packages/create-pubkey-ui-app/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "create-pubkey-ui-app",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/create-pubkey-ui-app/bin",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/create-pubkey-ui-app",
"main": "packages/create-pubkey-ui-app/bin/index.ts",
"tsConfig": "packages/create-pubkey-ui-app/tsconfig.lib.json",
"assets": ["packages/create-pubkey-ui-app/*.md"]
}
},
"publish": {
"command": "node tools/scripts/publish.mjs create-pubkey-ui-app {args.ver} {args.tag}",
"dependsOn": ["build"]
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["packages/create-pubkey-ui-app/**/*.ts", "packages/create-pubkey-ui-app/package.json"]
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "packages/create-pubkey-ui-app/jest.config.ts"
}
}
},
"tags": [],
"implicitDependencies": ["generators"]
}
16 changes: 16 additions & 0 deletions packages/create-pubkey-ui-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs"
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
10 changes: 10 additions & 0 deletions packages/create-pubkey-ui-app/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"include": ["src/**/*.ts", "bin/**/*.ts"],
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
}
9 changes: 9 additions & 0 deletions packages/create-pubkey-ui-app/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"]
}
52 changes: 52 additions & 0 deletions packages/generators-e2e/src/create-pubkey-ui-app.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { execSync } from 'child_process'
import { join, dirname } from 'path'
import { mkdirSync, rmSync } from 'fs'

describe('create-pubkey-ui-app', () => {
let projectDirectory: string

afterAll(() => {
// Cleanup the test project
rmSync(projectDirectory, {
recursive: true,
force: true,
})
})

it('should be installed', () => {
projectDirectory = createTestProject()

// npm ls will fail if the package is not installed properly
execSync('npm ls @pubkey-ui/generators', {
cwd: projectDirectory,
stdio: 'inherit',
})
})
})

/**
* Creates a test project with create-nx-workspace and installs the plugin
* @returns The directory where the test project was created
*/
function createTestProject(extraArgs = '') {
const projectName = 'test-project'
const projectDirectory = join(process.cwd(), 'tmp', projectName)

// Ensure projectDirectory is empty
rmSync(projectDirectory, {
recursive: true,
force: true,
})
mkdirSync(dirname(projectDirectory), {
recursive: true,
})

execSync(`npx --yes create-pubkey-ui-app@e2e ${projectName} ${extraArgs}`, {
cwd: dirname(projectDirectory),
stdio: 'inherit',
env: process.env,
})
console.log(`Created test project in "${projectDirectory}"`)

return projectDirectory
}
16 changes: 11 additions & 5 deletions packages/generators/generators.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"generators": {
"application": {
"factory": "./src/generators/application/application-generator",
"schema": "./src/generators/application/application-generator-schema.json",
"description": "application generator",
"aliases": ["preset"]
},
"component": {
"factory": "./src/generators/component/component-generator",
"schema": "./src/generators/component/component-generator-schema.json",
Expand All @@ -10,11 +16,6 @@
"schema": "./src/generators/components/components-generator-schema.json",
"description": "components generator"
},
"theme": {
"factory": "./src/generators/theme/theme-generator",
"schema": "./src/generators/theme/theme-generator-schema.json",
"description": "theme generator"
},
"feature": {
"factory": "./src/generators/feature/feature-generator",
"schema": "./src/generators/feature/feature-generator-schema.json",
Expand All @@ -24,6 +25,11 @@
"factory": "./src/generators/features/features-generator",
"schema": "./src/generators/features/features-generator-schema.json",
"description": "features generator"
},
"theme": {
"factory": "./src/generators/theme/theme-generator",
"schema": "./src/generators/theme/theme-generator-schema.json",
"description": "theme generator"
}
}
}
5 changes: 4 additions & 1 deletion packages/generators/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"dependencies": {
"@nx/devkit": "17.1.3",
"tslib": "^2.3.0",
"@nx/js": "17.1.3"
"@nx/js": "17.1.3",
"@nx/linter": "^17.1.3",
"@nx/react": "17.1.3",
"@solana-developers/preset-anchor": "2.0.0-beta.2"
},
"type": "commonjs",
"main": "./src/index.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* eslint-disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
*/

export interface ApplicationGeneratorSchema {
/**
* Name of the application
*/
name: string
/**
* Name of the web application (overrides name)
*/
webName?: string
/**
* Skip formatting files
*/
skipFormat?: boolean
/**
* Anchor template to use
*/
anchor?: 'none' | 'counter' | 'hello-world'
/**
* Anchor project name
*/
anchorName?: string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"$schema": "http://json-schema.org/schema",
"$id": "ApplicationGeneratorSchema",
"title": "",
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Name of the application",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "What name would you like to use?"
},
"webName": {
"type": "string",
"description": "Name of the web application (overrides name)"
},
"skipFormat": {
"description": "Skip formatting files",
"type": "boolean",
"default": false,
"x-priority": "internal"
},
"anchor": {
"type": "string",
"description": "Anchor template to use",
"enum": ["none", "counter", "hello-world"],
"default": "counter"
},
"anchorName": {
"type": "string",
"description": "Anchor project name",
"default": "anchor"
}
},
"required": ["name"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'
import { Tree, readProjectConfiguration } from '@nx/devkit'

import { applicationGenerator } from './application-generator'
import { ApplicationGeneratorSchema } from './application-generator-schema'

describe('application generator', () => {
let tree: Tree
const options: ApplicationGeneratorSchema = { name: 'test' }

beforeEach(() => {
tree = createTreeWithEmptyWorkspace()
})

it('should run successfully', async () => {
await applicationGenerator(tree, options)
const config = readProjectConfiguration(tree, 'test')
expect(config).toBeDefined()
})
})
Loading

0 comments on commit e9801bd

Please sign in to comment.