UNPKG

1.08 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.move = void 0;
11const core_1 = require("@angular-devkit/core");
12const base_1 = require("./base");
13function move(from, to) {
14 if (to === undefined) {
15 to = from;
16 from = '/';
17 }
18 const fromPath = (0, core_1.normalize)('/' + from);
19 const toPath = (0, core_1.normalize)('/' + to);
20 if (fromPath === toPath) {
21 return base_1.noop;
22 }
23 return (tree) => {
24 if (tree.exists(fromPath)) {
25 // fromPath is a file
26 tree.rename(fromPath, toPath);
27 }
28 else {
29 // fromPath is a directory
30 tree.getDir(fromPath).visit((path) => {
31 tree.rename(path, (0, core_1.join)(toPath, path.slice(fromPath.length)));
32 });
33 }
34 return tree;
35 };
36}
37exports.move = move;