task-script-support-cli 0.2.6 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +1 -1
- package/dist/src/services/templater-service.d.ts +24 -0
- package/dist/src/services/templater-service.d.ts.map +1 -0
- package/dist/src/services/templater-service.js +134 -0
- package/dist/src/services/templater-service.js.map +1 -0
- package/dist/src/tasks/create-new-project.d.ts +12 -3
- package/dist/src/tasks/create-new-project.d.ts.map +1 -1
- package/dist/src/tasks/create-new-project.js +25 -15
- package/dist/src/tasks/create-new-project.js.map +1 -1
- package/dist/src/tasks/stdout/print-generated-results.d.ts +3 -1
- package/dist/src/tasks/stdout/print-generated-results.d.ts.map +1 -1
- package/dist/src/tasks/stdout/print-generated-results.js +14 -5
- package/dist/src/tasks/stdout/print-generated-results.js.map +1 -1
- package/package.json +1 -1
- package/src/services/templater-service.ts +136 -0
- package/src/tasks/create-new-project.ts +28 -16
- package/src/tasks/stdout/print-generated-results.ts +21 -4
- package/assets/yargs-template/task-runner/templater.sh +0 -69
- package/dist/assets/yargs-template/task-runner/templater.sh +0 -69
package/dist/package.json
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SpawnService } from "./spawn-service";
|
|
2
|
+
import { LogService } from "./log-service";
|
|
3
|
+
export declare class TemplateService {
|
|
4
|
+
private spawnService;
|
|
5
|
+
private logger;
|
|
6
|
+
private loggerName;
|
|
7
|
+
private outputName;
|
|
8
|
+
private sourceDir;
|
|
9
|
+
private destination;
|
|
10
|
+
private dirListToCopy;
|
|
11
|
+
private fileListToCopy;
|
|
12
|
+
private nameRefList;
|
|
13
|
+
constructor(spawnService: SpawnService, logger: LogService);
|
|
14
|
+
runTemplater(outputName: string): Promise<void>;
|
|
15
|
+
private ensureDestinationExists;
|
|
16
|
+
private copyDirectories;
|
|
17
|
+
private copyFiles;
|
|
18
|
+
private fixNaming;
|
|
19
|
+
private createGitignore;
|
|
20
|
+
private removeDoubleNestedTestsDirectory;
|
|
21
|
+
private renameTaskRunner;
|
|
22
|
+
private initializeWithGit;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=templater-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templater-service.d.ts","sourceRoot":"./src/","sources":["src/services/templater-service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAM3C,qBACa,eAAe;IA2BxB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,MAAM;IA3BhB,OAAO,CAAC,UAAU,CAAsB;IAExC,OAAO,CAAC,UAAU,CAAU;IAC5B,OAAO,CAAC,SAAS,CAAU;IAC3B,OAAO,CAAC,WAAW,CAAU;IAE7B,OAAO,CAAC,aAAa,CAAyC;IAC9D,OAAO,CAAC,cAAc,CAUpB;IACF,OAAO,CAAC,WAAW,CAKjB;gBAGQ,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,UAAU;IASf,YAAY,CAAC,UAAU,EAAE,MAAM;YAoB9B,uBAAuB;YAMvB,eAAe;YASf,SAAS;YAST,SAAS;YAWT,eAAe;YAOf,gCAAgC;YAUhC,gBAAgB;YAOhB,iBAAiB;CAQhC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.TemplateService = void 0;
|
|
16
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
17
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
18
|
+
const tsyringe_1 = require("tsyringe");
|
|
19
|
+
const spawn_service_1 = require("./spawn-service");
|
|
20
|
+
const log_service_1 = require("./log-service");
|
|
21
|
+
const gitignoreContent = `node_modules
|
|
22
|
+
dist
|
|
23
|
+
.env`;
|
|
24
|
+
let TemplateService = class TemplateService {
|
|
25
|
+
spawnService;
|
|
26
|
+
logger;
|
|
27
|
+
loggerName = "Template Service";
|
|
28
|
+
outputName;
|
|
29
|
+
sourceDir;
|
|
30
|
+
destination;
|
|
31
|
+
dirListToCopy = [".vscode", "src", "tests"];
|
|
32
|
+
fileListToCopy = [
|
|
33
|
+
".prettierignore",
|
|
34
|
+
".prettierrc",
|
|
35
|
+
"task-runner",
|
|
36
|
+
"install-link.sh",
|
|
37
|
+
"eslint.config.ts",
|
|
38
|
+
"vitest.config.ts",
|
|
39
|
+
"package-lock.json",
|
|
40
|
+
"package.json",
|
|
41
|
+
"tsconfig.json",
|
|
42
|
+
];
|
|
43
|
+
nameRefList = [
|
|
44
|
+
// files that have name references
|
|
45
|
+
"package.json",
|
|
46
|
+
"package-lock.json",
|
|
47
|
+
"install-link.sh",
|
|
48
|
+
];
|
|
49
|
+
constructor(spawnService, logger) {
|
|
50
|
+
this.spawnService = spawnService;
|
|
51
|
+
this.logger = logger;
|
|
52
|
+
this.sourceDir = node_path_1.default.join(__dirname, "../../assets/yargs-template/task-runner/");
|
|
53
|
+
this.logger.setPrefix(this.loggerName);
|
|
54
|
+
}
|
|
55
|
+
async runTemplater(outputName) {
|
|
56
|
+
if (!outputName) {
|
|
57
|
+
throw new Error("Missing required parameter. Usage: Templater <output-name>");
|
|
58
|
+
}
|
|
59
|
+
this.outputName = outputName;
|
|
60
|
+
this.destination = node_path_1.default.join(process.cwd(), outputName);
|
|
61
|
+
await this.ensureDestinationExists();
|
|
62
|
+
await this.copyDirectories();
|
|
63
|
+
await this.copyFiles();
|
|
64
|
+
await this.fixNaming();
|
|
65
|
+
await this.createGitignore();
|
|
66
|
+
await this.removeDoubleNestedTestsDirectory();
|
|
67
|
+
await this.renameTaskRunner();
|
|
68
|
+
await this.initializeWithGit();
|
|
69
|
+
await this.logger.flush();
|
|
70
|
+
}
|
|
71
|
+
async ensureDestinationExists() {
|
|
72
|
+
if (!node_fs_1.default.existsSync(this.destination)) {
|
|
73
|
+
node_fs_1.default.mkdirSync(this.destination, { recursive: true });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async copyDirectories() {
|
|
77
|
+
for (const folder of this.dirListToCopy) {
|
|
78
|
+
const src = node_path_1.default.join(this.sourceDir, folder);
|
|
79
|
+
const dest = node_path_1.default.join(this.destination, folder);
|
|
80
|
+
this.logger.debug(`Running Copy: cp -R ${src} ${dest}`);
|
|
81
|
+
node_fs_1.default.cpSync(src, dest, { recursive: true });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async copyFiles() {
|
|
85
|
+
for (const filename of this.fileListToCopy) {
|
|
86
|
+
const src = node_path_1.default.join(this.sourceDir, filename);
|
|
87
|
+
const dest = node_path_1.default.join(this.destination, filename);
|
|
88
|
+
this.logger.debug(`Running Copy: cp ${src} ${dest}`);
|
|
89
|
+
node_fs_1.default.copyFileSync(src, dest);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async fixNaming() {
|
|
93
|
+
for (const fileToEdit of this.nameRefList) {
|
|
94
|
+
const dest = node_path_1.default.join(this.destination, fileToEdit);
|
|
95
|
+
const replacePattern = new RegExp("task-runner", "g");
|
|
96
|
+
const content = node_fs_1.default
|
|
97
|
+
.readFileSync(dest, "utf-8")
|
|
98
|
+
.replaceAll(replacePattern, this.outputName);
|
|
99
|
+
node_fs_1.default.writeFileSync(dest, content);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async createGitignore() {
|
|
103
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(this.destination, ".gitignore"), gitignoreContent);
|
|
104
|
+
}
|
|
105
|
+
async removeDoubleNestedTestsDirectory() {
|
|
106
|
+
const doubleNestedTestsPath = node_path_1.default.join(this.destination, "tests", "tests");
|
|
107
|
+
if (node_fs_1.default.existsSync(doubleNestedTestsPath)) {
|
|
108
|
+
this.logger.debug(`Removing double nested tests directory: ${doubleNestedTestsPath}`);
|
|
109
|
+
node_fs_1.default.rmSync(doubleNestedTestsPath, { recursive: true });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async renameTaskRunner() {
|
|
113
|
+
const src = node_path_1.default.join(this.destination, "task-runner");
|
|
114
|
+
const dest = node_path_1.default.join(this.destination, this.outputName);
|
|
115
|
+
this.logger.debug(`Renaming task-runner to ${this.outputName}`);
|
|
116
|
+
node_fs_1.default.renameSync(src, dest);
|
|
117
|
+
}
|
|
118
|
+
async initializeWithGit() {
|
|
119
|
+
try {
|
|
120
|
+
this.logger.debug("Initializing with git");
|
|
121
|
+
this.spawnService.execSyncFromDir(`git init -b main`, this.destination);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
console.error("Error initializing git:", error.message);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
exports.TemplateService = TemplateService;
|
|
129
|
+
exports.TemplateService = TemplateService = __decorate([
|
|
130
|
+
(0, tsyringe_1.autoInjectable)(),
|
|
131
|
+
__metadata("design:paramtypes", [spawn_service_1.SpawnService,
|
|
132
|
+
log_service_1.LogService])
|
|
133
|
+
], TemplateService);
|
|
134
|
+
//# sourceMappingURL=templater-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templater-service.js","sourceRoot":"./src/","sources":["src/services/templater-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0DAA6B;AAC7B,sDAAyB;AACzB,uCAA0C;AAC1C,mDAA+C;AAC/C,+CAA2C;AAE3C,MAAM,gBAAgB,GAAG;;KAEpB,CAAC;AAGC,IAAM,eAAe,GAArB,MAAM,eAAe;IA2BhB;IACA;IA3BF,UAAU,GAAG,kBAAkB,CAAC;IAEhC,UAAU,CAAU;IACpB,SAAS,CAAU;IACnB,WAAW,CAAU;IAErB,aAAa,GAAa,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IACtD,cAAc,GAAa;QACjC,iBAAiB;QACjB,aAAa;QACb,aAAa;QACb,iBAAiB;QACjB,kBAAkB;QAClB,kBAAkB;QAClB,mBAAmB;QACnB,cAAc;QACd,eAAe;KAChB,CAAC;IACM,WAAW,GAAa;QAC9B,kCAAkC;QAClC,cAAc;QACd,mBAAmB;QACnB,iBAAiB;KAClB,CAAC;IAEF,YACU,YAA0B,EAC1B,MAAkB;QADlB,iBAAY,GAAZ,YAAY,CAAc;QAC1B,WAAM,GAAN,MAAM,CAAY;QAE1B,IAAI,CAAC,SAAS,GAAG,mBAAI,CAAC,IAAI,CACxB,SAAS,EACT,0CAA0C,CAC3C,CAAC;QACF,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACzC,CAAC;IAEM,KAAK,CAAC,YAAY,CAAC,UAAkB;QAC1C,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,mBAAI,CAAC,IAAI,CA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AM,CAAC,KAAK,CACf,2CAA2C,qBAAqB,EAAE,CACnE,CAAC;YACF,iBAAE,CAAC,MAAM,CAAC,qBAAqB,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,gBAAgB;QAC5B,MAAM,GAAG,GAAG,mBAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;QACvD,MAAM,IAAI,GAAG,mBAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAC1D,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,2BAA2B,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QAChE,iBAAE,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC3B,CAAC;IAEO,KAAK,CAAC,iBAAiB;QAC7B,IAAI,CAAC;YACH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YAC3C,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,kBAAkB,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAC1E,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAG,KAAe,CAAC,OAAO,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;CACF,CAAA;AA5HY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,yBAAc,GAAE;qCA4BS,4BAAY;QAClB,wBAAU;GA5BjB,eAAe,CA4H3B"}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { SpawnService } from "../services/spawn-service";
|
|
2
1
|
import { FileService } from "../services/file-service";
|
|
3
2
|
import { PromptService } from "../services/prompt-service";
|
|
4
3
|
import { AppTask } from "../wrappers/app-task";
|
|
4
|
+
import { TemplateService } from "../services/templater-service";
|
|
5
|
+
import { UtilService } from "../services/util-service";
|
|
5
6
|
/**
|
|
6
7
|
* Creates a New Task Script Support Project
|
|
7
8
|
*/
|
|
8
9
|
export default class CreateNewProject extends AppTask {
|
|
9
10
|
private fileService;
|
|
10
|
-
private
|
|
11
|
+
private utilService;
|
|
11
12
|
private promptService;
|
|
13
|
+
private templaterService;
|
|
12
14
|
loggerName: string;
|
|
13
|
-
constructor(fileService: FileService,
|
|
15
|
+
constructor(fileService: FileService, utilService: UtilService, promptService: PromptService, templaterService: TemplateService);
|
|
14
16
|
/**
|
|
15
17
|
* Generates a new project. Updates state with outputDestination of the
|
|
16
18
|
* newly generated project path.
|
|
@@ -22,5 +24,12 @@ export default class CreateNewProject extends AppTask {
|
|
|
22
24
|
* @returns the project name string
|
|
23
25
|
*/
|
|
24
26
|
getProjectName(): Promise<string>;
|
|
27
|
+
/**
|
|
28
|
+
* Normalize the name to the provided case or kebab.
|
|
29
|
+
*
|
|
30
|
+
* @param projectName the target project name to normalize
|
|
31
|
+
* @returns the normalized project name
|
|
32
|
+
*/
|
|
33
|
+
normalizeProjectName(projectName: string): string;
|
|
25
34
|
}
|
|
26
35
|
//# sourceMappingURL=create-new-project.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-new-project.d.ts","sourceRoot":"./src/","sources":["src/tasks/create-new-project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"create-new-project.d.ts","sourceRoot":"./src/","sources":["src/tasks/create-new-project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD;;GAEG;AAEH,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,OAAO;IAIjD,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,gBAAgB;IAN1B,UAAU,SAAwB;gBAGxB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,EAC5B,gBAAgB,EAAE,eAAe;IAK3C;;;OAGG;IACG,GAAG;IAeT;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAavC;;;;;OAKG;IACH,oBAAoB,CAAC,WAAW,EAAE,MAAM;CASzC"}
|
|
@@ -9,42 +9,41 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const spawn_service_1 = require("../services/spawn-service");
|
|
13
12
|
const file_service_1 = require("../services/file-service");
|
|
14
13
|
const prompt_service_1 = require("../services/prompt-service");
|
|
15
14
|
const process_1 = require("../types/process");
|
|
16
15
|
const app_task_1 = require("../wrappers/app-task");
|
|
17
16
|
const tsyringe_1 = require("tsyringe");
|
|
17
|
+
const templater_service_1 = require("../services/templater-service");
|
|
18
|
+
const util_service_1 = require("../services/util-service");
|
|
19
|
+
const format_1 = require("../types/format");
|
|
18
20
|
/**
|
|
19
21
|
* Creates a New Task Script Support Project
|
|
20
22
|
*/
|
|
21
23
|
let CreateNewProject = class CreateNewProject extends app_task_1.AppTask {
|
|
22
24
|
fileService;
|
|
23
|
-
|
|
25
|
+
utilService;
|
|
24
26
|
promptService;
|
|
27
|
+
templaterService;
|
|
25
28
|
loggerName = "Create New Project";
|
|
26
|
-
constructor(fileService,
|
|
29
|
+
constructor(fileService, utilService, promptService, templaterService) {
|
|
27
30
|
super();
|
|
28
31
|
this.fileService = fileService;
|
|
29
|
-
this.
|
|
32
|
+
this.utilService = utilService;
|
|
30
33
|
this.promptService = promptService;
|
|
34
|
+
this.templaterService = templaterService;
|
|
31
35
|
}
|
|
32
36
|
/**
|
|
33
37
|
* Generates a new project. Updates state with outputDestination of the
|
|
34
38
|
* newly generated project path.
|
|
35
39
|
*/
|
|
36
40
|
async run() {
|
|
37
|
-
// get path of the templater
|
|
38
|
-
const templaterFullPath = this.fileService.join(__dirname, "../../assets/yargs-template/task-runner/templater.sh");
|
|
39
|
-
// get execution directory
|
|
40
|
-
const runnerDir = this.fileService.getRunnerDir();
|
|
41
41
|
// get project name user input
|
|
42
42
|
const projectName = await this.getProjectName();
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
this.spawnService.execSyncFromDir(shCmd, runnerDir);
|
|
43
|
+
// run the templater
|
|
44
|
+
await this.templaterService.runTemplater(projectName);
|
|
46
45
|
this.setData({
|
|
47
|
-
outputDestination: this.fileService.join(
|
|
46
|
+
outputDestination: this.fileService.join(this.fileService.getRunnerDir(), projectName),
|
|
48
47
|
});
|
|
49
48
|
}
|
|
50
49
|
/**
|
|
@@ -63,14 +62,25 @@ let CreateNewProject = class CreateNewProject extends app_task_1.AppTask {
|
|
|
63
62
|
if (!projectName) {
|
|
64
63
|
throw new Error("Unable to resolve projectName");
|
|
65
64
|
}
|
|
66
|
-
return projectName;
|
|
65
|
+
return this.normalizeProjectName(projectName);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Normalize the name to the provided case or kebab.
|
|
69
|
+
*
|
|
70
|
+
* @param projectName the target project name to normalize
|
|
71
|
+
* @returns the normalized project name
|
|
72
|
+
*/
|
|
73
|
+
normalizeProjectName(projectName) {
|
|
74
|
+
const normalizedTarget = this.utilService.detectCase(`${projectName}.ts`) || format_1.CaseType.KEBAB_CASE;
|
|
75
|
+
return this.utilService.titleizedToCase(this.utilService.titleizeAll(projectName), normalizedTarget);
|
|
67
76
|
}
|
|
68
77
|
};
|
|
69
78
|
CreateNewProject = __decorate([
|
|
70
79
|
(0, tsyringe_1.autoInjectable)(),
|
|
71
80
|
__metadata("design:paramtypes", [file_service_1.FileService,
|
|
72
|
-
|
|
73
|
-
prompt_service_1.PromptService
|
|
81
|
+
util_service_1.UtilService,
|
|
82
|
+
prompt_service_1.PromptService,
|
|
83
|
+
templater_service_1.TemplateService])
|
|
74
84
|
], CreateNewProject);
|
|
75
85
|
exports.default = CreateNewProject;
|
|
76
86
|
//# sourceMappingURL=create-new-project.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-new-project.js","sourceRoot":"./src/","sources":["src/tasks/create-new-project.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"create-new-project.js","sourceRoot":"./src/","sources":["src/tasks/create-new-project.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,2DAAuD;AACvD,+DAA2D;AAC3D,8CAA8C;AAC9C,mDAA+C;AAC/C,uCAA0C;AAC1C,qEAAgE;AAChE,2DAAuD;AACvD,4CAA2C;AAE3C;;GAEG;AAEY,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,kBAAO;IAIzC;IACA;IACA;IACA;IANV,UAAU,GAAG,oBAAoB,CAAC;IAElC,YACU,WAAwB,EACxB,WAAwB,EACxB,aAA4B,EAC5B,gBAAiC;QAEzC,KAAK,EAAE,CAAC;QALA,gBAAW,GAAX,WAAW,CAAa;QACxB,gBAAW,GAAX,WAAW,CAAa;QACxB,kBAAa,GAAb,aAAa,CAAe;QAC5B,qBAAgB,GAAhB,gBAAgB,CAAiB;IAG3C,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,GAAG;QACP,8BAA8B;QAC9B,MAAM,WAAW,GAAW,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;QAExD,oBAAoB;QACpB,MAAM,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QAEtD,IAAI,CAAC,OAAO,CAAC;YACX,iBAAiB,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CACtC,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,EAC/B,WAAW,CACZ;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,cAAc;QAClB,IAAI,WAAmB,CAAC;QACxB,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,oBAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7C,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAS,oBAAU,CAAC,IAAI,CAAC,CAAC;QACnE,CAAC;aAAM,CAAC;YACN,WAAW,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAAC;QACxE,CAAC;QACD,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;QACnD,CAAC;QACD,OAAO,IAAI,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC;IAChD,CAAC;IAED;;;;;OAKG;IACH,oBAAoB,CAAC,WAAmB;QACtC,MAAM,gBAAgB,GACpB,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,WAAW,KAAK,CAAC,IAAI,iBAAQ,CAAC,UAAU,CAAC;QAE1E,OAAO,IAAI,CAAC,WAAW,CAAC,eAAe,CACrC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,WAAW,CAAC,EACzC,gBAAgB,CACjB,CAAC;IACJ,CAAC;CACF,CAAA;AAhEoB,gBAAgB;IADpC,IAAA,yBAAc,GAAE;qCAKQ,0BAAW;QACX,0BAAW;QACT,8BAAa;QACV,mCAAe;GAPxB,gBAAgB,CAgEpC;kBAhEoB,gBAAgB"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { AppTask } from "../../wrappers/app-task";
|
|
2
2
|
import { UtilService } from "../../services/util-service";
|
|
3
|
+
import { FileService } from "../../services/file-service";
|
|
3
4
|
/**
|
|
4
5
|
* Prints the generated output results
|
|
5
6
|
*/
|
|
6
7
|
export default class PrintGeneratedResults extends AppTask {
|
|
7
8
|
private utilService;
|
|
9
|
+
private fileService;
|
|
8
10
|
loggerName: string;
|
|
9
|
-
constructor(utilService: UtilService);
|
|
11
|
+
constructor(utilService: UtilService, fileService: FileService);
|
|
10
12
|
run(): Promise<void>;
|
|
11
13
|
}
|
|
12
14
|
//# sourceMappingURL=print-generated-results.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"print-generated-results.d.ts","sourceRoot":"./src/","sources":["src/tasks/stdout/print-generated-results.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"print-generated-results.d.ts","sourceRoot":"./src/","sources":["src/tasks/stdout/print-generated-results.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAO1D;;GAEG;AAEH,MAAM,CAAC,OAAO,OAAO,qBAAsB,SAAQ,OAAO;IAItD,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,WAAW;IAJrB,UAAU,SAAmB;gBAGnB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW;IAK5B,GAAG;CA4BV"}
|
|
@@ -16,16 +16,22 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
16
16
|
const app_task_1 = require("../../wrappers/app-task");
|
|
17
17
|
const tsyringe_1 = require("tsyringe");
|
|
18
18
|
const util_service_1 = require("../../services/util-service");
|
|
19
|
-
const
|
|
19
|
+
const file_service_1 = require("../../services/file-service");
|
|
20
|
+
const newProjectMessage = (dest) => `
|
|
21
|
+
Try:
|
|
22
|
+
cd ${dest} && npm i && npm start -- help
|
|
23
|
+
`;
|
|
20
24
|
/**
|
|
21
25
|
* Prints the generated output results
|
|
22
26
|
*/
|
|
23
27
|
let PrintGeneratedResults = class PrintGeneratedResults extends app_task_1.AppTask {
|
|
24
28
|
utilService;
|
|
29
|
+
fileService;
|
|
25
30
|
loggerName = "Print Results";
|
|
26
|
-
constructor(utilService) {
|
|
31
|
+
constructor(utilService, fileService) {
|
|
27
32
|
super();
|
|
28
33
|
this.utilService = utilService;
|
|
34
|
+
this.fileService = fileService;
|
|
29
35
|
}
|
|
30
36
|
async run() {
|
|
31
37
|
const genType = this.state.data.genTargetType
|
|
@@ -37,16 +43,19 @@ let PrintGeneratedResults = class PrintGeneratedResults extends app_task_1.AppTa
|
|
|
37
43
|
await this.utilService.sleep(200);
|
|
38
44
|
console.log(`
|
|
39
45
|
|
|
40
|
-
Generated new ${
|
|
46
|
+
Generated new ${genType !== "Project" ? "file" : "project"}:
|
|
41
47
|
|
|
42
48
|
${this.state.data.outputDestination || "<None>"}
|
|
43
|
-
|
|
49
|
+
${genType === "Project"
|
|
50
|
+
? `\n${newProjectMessage(this.fileService.toRelativePath(this.fileService.getRunnerDir(), this.state.data.outputDestination))}\n`
|
|
51
|
+
: ""}
|
|
44
52
|
`);
|
|
45
53
|
}
|
|
46
54
|
};
|
|
47
55
|
PrintGeneratedResults = __decorate([
|
|
48
56
|
(0, tsyringe_1.autoInjectable)(),
|
|
49
|
-
__metadata("design:paramtypes", [util_service_1.UtilService
|
|
57
|
+
__metadata("design:paramtypes", [util_service_1.UtilService,
|
|
58
|
+
file_service_1.FileService])
|
|
50
59
|
], PrintGeneratedResults);
|
|
51
60
|
exports.default = PrintGeneratedResults;
|
|
52
61
|
//# sourceMappingURL=print-generated-results.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"print-generated-results.js","sourceRoot":"./src/","sources":["src/tasks/stdout/print-generated-results.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,kDAA0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ACnB,CAAC,CAAC,KAAK,iBAAiB,CACpB,IAAI,CAAC,WAAW,CAAC,cAAc,CAC7B,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,EAC/B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,iBAAkB,CACnC,CACF,IAAI;YACP,CAAC,CAAC,EACN;OACD,CAAC,CAAC;IACP,CAAC;CACF,CAAA;AAtCoB,qBAAqB;IADzC,IAAA,yBAAc,GAAE;qCAKQ,0BAAW;QACX,0BAAW;GALf,qBAAqB,CAsCzC;kBAtCoB,qBAAqB"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { autoInjectable } from "tsyringe";
|
|
4
|
+
import { SpawnService } from "./spawn-service";
|
|
5
|
+
import { LogService } from "./log-service";
|
|
6
|
+
|
|
7
|
+
const gitignoreContent = `node_modules
|
|
8
|
+
dist
|
|
9
|
+
.env`;
|
|
10
|
+
|
|
11
|
+
@autoInjectable()
|
|
12
|
+
export class TemplateService {
|
|
13
|
+
private loggerName = "Template Service";
|
|
14
|
+
|
|
15
|
+
private outputName!: string;
|
|
16
|
+
private sourceDir!: string;
|
|
17
|
+
private destination!: string;
|
|
18
|
+
|
|
19
|
+
private dirListToCopy: string[] = [".vscode", "src", "tests"];
|
|
20
|
+
private fileListToCopy: string[] = [
|
|
21
|
+
".prettierignore",
|
|
22
|
+
".prettierrc",
|
|
23
|
+
"task-runner",
|
|
24
|
+
"install-link.sh",
|
|
25
|
+
"eslint.config.ts",
|
|
26
|
+
"vitest.config.ts",
|
|
27
|
+
"package-lock.json",
|
|
28
|
+
"package.json",
|
|
29
|
+
"tsconfig.json",
|
|
30
|
+
];
|
|
31
|
+
private nameRefList: string[] = [
|
|
32
|
+
// files that have name references
|
|
33
|
+
"package.json",
|
|
34
|
+
"package-lock.json",
|
|
35
|
+
"install-link.sh",
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
constructor(
|
|
39
|
+
private spawnService: SpawnService,
|
|
40
|
+
private logger: LogService,
|
|
41
|
+
) {
|
|
42
|
+
this.sourceDir = path.join(
|
|
43
|
+
__dirname,
|
|
44
|
+
"../../assets/yargs-template/task-runner/",
|
|
45
|
+
);
|
|
46
|
+
this.logger.setPrefix(this.loggerName);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public async runTemplater(outputName: string) {
|
|
50
|
+
if (!outputName) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
"Missing required parameter. Usage: Templater <output-name>",
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
this.outputName = outputName;
|
|
56
|
+
this.destination = path.join(process.cwd(), outputName);
|
|
57
|
+
|
|
58
|
+
await this.ensureDestinationExists();
|
|
59
|
+
await this.copyDirectories();
|
|
60
|
+
await this.copyFiles();
|
|
61
|
+
await this.fixNaming();
|
|
62
|
+
await this.createGitignore();
|
|
63
|
+
await this.removeDoubleNestedTestsDirectory();
|
|
64
|
+
await this.renameTaskRunner();
|
|
65
|
+
await this.initializeWithGit();
|
|
66
|
+
await this.logger.flush();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private async ensureDestinationExists() {
|
|
70
|
+
if (!fs.existsSync(this.destination)) {
|
|
71
|
+
fs.mkdirSync(this.destination, { recursive: true });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private async copyDirectories() {
|
|
76
|
+
for (const folder of this.dirListToCopy) {
|
|
77
|
+
const src = path.join(this.sourceDir, folder);
|
|
78
|
+
const dest = path.join(this.destination, folder);
|
|
79
|
+
this.logger.debug(`Running Copy: cp -R ${src} ${dest}`);
|
|
80
|
+
fs.cpSync(src, dest, { recursive: true });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private async copyFiles() {
|
|
85
|
+
for (const filename of this.fileListToCopy) {
|
|
86
|
+
const src = path.join(this.sourceDir, filename);
|
|
87
|
+
const dest = path.join(this.destination, filename);
|
|
88
|
+
this.logger.debug(`Running Copy: cp ${src} ${dest}`);
|
|
89
|
+
fs.copyFileSync(src, dest);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private async fixNaming() {
|
|
94
|
+
for (const fileToEdit of this.nameRefList) {
|
|
95
|
+
const dest = path.join(this.destination, fileToEdit);
|
|
96
|
+
const replacePattern = new RegExp("task-runner", "g");
|
|
97
|
+
const content = fs
|
|
98
|
+
.readFileSync(dest, "utf-8")
|
|
99
|
+
.replaceAll(replacePattern, this.outputName);
|
|
100
|
+
fs.writeFileSync(dest, content);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private async createGitignore() {
|
|
105
|
+
fs.writeFileSync(
|
|
106
|
+
path.join(this.destination, ".gitignore"),
|
|
107
|
+
gitignoreContent,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private async removeDoubleNestedTestsDirectory() {
|
|
112
|
+
const doubleNestedTestsPath = path.join(this.destination, "tests", "tests");
|
|
113
|
+
if (fs.existsSync(doubleNestedTestsPath)) {
|
|
114
|
+
this.logger.debug(
|
|
115
|
+
`Removing double nested tests directory: ${doubleNestedTestsPath}`,
|
|
116
|
+
);
|
|
117
|
+
fs.rmSync(doubleNestedTestsPath, { recursive: true });
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private async renameTaskRunner() {
|
|
122
|
+
const src = path.join(this.destination, "task-runner");
|
|
123
|
+
const dest = path.join(this.destination, this.outputName);
|
|
124
|
+
this.logger.debug(`Renaming task-runner to ${this.outputName}`);
|
|
125
|
+
fs.renameSync(src, dest);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private async initializeWithGit() {
|
|
129
|
+
try {
|
|
130
|
+
this.logger.debug("Initializing with git");
|
|
131
|
+
this.spawnService.execSyncFromDir(`git init -b main`, this.destination);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
console.error("Error initializing git:", (error as Error).message);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { SpawnService } from "../services/spawn-service";
|
|
2
1
|
import { FileService } from "../services/file-service";
|
|
3
2
|
import { PromptService } from "../services/prompt-service";
|
|
4
3
|
import { CLIOptions } from "../types/process";
|
|
5
4
|
import { AppTask } from "../wrappers/app-task";
|
|
6
5
|
import { autoInjectable } from "tsyringe";
|
|
6
|
+
import { TemplateService } from "../services/templater-service";
|
|
7
|
+
import { UtilService } from "../services/util-service";
|
|
8
|
+
import { CaseType } from "../types/format";
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* Creates a New Task Script Support Project
|
|
@@ -14,8 +16,9 @@ export default class CreateNewProject extends AppTask {
|
|
|
14
16
|
|
|
15
17
|
constructor(
|
|
16
18
|
private fileService: FileService,
|
|
17
|
-
private
|
|
19
|
+
private utilService: UtilService,
|
|
18
20
|
private promptService: PromptService,
|
|
21
|
+
private templaterService: TemplateService,
|
|
19
22
|
) {
|
|
20
23
|
super();
|
|
21
24
|
}
|
|
@@ -25,24 +28,17 @@ export default class CreateNewProject extends AppTask {
|
|
|
25
28
|
* newly generated project path.
|
|
26
29
|
*/
|
|
27
30
|
async run() {
|
|
28
|
-
// get path of the templater
|
|
29
|
-
const templaterFullPath = this.fileService.join(
|
|
30
|
-
__dirname,
|
|
31
|
-
"../../assets/yargs-template/task-runner/templater.sh",
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
// get execution directory
|
|
35
|
-
const runnerDir = this.fileService.getRunnerDir();
|
|
36
|
-
|
|
37
31
|
// get project name user input
|
|
38
32
|
const projectName: string = await this.getProjectName();
|
|
39
33
|
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
this.spawnService.execSyncFromDir(shCmd, runnerDir);
|
|
34
|
+
// run the templater
|
|
35
|
+
await this.templaterService.runTemplater(projectName);
|
|
43
36
|
|
|
44
37
|
this.setData({
|
|
45
|
-
outputDestination: this.fileService.join(
|
|
38
|
+
outputDestination: this.fileService.join(
|
|
39
|
+
this.fileService.getRunnerDir(),
|
|
40
|
+
projectName,
|
|
41
|
+
),
|
|
46
42
|
});
|
|
47
43
|
}
|
|
48
44
|
|
|
@@ -61,6 +57,22 @@ export default class CreateNewProject extends AppTask {
|
|
|
61
57
|
if (!projectName) {
|
|
62
58
|
throw new Error("Unable to resolve projectName");
|
|
63
59
|
}
|
|
64
|
-
return projectName;
|
|
60
|
+
return this.normalizeProjectName(projectName);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Normalize the name to the provided case or kebab.
|
|
65
|
+
*
|
|
66
|
+
* @param projectName the target project name to normalize
|
|
67
|
+
* @returns the normalized project name
|
|
68
|
+
*/
|
|
69
|
+
normalizeProjectName(projectName: string) {
|
|
70
|
+
const normalizedTarget: CaseType =
|
|
71
|
+
this.utilService.detectCase(`${projectName}.ts`) || CaseType.KEBAB_CASE;
|
|
72
|
+
|
|
73
|
+
return this.utilService.titleizedToCase(
|
|
74
|
+
this.utilService.titleizeAll(projectName),
|
|
75
|
+
normalizedTarget,
|
|
76
|
+
);
|
|
65
77
|
}
|
|
66
78
|
}
|
|
@@ -2,7 +2,12 @@ import chalk from "chalk";
|
|
|
2
2
|
import { AppTask } from "../../wrappers/app-task";
|
|
3
3
|
import { autoInjectable } from "tsyringe";
|
|
4
4
|
import { UtilService } from "../../services/util-service";
|
|
5
|
-
import {
|
|
5
|
+
import { FileService } from "../../services/file-service";
|
|
6
|
+
|
|
7
|
+
const newProjectMessage = (dest: string) => `
|
|
8
|
+
Try:
|
|
9
|
+
cd ${dest} && npm i && npm start -- help
|
|
10
|
+
`;
|
|
6
11
|
|
|
7
12
|
/**
|
|
8
13
|
* Prints the generated output results
|
|
@@ -11,7 +16,10 @@ import { ProjectService } from "../../services/project-service";
|
|
|
11
16
|
export default class PrintGeneratedResults extends AppTask {
|
|
12
17
|
loggerName = "Print Results";
|
|
13
18
|
|
|
14
|
-
constructor(
|
|
19
|
+
constructor(
|
|
20
|
+
private utilService: UtilService,
|
|
21
|
+
private fileService: FileService,
|
|
22
|
+
) {
|
|
15
23
|
super();
|
|
16
24
|
}
|
|
17
25
|
|
|
@@ -28,10 +36,19 @@ export default class PrintGeneratedResults extends AppTask {
|
|
|
28
36
|
|
|
29
37
|
console.log(`
|
|
30
38
|
|
|
31
|
-
Generated new ${
|
|
39
|
+
Generated new ${genType !== "Project" ? "file" : "project"}:
|
|
32
40
|
|
|
33
41
|
${this.state.data.outputDestination || "<None>"}
|
|
34
|
-
|
|
42
|
+
${
|
|
43
|
+
genType === "Project"
|
|
44
|
+
? `\n${newProjectMessage(
|
|
45
|
+
this.fileService.toRelativePath(
|
|
46
|
+
this.fileService.getRunnerDir(),
|
|
47
|
+
this.state.data.outputDestination!,
|
|
48
|
+
),
|
|
49
|
+
)}\n`
|
|
50
|
+
: ""
|
|
51
|
+
}
|
|
35
52
|
`);
|
|
36
53
|
}
|
|
37
54
|
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
set -euo pipefail
|
|
3
|
-
|
|
4
|
-
if [[ -z "$1" ]]; then
|
|
5
|
-
echo "Missing required parameter. Usage: ./templater.sh <output-name>"
|
|
6
|
-
exit 1;
|
|
7
|
-
fi
|
|
8
|
-
|
|
9
|
-
DIR_LIST_TO_COPY=('.vscode' 'src' 'tests')
|
|
10
|
-
FILE_LIST_TO_COPY=('.prettierignore' '.prettierrc' 'task-runner' 'install-link.sh' 'eslint.config.ts' 'vitest.config.ts' 'package-lock.json' 'package.json' 'tsconfig.json')
|
|
11
|
-
NAME_REF_LIST=('package.json' 'package-lock.json' 'install-link.sh')
|
|
12
|
-
CWD=$(pwd)
|
|
13
|
-
SCRIPT_DIR=$(dirname "$0")
|
|
14
|
-
DESTINATION="$CWD/$1"
|
|
15
|
-
|
|
16
|
-
# ensure dest exists
|
|
17
|
-
if [ -f "$DESTINATION" ]; then
|
|
18
|
-
echo "Using destination: $DESTINATION"
|
|
19
|
-
else
|
|
20
|
-
echo "Creating destination directory: $DESTINATION"
|
|
21
|
-
mkdir -p "$DESTINATION"
|
|
22
|
-
fi
|
|
23
|
-
|
|
24
|
-
# copy directories
|
|
25
|
-
for folder in "${DIR_LIST_TO_COPY[@]}"; do
|
|
26
|
-
echo "Running Copy/: cp -R $SCRIPT_DIR/$folder $DESTINATION/$folder"
|
|
27
|
-
cp -R "$SCRIPT_DIR/$folder" "$DESTINATION/$folder"
|
|
28
|
-
done
|
|
29
|
-
|
|
30
|
-
# copy files
|
|
31
|
-
for filename in "${FILE_LIST_TO_COPY[@]}"; do
|
|
32
|
-
echo "Running Copy: cp $SCRIPT_DIR/$filename $DESTINATION/$filename"
|
|
33
|
-
cp "$SCRIPT_DIR/$filename" "$DESTINATION/$filename"
|
|
34
|
-
done
|
|
35
|
-
|
|
36
|
-
# fix naming
|
|
37
|
-
for fileToEdit in "${NAME_REF_LIST[@]}"; do
|
|
38
|
-
dest="$DESTINATION/$fileToEdit"
|
|
39
|
-
replace_pattern="s/task-runner/$1/g"
|
|
40
|
-
echo "Running Patch: cat \"$dest\" | sed -i \"$replace_pattern\" "
|
|
41
|
-
output=$(cat "$dest" | sed "$replace_pattern")
|
|
42
|
-
echo "$output" > "$dest"
|
|
43
|
-
|
|
44
|
-
# echo "Running patch: sed -i \"s/task-runner/$1/g\" \"$DESTINATION/$fileToEdit\""
|
|
45
|
-
# sed -i "s/task-runner/$1/g" "$DESTINATION/$fileToEdit"
|
|
46
|
-
done
|
|
47
|
-
|
|
48
|
-
# do the .gitignore file manually since npm won't let us publish that in the template
|
|
49
|
-
# see: https://github.com/npm/npm/issues/3763
|
|
50
|
-
echo 'node_modules
|
|
51
|
-
dist
|
|
52
|
-
.env' > "$DESTINATION/.gitignore";
|
|
53
|
-
|
|
54
|
-
# remove double nested tests directory : need to look into why this is happening
|
|
55
|
-
if [ -d "$DESTINATION/tests/tests" ]; then
|
|
56
|
-
rm -rf "$DESTINATION/tests/tests";
|
|
57
|
-
fi
|
|
58
|
-
|
|
59
|
-
mv "$DESTINATION/task-runner" "$DESTINATION/$1"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
# cd into destination and run git init
|
|
63
|
-
echo "initializing with git"
|
|
64
|
-
INITIALIZED=$(cd "$DESTINATION" && git init -b main)
|
|
65
|
-
|
|
66
|
-
echo;
|
|
67
|
-
echo " Try:"
|
|
68
|
-
echo " cd $DESTINATION && npm i && npm run dev"
|
|
69
|
-
echo;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
set -euo pipefail
|
|
3
|
-
|
|
4
|
-
if [[ -z "$1" ]]; then
|
|
5
|
-
echo "Missing required parameter. Usage: ./templater.sh <output-name>"
|
|
6
|
-
exit 1;
|
|
7
|
-
fi
|
|
8
|
-
|
|
9
|
-
DIR_LIST_TO_COPY=('.vscode' 'src' 'tests')
|
|
10
|
-
FILE_LIST_TO_COPY=('.prettierignore' '.prettierrc' 'task-runner' 'install-link.sh' 'eslint.config.ts' 'vitest.config.ts' 'package-lock.json' 'package.json' 'tsconfig.json')
|
|
11
|
-
NAME_REF_LIST=('package.json' 'package-lock.json' 'install-link.sh')
|
|
12
|
-
CWD=$(pwd)
|
|
13
|
-
SCRIPT_DIR=$(dirname "$0")
|
|
14
|
-
DESTINATION="$CWD/$1"
|
|
15
|
-
|
|
16
|
-
# ensure dest exists
|
|
17
|
-
if [ -f "$DESTINATION" ]; then
|
|
18
|
-
echo "Using destination: $DESTINATION"
|
|
19
|
-
else
|
|
20
|
-
echo "Creating destination directory: $DESTINATION"
|
|
21
|
-
mkdir -p "$DESTINATION"
|
|
22
|
-
fi
|
|
23
|
-
|
|
24
|
-
# copy directories
|
|
25
|
-
for folder in "${DIR_LIST_TO_COPY[@]}"; do
|
|
26
|
-
echo "Running Copy/: cp -R $SCRIPT_DIR/$folder $DESTINATION/$folder"
|
|
27
|
-
cp -R "$SCRIPT_DIR/$folder" "$DESTINATION/$folder"
|
|
28
|
-
done
|
|
29
|
-
|
|
30
|
-
# copy files
|
|
31
|
-
for filename in "${FILE_LIST_TO_COPY[@]}"; do
|
|
32
|
-
echo "Running Copy: cp $SCRIPT_DIR/$filename $DESTINATION/$filename"
|
|
33
|
-
cp "$SCRIPT_DIR/$filename" "$DESTINATION/$filename"
|
|
34
|
-
done
|
|
35
|
-
|
|
36
|
-
# fix naming
|
|
37
|
-
for fileToEdit in "${NAME_REF_LIST[@]}"; do
|
|
38
|
-
dest="$DESTINATION/$fileToEdit"
|
|
39
|
-
replace_pattern="s/task-runner/$1/g"
|
|
40
|
-
echo "Running Patch: cat \"$dest\" | sed -i \"$replace_pattern\" "
|
|
41
|
-
output=$(cat "$dest" | sed "$replace_pattern")
|
|
42
|
-
echo "$output" > "$dest"
|
|
43
|
-
|
|
44
|
-
# echo "Running patch: sed -i \"s/task-runner/$1/g\" \"$DESTINATION/$fileToEdit\""
|
|
45
|
-
# sed -i "s/task-runner/$1/g" "$DESTINATION/$fileToEdit"
|
|
46
|
-
done
|
|
47
|
-
|
|
48
|
-
# do the .gitignore file manually since npm won't let us publish that in the template
|
|
49
|
-
# see: https://github.com/npm/npm/issues/3763
|
|
50
|
-
echo 'node_modules
|
|
51
|
-
dist
|
|
52
|
-
.env' > "$DESTINATION/.gitignore";
|
|
53
|
-
|
|
54
|
-
# remove double nested tests directory : need to look into why this is happening
|
|
55
|
-
if [ -d "$DESTINATION/tests/tests" ]; then
|
|
56
|
-
rm -rf "$DESTINATION/tests/tests";
|
|
57
|
-
fi
|
|
58
|
-
|
|
59
|
-
mv "$DESTINATION/task-runner" "$DESTINATION/$1"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
# cd into destination and run git init
|
|
63
|
-
echo "initializing with git"
|
|
64
|
-
INITIALIZED=$(cd "$DESTINATION" && git init -b main)
|
|
65
|
-
|
|
66
|
-
echo;
|
|
67
|
-
echo " Try:"
|
|
68
|
-
echo " cd $DESTINATION && npm i && npm run dev"
|
|
69
|
-
echo;
|