-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Craigory Coppola <craigory.coppola@universalplant.com>
- Loading branch information
1 parent
77d8e6e
commit 621627d
Showing
24 changed files
with
376 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
"utils", | ||
"typescript", | ||
"nxdoc", | ||
"nx-ghpages", | ||
"docs-site", | ||
"ci", | ||
"repo" | ||
|
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,14 @@ | ||
module.exports = { | ||
displayName: 'nx-ghpages-e2e', | ||
preset: '../../jest.preset.js', | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: '<rootDir>/tsconfig.spec.json', | ||
}, | ||
}, | ||
transform: { | ||
'^.+\\.[tj]s$': 'ts-jest', | ||
}, | ||
moduleFileExtensions: ['ts', 'js', 'html'], | ||
coverageDirectory: '../../coverage/apps\nx-ghpages-e2e', | ||
}; |
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,48 @@ | ||
import { | ||
checkFilesExist, | ||
ensureNxProject, | ||
readJson, | ||
runNxCommandAsync, | ||
uniq, | ||
} from '@nrwl/nx-plugin/testing'; | ||
describe('nx-ghpages e2e', () => { | ||
it('should create nx-ghpages', async (done) => { | ||
const plugin = uniq('nx-ghpages'); | ||
ensureNxProject('@nx-dotnet/nx-ghpages', 'dist/packages/nx-ghpages'); | ||
await runNxCommandAsync( | ||
`generate @nx-dotnet/nx-ghpages:nx-ghpages ${plugin}`, | ||
); | ||
|
||
const result = await runNxCommandAsync(`build ${plugin}`); | ||
expect(result.stdout).toContain('Executor ran'); | ||
|
||
done(); | ||
}); | ||
|
||
describe('--directory', () => { | ||
it('should create src in the specified directory', async (done) => { | ||
const plugin = uniq('nx-ghpages'); | ||
ensureNxProject('@nx-dotnet/nx-ghpages', 'dist/packages/nx-ghpages'); | ||
await runNxCommandAsync( | ||
`generate @nx-dotnet/nx-ghpages:nx-ghpages ${plugin} --directory subdir`, | ||
); | ||
expect(() => | ||
checkFilesExist(`libs/subdir/${plugin}/src/index.ts`), | ||
).not.toThrow(); | ||
done(); | ||
}); | ||
}); | ||
|
||
describe('--tags', () => { | ||
it('should add tags to nx.json', async (done) => { | ||
const plugin = uniq('nx-ghpages'); | ||
ensureNxProject('@nx-dotnet/nx-ghpages', 'dist/packages/nx-ghpages'); | ||
await runNxCommandAsync( | ||
`generate @nx-dotnet/nx-ghpages:nx-ghpages ${plugin} --tags e2etag,e2ePackage`, | ||
); | ||
const nxJson = readJson('nx.json'); | ||
expect(nxJson.projects[plugin].tags).toEqual(['e2etag', 'e2ePackage']); | ||
done(); | ||
}); | ||
}); | ||
}); |
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,13 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.e2e.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
] | ||
} |
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 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"module": "commonjs", | ||
"types": ["jest", "node"] | ||
}, | ||
"include": ["**/*.spec.ts", "**/*.d.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
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,3 @@ | ||
{ | ||
"presets": [["@nrwl/web/babel", { "useBuiltIns": "usage" }]] | ||
} |
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,21 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"parserOptions": { | ||
"project": ["packages/nx-ghpages/tsconfig.*?.json"] | ||
}, | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
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 @@ | ||
# nx-ghpages | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Running unit tests | ||
|
||
Run `nx test nx-ghpages` to execute the unit tests via [Jest](https://jestjs.io). |
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 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"executors": { | ||
"deploy": { | ||
"implementation": "./src/executors/deploy/executor", | ||
"schema": "./src/executors/deploy/schema.json", | ||
"description": "Deploy a site to the gh-pages branch of a specified repository." | ||
} | ||
} | ||
} |
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 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"name": "nx-ghpages", | ||
"version": "0.0.1", | ||
"generators": {} | ||
} |
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,14 @@ | ||
module.exports = { | ||
displayName: 'nx-ghpages', | ||
preset: '../../jest.preset.js', | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: '<rootDir>/tsconfig.spec.json', | ||
}, | ||
}, | ||
transform: { | ||
'^.+\\.[tj]sx?$': 'ts-jest', | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], | ||
coverageDirectory: '../../coverage/packages/nx-ghpages', | ||
}; |
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": "@nx-dotnet/nx-ghpages", | ||
"version": "0.0.1", | ||
"main": "src/index.js", | ||
"generators": "./generators.json", | ||
"executors": "./executors.json" | ||
} |
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,11 @@ | ||
import { BuildExecutorSchema } from './schema'; | ||
import executor from './executor'; | ||
|
||
const options: BuildExecutorSchema = {}; | ||
|
||
describe('Build Executor', () => { | ||
it('can run', async () => { | ||
const output = await executor(options); | ||
expect(output.success).toBe(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,64 @@ | ||
import { BuildExecutorSchema } from './schema'; | ||
import { exec as execCallback } from 'child_process'; | ||
import { stat } from 'fs'; | ||
import { dirname, join } from 'path'; | ||
import { promisify } from 'util'; | ||
import { logger } from '@nrwl/devkit'; | ||
|
||
const exec = promisify(execCallback); | ||
|
||
async function exists(path: string) { | ||
return new Promise((resolve) => { | ||
stat(path, (err) => resolve(err ? false : true)); | ||
}); | ||
} | ||
|
||
export default async function deployExecutor(options: BuildExecutorSchema) { | ||
const directory = join(await findWorkspaceRoot(), options.directory); | ||
|
||
if (!(await exists(directory))) { | ||
logger.error(`Output directory does not exist! ${directory}`); | ||
return { | ||
success: false, | ||
}; | ||
} | ||
|
||
if (!(await exists(join(directory, '.git')))) { | ||
logger.info( | ||
`Git repository not found, initializing a blank repository ${directory}`, | ||
); | ||
await exec('git init', { cwd: directory }); | ||
} | ||
|
||
try { | ||
await exec(`git remote add ${options.remoteName} ${options.remote}`, { | ||
cwd: directory, | ||
}); | ||
} catch { | ||
await exec(`git remote set-url ${options.remoteName} ${options.remote}`, { | ||
cwd: directory, | ||
}); | ||
} | ||
|
||
await exec( | ||
`git add . && git commit -m "deploy to gh-pages (nx-ghpages)" && git push --set-upstream ${options.remoteName} gh-pages`, | ||
{ cwd: directory }, | ||
); | ||
|
||
return { | ||
success: true, | ||
}; | ||
} | ||
|
||
async function findWorkspaceRoot(dir: string = process.cwd()): Promise<string> { | ||
if (dirname(dir) === dir) { | ||
throw new Error(`The cwd isn't part of an Nx workspace`); | ||
} | ||
if ( | ||
(await exists(join(dir, 'angular.json'))) || | ||
(await exists(join(dir, 'workspace.json'))) | ||
) { | ||
return dir; | ||
} | ||
return findWorkspaceRoot(dirname(dir)); | ||
} |
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,5 @@ | ||
export interface BuildExecutorSchema { | ||
remote: string; | ||
directory: string; | ||
remoteName: string; | ||
} |
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,23 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"cli": "nx", | ||
"title": "Deploy", | ||
"description": "Deploy a page to a specified repository's gh-pages branch.", | ||
"type": "object", | ||
"properties": { | ||
"remote": { | ||
"type": "string", | ||
"description": "URL for the git remote to deploy to." | ||
}, | ||
"directory": { | ||
"type": "string", | ||
"description": "Directory to push to gh-pages" | ||
}, | ||
"remoteName": { | ||
"type": "string", | ||
"description": "Name of the remote to push to", | ||
"default": "origin" | ||
} | ||
}, | ||
"required": ["remote", "directory"] | ||
} |
Empty file.
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,13 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
] | ||
} |
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,11 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"outDir": "../../dist/out-tsc", | ||
"declaration": true, | ||
"types": ["node"] | ||
}, | ||
"exclude": ["**/*.spec.ts"], | ||
"include": ["**/*.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,15 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"module": "commonjs", | ||
"types": ["jest", "node"] | ||
}, | ||
"include": [ | ||
"**/*.spec.ts", | ||
"**/*.spec.tsx", | ||
"**/*.spec.js", | ||
"**/*.spec.jsx", | ||
"**/*.d.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
Oops, something went wrong.