-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: removed "schematics-utilities" package and dependent code (#91)
* chore: update github action to publish package updated github action so that whenever we create a new release then only it will be triggered and publish the package to npm * feat: removed "schematics-utilities" package and dependent code and replaced it with native workspace methods
- Loading branch information
1 parent
4dff6e6
commit b445981
Showing
5 changed files
with
93 additions
and
45 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
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,5 +1,3 @@ | ||
export interface NgAddOptions { | ||
project: string | undefined; | ||
siteID: string; | ||
netlifyToken: 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,64 @@ | ||
import { virtualFs, workspaces } from '@angular-devkit/core'; | ||
import { noop, Rule, SchematicsException, Tree } from '@angular-devkit/schematics'; | ||
|
||
/* Below code reference is taken from Angular CLI project. | ||
https://github.com/angular/angular-cli/blob/master/packages/schematics/angular/utility/workspace.ts | ||
These methods are not part of public APIs so we should not be referencing those methods. | ||
that's why added below method here. | ||
*/ | ||
|
||
function createHost(tree: Tree): workspaces.WorkspaceHost { | ||
return { | ||
async readFile(path: string): Promise<string> { | ||
const data = tree.read(path); | ||
if (!data) { | ||
throw new SchematicsException('File not found.'); | ||
} | ||
return virtualFs.fileBufferToString(data); | ||
}, | ||
async writeFile(path: string, data: string): Promise<void> { | ||
return tree.overwrite(path, data); | ||
}, | ||
async isDirectory(path: string): Promise<boolean> { | ||
return !tree.exists(path) && tree.getDir(path).subfiles.length > 0; | ||
}, | ||
async isFile(path: string): Promise<boolean> { | ||
return tree.exists(path); | ||
}, | ||
}; | ||
} | ||
|
||
export async function getWorkspace(tree: Tree, path = '/') : Promise<workspaces.WorkspaceDefinition> { | ||
const host = createHost(tree); | ||
const { workspace } = await workspaces.readWorkspace(path, host); | ||
return workspace; | ||
} | ||
|
||
export function updateWorkspace( | ||
updater: (workspace: workspaces.WorkspaceDefinition) => void | Rule | PromiseLike<void | Rule>, | ||
): Rule; | ||
export function updateWorkspace(workspace: workspaces.WorkspaceDefinition): Rule; | ||
export function updateWorkspace( | ||
updaterOrWorkspace: | ||
| workspaces.WorkspaceDefinition | ||
| ((workspace: workspaces.WorkspaceDefinition) => void | Rule | PromiseLike<void | Rule>), | ||
): Rule { | ||
return async (tree: Tree) => { | ||
const host = createHost(tree); | ||
|
||
if (typeof updaterOrWorkspace === 'function') { | ||
const { workspace } = await workspaces.readWorkspace('/', host); | ||
|
||
const result = await updaterOrWorkspace(workspace); | ||
|
||
await workspaces.writeWorkspace(workspace, host); | ||
|
||
return result || noop; | ||
} else { | ||
await workspaces.writeWorkspace(updaterOrWorkspace, host); | ||
|
||
return noop; | ||
} | ||
}; | ||
} |
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