@devbro/pashmak 0.1.9 → 0.1.10
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/app/console/DefaultCommand.mjs +3 -1
- package/dist/app/console/DefaultCommand.mjs.map +1 -1
- package/dist/app/console/KeyGenerateCommand.mjs +19 -17
- package/dist/app/console/KeyGenerateCommand.mjs.map +1 -1
- package/dist/app/console/StartCommand.mjs +9 -13
- package/dist/app/console/StartCommand.mjs.map +1 -1
- package/dist/app/console/generate/GenerateControllerCommand.mjs +14 -17
- package/dist/app/console/generate/GenerateControllerCommand.mjs.map +1 -1
- package/dist/app/console/generate/index.mjs +1 -1
- package/dist/app/console/generate/index.mjs.map +1 -1
- package/dist/app/console/index.mjs +7 -7
- package/dist/app/console/index.mjs.map +1 -1
- package/dist/app/console/migrate/GenerateMigrateCommand.mjs +14 -17
- package/dist/app/console/migrate/GenerateMigrateCommand.mjs.map +1 -1
- package/dist/app/console/migrate/MigrateCommand.mjs +5 -10
- package/dist/app/console/migrate/MigrateCommand.mjs.map +1 -1
- package/dist/app/console/migrate/MigrateRollbackCommand.mjs +2 -9
- package/dist/app/console/migrate/MigrateRollbackCommand.mjs.map +1 -1
- package/dist/app/console/migrate/index.mjs +3 -3
- package/dist/app/console/migrate/index.mjs.map +1 -1
- package/dist/app/console/project/CreateProjectCommand.mjs +17 -23
- package/dist/app/console/project/CreateProjectCommand.mjs.map +1 -1
- package/dist/bin/app/console/DefaultCommand.cjs +5 -3
- package/dist/bin/app/console/KeyGenerateCommand.cjs +23 -21
- package/dist/bin/app/console/StartCommand.cjs +11 -15
- package/dist/bin/app/console/generate/GenerateControllerCommand.cjs +20 -23
- package/dist/bin/app/console/generate/index.cjs +20 -23
- package/dist/bin/app/console/index.cjs +110 -134
- package/dist/bin/app/console/migrate/GenerateMigrateCommand.cjs +19 -22
- package/dist/bin/app/console/migrate/MigrateCommand.cjs +9 -14
- package/dist/bin/app/console/migrate/MigrateRollbackCommand.cjs +7 -14
- package/dist/bin/app/console/migrate/index.cjs +33 -48
- package/dist/bin/app/console/project/CreateProjectCommand.cjs +21 -27
- package/dist/bin/bin/pashmak_cli.cjs +21 -27
- package/dist/bin/index.cjs +123 -150
- package/dist/bin/pashmak_cli.mjs +2 -2
- package/dist/bin/pashmak_cli.mjs.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +2 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1184,7 +1184,7 @@ var require_lib = __commonJS({
|
|
|
1184
1184
|
}
|
|
1185
1185
|
});
|
|
1186
1186
|
|
|
1187
|
-
// src/app/console/migrate/MigrateRollbackCommand.
|
|
1187
|
+
// src/app/console/migrate/MigrateRollbackCommand.mts
|
|
1188
1188
|
var MigrateRollbackCommand_exports = {};
|
|
1189
1189
|
__export(MigrateRollbackCommand_exports, {
|
|
1190
1190
|
MigrateRollbackCommand: () => MigrateRollbackCommand
|
|
@@ -1627,23 +1627,18 @@ var mailer = (0, import_neko_helper.createSingleton)((label) => {
|
|
|
1627
1627
|
return rc;
|
|
1628
1628
|
});
|
|
1629
1629
|
|
|
1630
|
-
// src/app/console/migrate/MigrateRollbackCommand.
|
|
1630
|
+
// src/app/console/migrate/MigrateRollbackCommand.mts
|
|
1631
1631
|
var import_clipanion2 = require("clipanion");
|
|
1632
1632
|
var import_neko_context3 = require("@devbro/neko-context");
|
|
1633
|
-
var import_path2 = __toESM(require("path"));
|
|
1634
|
-
var import_promises = __toESM(require("fs/promises"));
|
|
1633
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
1634
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
1635
1635
|
var import_neko_config2 = require("@devbro/neko-config");
|
|
1636
|
-
var t = __toESM(require_lib());
|
|
1636
|
+
var t = __toESM(require_lib(), 1);
|
|
1637
1637
|
var MigrateRollbackCommand = class extends import_clipanion2.Command {
|
|
1638
1638
|
static {
|
|
1639
1639
|
__name(this, "MigrateRollbackCommand");
|
|
1640
1640
|
}
|
|
1641
|
-
static paths = [
|
|
1642
|
-
[
|
|
1643
|
-
`migrate`,
|
|
1644
|
-
"rollback"
|
|
1645
|
-
]
|
|
1646
|
-
];
|
|
1641
|
+
static paths = [[`migrate`, "rollback"]];
|
|
1647
1642
|
steps = import_clipanion2.Option.String(`--steps`, {
|
|
1648
1643
|
description: `how many migrations to rollback`,
|
|
1649
1644
|
validator: t.isNumber()
|
|
@@ -1669,9 +1664,7 @@ var MigrateRollbackCommand = class extends import_clipanion2.Command {
|
|
|
1669
1664
|
await c.down(db2.getSchema());
|
|
1670
1665
|
await db2.runQuery({
|
|
1671
1666
|
sql: "delete from migrations where id = $1",
|
|
1672
|
-
bindings: [
|
|
1673
|
-
migration.id
|
|
1674
|
-
]
|
|
1667
|
+
bindings: [migration.id]
|
|
1675
1668
|
});
|
|
1676
1669
|
}
|
|
1677
1670
|
});
|
|
@@ -1184,7 +1184,7 @@ var require_lib = __commonJS({
|
|
|
1184
1184
|
}
|
|
1185
1185
|
});
|
|
1186
1186
|
|
|
1187
|
-
// src/app/console/migrate/index.
|
|
1187
|
+
// src/app/console/migrate/index.mts
|
|
1188
1188
|
var migrate_exports = {};
|
|
1189
1189
|
__export(migrate_exports, {
|
|
1190
1190
|
GenerateMigrateCommand: () => GenerateMigrateCommand,
|
|
@@ -1629,21 +1629,17 @@ var mailer = (0, import_neko_helper.createSingleton)((label) => {
|
|
|
1629
1629
|
return rc;
|
|
1630
1630
|
});
|
|
1631
1631
|
|
|
1632
|
-
// src/app/console/migrate/MigrateCommand.
|
|
1632
|
+
// src/app/console/migrate/MigrateCommand.mts
|
|
1633
1633
|
var import_clipanion2 = require("clipanion");
|
|
1634
1634
|
var import_neko_context3 = require("@devbro/neko-context");
|
|
1635
|
-
var import_path2 = __toESM(require("path"));
|
|
1636
|
-
var import_promises = __toESM(require("fs/promises"));
|
|
1635
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
1636
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
1637
1637
|
var import_neko_config2 = require("@devbro/neko-config");
|
|
1638
1638
|
var MigrateCommand = class extends import_clipanion2.Command {
|
|
1639
1639
|
static {
|
|
1640
1640
|
__name(this, "MigrateCommand");
|
|
1641
1641
|
}
|
|
1642
|
-
static paths = [
|
|
1643
|
-
[
|
|
1644
|
-
`migrate`
|
|
1645
|
-
]
|
|
1646
|
-
];
|
|
1642
|
+
static paths = [[`migrate`]];
|
|
1647
1643
|
fresh = import_clipanion2.Option.Boolean("--fresh", false);
|
|
1648
1644
|
async execute() {
|
|
1649
1645
|
await import_neko_context3.context_provider.run(async () => {
|
|
@@ -1691,7 +1687,9 @@ var MigrateCommand = class extends import_clipanion2.Command {
|
|
|
1691
1687
|
bindings: []
|
|
1692
1688
|
});
|
|
1693
1689
|
const completed_migrations = migrations.map((r) => r.filename);
|
|
1694
|
-
const pending_migrations = files.filter(
|
|
1690
|
+
const pending_migrations = files.filter(
|
|
1691
|
+
(file) => !completed_migrations.includes(file)
|
|
1692
|
+
);
|
|
1695
1693
|
let migrated_count = 0;
|
|
1696
1694
|
for (const class_to_migrate of pending_migrations) {
|
|
1697
1695
|
logger().info(`migrating up ${class_to_migrate}`);
|
|
@@ -1700,10 +1698,7 @@ var MigrateCommand = class extends import_clipanion2.Command {
|
|
|
1700
1698
|
await c.up(db2.getSchema());
|
|
1701
1699
|
await db2.runQuery({
|
|
1702
1700
|
sql: "insert into migrations (filename, batch) values ($1,$2)",
|
|
1703
|
-
bindings: [
|
|
1704
|
-
class_to_migrate,
|
|
1705
|
-
batch_number
|
|
1706
|
-
]
|
|
1701
|
+
bindings: [class_to_migrate, batch_number]
|
|
1707
1702
|
});
|
|
1708
1703
|
migrated_count++;
|
|
1709
1704
|
}
|
|
@@ -1717,13 +1712,13 @@ var MigrateCommand = class extends import_clipanion2.Command {
|
|
|
1717
1712
|
};
|
|
1718
1713
|
cli().register(MigrateCommand);
|
|
1719
1714
|
|
|
1720
|
-
// src/app/console/migrate/GenerateMigrateCommand.
|
|
1715
|
+
// src/app/console/migrate/GenerateMigrateCommand.mts
|
|
1721
1716
|
var import_clipanion3 = require("clipanion");
|
|
1722
1717
|
var import_change_case_all = require("change-case-all");
|
|
1723
|
-
var import_path3 = __toESM(require("path"));
|
|
1724
|
-
var fs2 = __toESM(require("fs/promises"));
|
|
1718
|
+
var import_path3 = __toESM(require("path"), 1);
|
|
1719
|
+
var fs2 = __toESM(require("fs/promises"), 1);
|
|
1725
1720
|
var import_neko_config3 = require("@devbro/neko-config");
|
|
1726
|
-
var import_handlebars = __toESM(require("handlebars"));
|
|
1721
|
+
var import_handlebars = __toESM(require("handlebars"), 1);
|
|
1727
1722
|
var import_url = require("url");
|
|
1728
1723
|
var import_meta = {};
|
|
1729
1724
|
var GenerateMigrateCommand = class extends import_clipanion3.Command {
|
|
@@ -1731,62 +1726,54 @@ var GenerateMigrateCommand = class extends import_clipanion3.Command {
|
|
|
1731
1726
|
__name(this, "GenerateMigrateCommand");
|
|
1732
1727
|
}
|
|
1733
1728
|
static paths = [
|
|
1734
|
-
[
|
|
1735
|
-
|
|
1736
|
-
`migrate`
|
|
1737
|
-
],
|
|
1738
|
-
[
|
|
1739
|
-
"generate",
|
|
1740
|
-
"migration"
|
|
1741
|
-
]
|
|
1729
|
+
[`generate`, `migrate`],
|
|
1730
|
+
["generate", "migration"]
|
|
1742
1731
|
];
|
|
1743
|
-
name = import_clipanion3.Option.String({
|
|
1744
|
-
required: true
|
|
1745
|
-
});
|
|
1732
|
+
name = import_clipanion3.Option.String({ required: true });
|
|
1746
1733
|
async execute() {
|
|
1747
1734
|
const date = /* @__PURE__ */ new Date();
|
|
1748
1735
|
const year = date.getFullYear();
|
|
1749
1736
|
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
1750
1737
|
const day = String(date.getDate()).padStart(2, "0");
|
|
1751
|
-
const secondsOfDay = String(
|
|
1738
|
+
const secondsOfDay = String(
|
|
1739
|
+
date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds()
|
|
1740
|
+
).padStart(5, "0");
|
|
1752
1741
|
const fixed_name = import_change_case_all.Case.snake(this.name);
|
|
1753
1742
|
const filename = `${year}_${month}_${day}_${secondsOfDay}_${fixed_name}.ts`;
|
|
1754
1743
|
this.context.stdout.write(`creating migration file ${filename}
|
|
1755
1744
|
`);
|
|
1756
|
-
await fs2.mkdir(import_neko_config3.config.get("migration.path"), {
|
|
1757
|
-
recursive: true
|
|
1758
|
-
});
|
|
1745
|
+
await fs2.mkdir(import_neko_config3.config.get("migration.path"), { recursive: true });
|
|
1759
1746
|
let dirname = typeof __dirname === "string" ? __dirname : void 0;
|
|
1760
1747
|
if (!dirname) {
|
|
1761
1748
|
dirname = import_path3.default.dirname((0, import_url.fileURLToPath)(import_meta.url));
|
|
1762
1749
|
}
|
|
1763
|
-
const compiledTemplate = import_handlebars.default.compile(
|
|
1750
|
+
const compiledTemplate = import_handlebars.default.compile(
|
|
1751
|
+
(await fs2.readFile(import_path3.default.join(dirname, "./make_migration.tpl"))).toString()
|
|
1752
|
+
);
|
|
1764
1753
|
const template = await compiledTemplate({
|
|
1765
1754
|
className: import_change_case_all.Case.pascal(this.name) + "Migration",
|
|
1766
1755
|
tableName: import_change_case_all.Case.snake(this.name)
|
|
1767
1756
|
});
|
|
1768
|
-
await fs2.writeFile(
|
|
1757
|
+
await fs2.writeFile(
|
|
1758
|
+
import_path3.default.join(import_neko_config3.config.get("migration.path"), filename),
|
|
1759
|
+
template
|
|
1760
|
+
);
|
|
1769
1761
|
}
|
|
1770
1762
|
};
|
|
1771
1763
|
cli().register(GenerateMigrateCommand);
|
|
1772
1764
|
|
|
1773
|
-
// src/app/console/migrate/MigrateRollbackCommand.
|
|
1765
|
+
// src/app/console/migrate/MigrateRollbackCommand.mts
|
|
1774
1766
|
var import_clipanion4 = require("clipanion");
|
|
1775
1767
|
var import_neko_context4 = require("@devbro/neko-context");
|
|
1776
|
-
var import_path4 = __toESM(require("path"));
|
|
1777
|
-
var import_promises2 = __toESM(require("fs/promises"));
|
|
1768
|
+
var import_path4 = __toESM(require("path"), 1);
|
|
1769
|
+
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
1778
1770
|
var import_neko_config4 = require("@devbro/neko-config");
|
|
1779
|
-
var t = __toESM(require_lib());
|
|
1771
|
+
var t = __toESM(require_lib(), 1);
|
|
1780
1772
|
var MigrateRollbackCommand = class extends import_clipanion4.Command {
|
|
1781
1773
|
static {
|
|
1782
1774
|
__name(this, "MigrateRollbackCommand");
|
|
1783
1775
|
}
|
|
1784
|
-
static paths = [
|
|
1785
|
-
[
|
|
1786
|
-
`migrate`,
|
|
1787
|
-
"rollback"
|
|
1788
|
-
]
|
|
1789
|
-
];
|
|
1776
|
+
static paths = [[`migrate`, "rollback"]];
|
|
1790
1777
|
steps = import_clipanion4.Option.String(`--steps`, {
|
|
1791
1778
|
description: `how many migrations to rollback`,
|
|
1792
1779
|
validator: t.isNumber()
|
|
@@ -1812,9 +1799,7 @@ var MigrateRollbackCommand = class extends import_clipanion4.Command {
|
|
|
1812
1799
|
await c.down(db2.getSchema());
|
|
1813
1800
|
await db2.runQuery({
|
|
1814
1801
|
sql: "delete from migrations where id = $1",
|
|
1815
|
-
bindings: [
|
|
1816
|
-
migration.id
|
|
1817
|
-
]
|
|
1802
|
+
bindings: [migration.id]
|
|
1818
1803
|
});
|
|
1819
1804
|
}
|
|
1820
1805
|
});
|
|
@@ -28,7 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
));
|
|
29
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
30
|
|
|
31
|
-
// src/app/console/project/CreateProjectCommand.
|
|
31
|
+
// src/app/console/project/CreateProjectCommand.mts
|
|
32
32
|
var CreateProjectCommand_exports = {};
|
|
33
33
|
__export(CreateProjectCommand_exports, {
|
|
34
34
|
CreateProjectCommand: () => CreateProjectCommand
|
|
@@ -36,22 +36,17 @@ __export(CreateProjectCommand_exports, {
|
|
|
36
36
|
module.exports = __toCommonJS(CreateProjectCommand_exports);
|
|
37
37
|
var import_clipanion = require("clipanion");
|
|
38
38
|
var import_change_case_all = require("change-case-all");
|
|
39
|
-
var import_path = __toESM(require("path"));
|
|
40
|
-
var fs = __toESM(require("fs/promises"));
|
|
39
|
+
var import_path = __toESM(require("path"), 1);
|
|
40
|
+
var fs = __toESM(require("fs/promises"), 1);
|
|
41
41
|
var import_url = require("url");
|
|
42
|
-
var import_handlebars = __toESM(require("handlebars"));
|
|
42
|
+
var import_handlebars = __toESM(require("handlebars"), 1);
|
|
43
43
|
var import_child_process = require("child_process");
|
|
44
44
|
var import_meta = {};
|
|
45
45
|
var CreateProjectCommand = class extends import_clipanion.Command {
|
|
46
46
|
static {
|
|
47
47
|
__name(this, "CreateProjectCommand");
|
|
48
48
|
}
|
|
49
|
-
static paths = [
|
|
50
|
-
[
|
|
51
|
-
`create`,
|
|
52
|
-
`project`
|
|
53
|
-
]
|
|
54
|
-
];
|
|
49
|
+
static paths = [[`create`, `project`]];
|
|
55
50
|
static usage = import_clipanion.Command.Usage({
|
|
56
51
|
category: `Project`,
|
|
57
52
|
description: `Create a new project`,
|
|
@@ -70,9 +65,7 @@ var CreateProjectCommand = class extends import_clipanion.Command {
|
|
|
70
65
|
]
|
|
71
66
|
]
|
|
72
67
|
});
|
|
73
|
-
projectPath = import_clipanion.Option.String("--path", {
|
|
74
|
-
required: true
|
|
75
|
-
});
|
|
68
|
+
projectPath = import_clipanion.Option.String("--path", { required: true });
|
|
76
69
|
git = import_clipanion.Option.Boolean(`--git`, false, {
|
|
77
70
|
description: `Initialize a git repository in the new project`
|
|
78
71
|
});
|
|
@@ -95,9 +88,7 @@ var CreateProjectCommand = class extends import_clipanion.Command {
|
|
|
95
88
|
return 1;
|
|
96
89
|
} catch {
|
|
97
90
|
}
|
|
98
|
-
await fs.mkdir(projectPath, {
|
|
99
|
-
recursive: true
|
|
100
|
-
});
|
|
91
|
+
await fs.mkdir(projectPath, { recursive: true });
|
|
101
92
|
console.log(`Created project directory at: ${projectPath}`);
|
|
102
93
|
const dirname = typeof __dirname === "undefined" ? import_path.default.dirname((0, import_url.fileURLToPath)(import_meta.url)) : __dirname;
|
|
103
94
|
let basePath = import_path.default.join(dirname, `./base_project`);
|
|
@@ -115,9 +106,12 @@ var CreateProjectCommand = class extends import_clipanion.Command {
|
|
|
115
106
|
console.log(`Updated package.json with project name: ${packageJson.name}`);
|
|
116
107
|
if (this.git) {
|
|
117
108
|
try {
|
|
118
|
-
(0, import_child_process.execSync)(
|
|
119
|
-
|
|
120
|
-
|
|
109
|
+
(0, import_child_process.execSync)(
|
|
110
|
+
'git init; git add --all; git commit --allow-empty -m "chore: first commit for pashmak"',
|
|
111
|
+
{
|
|
112
|
+
cwd: projectPath
|
|
113
|
+
}
|
|
114
|
+
);
|
|
121
115
|
} catch (error) {
|
|
122
116
|
console.error(`Failed to create project.`, error);
|
|
123
117
|
return 1;
|
|
@@ -125,26 +119,26 @@ var CreateProjectCommand = class extends import_clipanion.Command {
|
|
|
125
119
|
}
|
|
126
120
|
}
|
|
127
121
|
async processTplFolder(src, dest, data = {}) {
|
|
128
|
-
const files = await fs.readdir(src, {
|
|
129
|
-
withFileTypes: true
|
|
130
|
-
});
|
|
122
|
+
const files = await fs.readdir(src, { withFileTypes: true });
|
|
131
123
|
for (const file of files) {
|
|
132
124
|
const srcPath = import_path.default.join(src, file.name);
|
|
133
125
|
const destPath = file.isFile() && file.name.endsWith(".tpl") ? import_path.default.join(dest, file.name.substring(0, file.name.length - 4)) : import_path.default.join(dest, file.name);
|
|
134
126
|
if (file.isDirectory()) {
|
|
135
|
-
await fs.mkdir(destPath, {
|
|
136
|
-
recursive: true
|
|
137
|
-
});
|
|
127
|
+
await fs.mkdir(destPath, { recursive: true });
|
|
138
128
|
await this.processTplFolder(srcPath, destPath, data);
|
|
139
129
|
} else if (file.name.endsWith(".tpl")) {
|
|
140
130
|
await this.processTplFile(srcPath, destPath, {});
|
|
141
131
|
} else {
|
|
142
|
-
throw new Error(
|
|
132
|
+
throw new Error(
|
|
133
|
+
"unexpected non tpl file: " + srcPath + " " + file.name
|
|
134
|
+
);
|
|
143
135
|
}
|
|
144
136
|
}
|
|
145
137
|
}
|
|
146
138
|
async processTplFile(src, dest, data = {}) {
|
|
147
|
-
const compiledTemplate = import_handlebars.default.compile(
|
|
139
|
+
const compiledTemplate = import_handlebars.default.compile(
|
|
140
|
+
(await fs.readFile(src)).toString()
|
|
141
|
+
);
|
|
148
142
|
const template = await compiledTemplate(data);
|
|
149
143
|
await fs.writeFile(dest, template);
|
|
150
144
|
}
|
|
@@ -27,25 +27,20 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
// src/bin/pashmak_cli.ts
|
|
28
28
|
var import_clipanion2 = require("clipanion");
|
|
29
29
|
|
|
30
|
-
// src/app/console/project/CreateProjectCommand.
|
|
30
|
+
// src/app/console/project/CreateProjectCommand.mts
|
|
31
31
|
var import_clipanion = require("clipanion");
|
|
32
32
|
var import_change_case_all = require("change-case-all");
|
|
33
|
-
var import_path = __toESM(require("path"));
|
|
34
|
-
var fs = __toESM(require("fs/promises"));
|
|
33
|
+
var import_path = __toESM(require("path"), 1);
|
|
34
|
+
var fs = __toESM(require("fs/promises"), 1);
|
|
35
35
|
var import_url = require("url");
|
|
36
|
-
var import_handlebars = __toESM(require("handlebars"));
|
|
36
|
+
var import_handlebars = __toESM(require("handlebars"), 1);
|
|
37
37
|
var import_child_process = require("child_process");
|
|
38
38
|
var import_meta = {};
|
|
39
39
|
var CreateProjectCommand = class extends import_clipanion.Command {
|
|
40
40
|
static {
|
|
41
41
|
__name(this, "CreateProjectCommand");
|
|
42
42
|
}
|
|
43
|
-
static paths = [
|
|
44
|
-
[
|
|
45
|
-
`create`,
|
|
46
|
-
`project`
|
|
47
|
-
]
|
|
48
|
-
];
|
|
43
|
+
static paths = [[`create`, `project`]];
|
|
49
44
|
static usage = import_clipanion.Command.Usage({
|
|
50
45
|
category: `Project`,
|
|
51
46
|
description: `Create a new project`,
|
|
@@ -64,9 +59,7 @@ var CreateProjectCommand = class extends import_clipanion.Command {
|
|
|
64
59
|
]
|
|
65
60
|
]
|
|
66
61
|
});
|
|
67
|
-
projectPath = import_clipanion.Option.String("--path", {
|
|
68
|
-
required: true
|
|
69
|
-
});
|
|
62
|
+
projectPath = import_clipanion.Option.String("--path", { required: true });
|
|
70
63
|
git = import_clipanion.Option.Boolean(`--git`, false, {
|
|
71
64
|
description: `Initialize a git repository in the new project`
|
|
72
65
|
});
|
|
@@ -89,9 +82,7 @@ var CreateProjectCommand = class extends import_clipanion.Command {
|
|
|
89
82
|
return 1;
|
|
90
83
|
} catch {
|
|
91
84
|
}
|
|
92
|
-
await fs.mkdir(projectPath, {
|
|
93
|
-
recursive: true
|
|
94
|
-
});
|
|
85
|
+
await fs.mkdir(projectPath, { recursive: true });
|
|
95
86
|
console.log(`Created project directory at: ${projectPath}`);
|
|
96
87
|
const dirname = typeof __dirname === "undefined" ? import_path.default.dirname((0, import_url.fileURLToPath)(import_meta.url)) : __dirname;
|
|
97
88
|
let basePath = import_path.default.join(dirname, `./base_project`);
|
|
@@ -109,9 +100,12 @@ var CreateProjectCommand = class extends import_clipanion.Command {
|
|
|
109
100
|
console.log(`Updated package.json with project name: ${packageJson.name}`);
|
|
110
101
|
if (this.git) {
|
|
111
102
|
try {
|
|
112
|
-
(0, import_child_process.execSync)(
|
|
113
|
-
|
|
114
|
-
|
|
103
|
+
(0, import_child_process.execSync)(
|
|
104
|
+
'git init; git add --all; git commit --allow-empty -m "chore: first commit for pashmak"',
|
|
105
|
+
{
|
|
106
|
+
cwd: projectPath
|
|
107
|
+
}
|
|
108
|
+
);
|
|
115
109
|
} catch (error) {
|
|
116
110
|
console.error(`Failed to create project.`, error);
|
|
117
111
|
return 1;
|
|
@@ -119,26 +113,26 @@ var CreateProjectCommand = class extends import_clipanion.Command {
|
|
|
119
113
|
}
|
|
120
114
|
}
|
|
121
115
|
async processTplFolder(src, dest, data = {}) {
|
|
122
|
-
const files = await fs.readdir(src, {
|
|
123
|
-
withFileTypes: true
|
|
124
|
-
});
|
|
116
|
+
const files = await fs.readdir(src, { withFileTypes: true });
|
|
125
117
|
for (const file of files) {
|
|
126
118
|
const srcPath = import_path.default.join(src, file.name);
|
|
127
119
|
const destPath = file.isFile() && file.name.endsWith(".tpl") ? import_path.default.join(dest, file.name.substring(0, file.name.length - 4)) : import_path.default.join(dest, file.name);
|
|
128
120
|
if (file.isDirectory()) {
|
|
129
|
-
await fs.mkdir(destPath, {
|
|
130
|
-
recursive: true
|
|
131
|
-
});
|
|
121
|
+
await fs.mkdir(destPath, { recursive: true });
|
|
132
122
|
await this.processTplFolder(srcPath, destPath, data);
|
|
133
123
|
} else if (file.name.endsWith(".tpl")) {
|
|
134
124
|
await this.processTplFile(srcPath, destPath, {});
|
|
135
125
|
} else {
|
|
136
|
-
throw new Error(
|
|
126
|
+
throw new Error(
|
|
127
|
+
"unexpected non tpl file: " + srcPath + " " + file.name
|
|
128
|
+
);
|
|
137
129
|
}
|
|
138
130
|
}
|
|
139
131
|
}
|
|
140
132
|
async processTplFile(src, dest, data = {}) {
|
|
141
|
-
const compiledTemplate = import_handlebars.default.compile(
|
|
133
|
+
const compiledTemplate = import_handlebars.default.compile(
|
|
134
|
+
(await fs.readFile(src)).toString()
|
|
135
|
+
);
|
|
142
136
|
const template = await compiledTemplate(data);
|
|
143
137
|
await fs.writeFile(dest, template);
|
|
144
138
|
}
|