@entur/function-tools 0.0.1 → 0.0.3
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/README.md +2 -2
- package/bin/enturFunctions.js +1 -1
- package/lib/commands/build.js +2 -2
- package/lib/commands/deploy.js +3 -3
- package/lib/commands/start.js +3 -3
- package/lib/commands/unusedExports.js +13 -17
- package/lib/commands/utils.d.ts +18 -0
- package/lib/commands/utils.js +3 -5
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#
|
|
2
|
-
Ekstra verktøy for firebase
|
|
1
|
+
# function-tools
|
|
2
|
+
Ekstra verktøy for firebase functions
|
package/bin/enturFunctions.js
CHANGED
|
@@ -5,7 +5,7 @@ import { registerStart } from '../lib/commands/start.js';
|
|
|
5
5
|
import { registerUnusedExports } from '../lib/commands/unusedExports.js';
|
|
6
6
|
|
|
7
7
|
const program = new Command();
|
|
8
|
-
program.name("entur-firebase").description("A multi-command CLI built with commander").version("0.0.
|
|
8
|
+
program.name("entur-firebase").description("A multi-command CLI built with commander").version("0.0.3").option("-v, --verbose", "Enable verbose output");
|
|
9
9
|
registerBuild(program);
|
|
10
10
|
registerDeploy(program);
|
|
11
11
|
registerStart(program);
|
package/lib/commands/build.js
CHANGED
|
@@ -3,12 +3,12 @@ import { flattenDependencies, harmonizeDependencies, calculateDependencies } fro
|
|
|
3
3
|
import { cleanDir } from '../utils/fs.js';
|
|
4
4
|
import { readPackageJSON } from '../utils/packageJSON.js';
|
|
5
5
|
import { getWorkspacePackageNames } from '../utils/workspace.js';
|
|
6
|
-
import {
|
|
6
|
+
import { resolveProjectConfig } from './utils.js';
|
|
7
7
|
|
|
8
8
|
function registerBuild(program) {
|
|
9
9
|
program.command("build").description("Build the project").option("-o, --output-dir <dir>", "Output directory").action(async (options)=>{
|
|
10
10
|
try {
|
|
11
|
-
const { packageRoot, packageJSON, outputDir, pnpmWorkspaceYAML } = await
|
|
11
|
+
const { packageRoot, packageJSON, outputDir, pnpmWorkspaceYAML } = await resolveProjectConfig(options);
|
|
12
12
|
const { name, exports: exports$1 } = await readPackageJSON(packageJSON);
|
|
13
13
|
console.log("🧹 Cleaning dist folder");
|
|
14
14
|
await cleanDir(outputDir);
|
package/lib/commands/deploy.js
CHANGED
|
@@ -6,13 +6,13 @@ import { getFirebaseJSON, writeFirebaseJSON } from '../utils/firebase.js';
|
|
|
6
6
|
import { cleanDir, writeJSON } from '../utils/fs.js';
|
|
7
7
|
import { readPackageJSON, getPackageName, writePackageJSON } from '../utils/packageJSON.js';
|
|
8
8
|
import { getWorkspacePackageNames } from '../utils/workspace.js';
|
|
9
|
-
import {
|
|
9
|
+
import { resolveProjectConfig } from './utils.js';
|
|
10
10
|
|
|
11
11
|
function registerDeploy(program) {
|
|
12
12
|
program.command("deploy").description("Deploy the project").option("-o, --output-dir <dir>", "Output directory").option("-P, --project <project id or alias>", "Project id or alias").action(async (options)=>{
|
|
13
13
|
try {
|
|
14
|
-
const
|
|
15
|
-
await deploy(
|
|
14
|
+
const projectConfig = await resolveProjectConfig(options);
|
|
15
|
+
await deploy(projectConfig);
|
|
16
16
|
} catch (error) {
|
|
17
17
|
console.error(error);
|
|
18
18
|
process.exit(1);
|
package/lib/commands/start.js
CHANGED
|
@@ -5,13 +5,13 @@ import { getFirebaseJSON, writeFirebaseJSON } from '../utils/firebase.js';
|
|
|
5
5
|
import { cleanDir, writeJSON } from '../utils/fs.js';
|
|
6
6
|
import { readPackageJSON, getPackageName, writePackageJSON } from '../utils/packageJSON.js';
|
|
7
7
|
import { getWorkspacePackageNames } from '../utils/workspace.js';
|
|
8
|
-
import {
|
|
8
|
+
import { resolveProjectConfig } from './utils.js';
|
|
9
9
|
|
|
10
10
|
function registerStart(program) {
|
|
11
11
|
program.command("start").description("Start function emulator").option("-o, --output-dir <dir>", "Output directory").option("-P, --project <project id or alias>", "Project id or alias").action(async (options)=>{
|
|
12
12
|
try {
|
|
13
|
-
const
|
|
14
|
-
await start(
|
|
13
|
+
const projectConfig = await resolveProjectConfig(options);
|
|
14
|
+
await start(projectConfig);
|
|
15
15
|
} catch (error) {
|
|
16
16
|
console.error(error);
|
|
17
17
|
process.exit(1);
|
|
@@ -9,26 +9,27 @@ import { createResolver } from '../importExports/resolve.js';
|
|
|
9
9
|
import { createResolveImport } from '../importExports/resolveImports.js';
|
|
10
10
|
import { createReadFileDependencies, extractUnusedExports } from '../importExports/unused.js';
|
|
11
11
|
import { createCache } from '../importExports/utils.js';
|
|
12
|
-
import { createContext } from './utils.js';
|
|
13
12
|
|
|
14
13
|
function registerUnusedExports(program) {
|
|
15
|
-
program.command("unused-exports").description("Check for unused exports").
|
|
14
|
+
program.command("unused-exports").description("Check for unused exports").option("-i, --include <pattern...>", "Include glob pattern", [
|
|
15
|
+
"**/*.ts"
|
|
16
|
+
]).option("-e, --exclude <numbers...>", "Excude glob pattern", [
|
|
17
|
+
"**/node_modules"
|
|
18
|
+
]).option("--ignore <numbers...>", "Ignore glob pattern", []).option("--extensions <numbers...>", "File extensions to resolve", [
|
|
19
|
+
".ts"
|
|
20
|
+
]).action(async (options)=>{
|
|
16
21
|
try {
|
|
17
|
-
const
|
|
18
|
-
await unusedExports(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
extensions: [
|
|
22
|
-
".ts"
|
|
23
|
-
]
|
|
24
|
-
}, context);
|
|
22
|
+
const cwd = process.cwd();
|
|
23
|
+
await unusedExports(options.include, options.ignore, options.exclude, {
|
|
24
|
+
extensions: options.extensions
|
|
25
|
+
}, cwd);
|
|
25
26
|
} catch (error) {
|
|
26
27
|
console.error(error);
|
|
27
28
|
process.exit(1);
|
|
28
29
|
}
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
|
-
async function unusedExports(patterns, ignorePatterns, resolverOptions,
|
|
32
|
+
async function unusedExports(patterns, ignorePatterns, excludePatterns, resolverOptions, cwd) {
|
|
32
33
|
const resolver = createResolver({
|
|
33
34
|
conditionNames: [
|
|
34
35
|
"import",
|
|
@@ -40,15 +41,10 @@ async function unusedExports(patterns, ignorePatterns, resolverOptions, { cwd })
|
|
|
40
41
|
});
|
|
41
42
|
const resolveImport = createResolveImport(resolver, getFileExports, getFileProxyExports);
|
|
42
43
|
const readFileDependencies = createReadFileDependencies(getFileImports, getFileExports, resolveImport);
|
|
43
|
-
const exclude = [
|
|
44
|
-
"**/node_modules",
|
|
45
|
-
"tools/createPackage/template",
|
|
46
|
-
"tools/dependency/mocks"
|
|
47
|
-
];
|
|
48
44
|
const fileDependencies = [];
|
|
49
45
|
for await (const filePath of glob(patterns, {
|
|
50
46
|
cwd,
|
|
51
|
-
exclude
|
|
47
|
+
exclude: excludePatterns
|
|
52
48
|
})){
|
|
53
49
|
fileDependencies.push(await readFileDependencies(join(cwd, filePath)));
|
|
54
50
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type Options = {
|
|
2
|
+
outputDir?: string;
|
|
3
|
+
project?: string;
|
|
4
|
+
cwd?: string;
|
|
5
|
+
};
|
|
6
|
+
type ProjectConfig = {
|
|
7
|
+
pnpmWorkspaceYAML: URL;
|
|
8
|
+
packageJSON: URL;
|
|
9
|
+
outputDir: URL;
|
|
10
|
+
packageRoot: URL;
|
|
11
|
+
projectRoot: URL;
|
|
12
|
+
projectAlias: string;
|
|
13
|
+
projectId: string;
|
|
14
|
+
};
|
|
15
|
+
declare function resolveProjectConfig({ outputDir, project, cwd, }?: Options): Promise<ProjectConfig>;
|
|
16
|
+
|
|
17
|
+
export { resolveProjectConfig };
|
|
18
|
+
export type { ProjectConfig };
|
package/lib/commands/utils.js
CHANGED
|
@@ -2,8 +2,7 @@ import { pathToFileURL } from 'node:url';
|
|
|
2
2
|
import { findUp } from 'find-up-simple';
|
|
3
3
|
import { readJSON } from '../utils/fs.js';
|
|
4
4
|
|
|
5
|
-
async function
|
|
6
|
-
const cwd = process.cwd();
|
|
5
|
+
async function resolveProjectConfig({ outputDir = "dist", project, cwd = process.cwd() } = {}) {
|
|
7
6
|
const [pnpmWorkspacePath, packageJSONPath, firebaseRCPath] = await Promise.all([
|
|
8
7
|
findUp("pnpm-workspace.yaml", {
|
|
9
8
|
cwd
|
|
@@ -36,8 +35,7 @@ async function createContext({ outputDir = "dist", project } = {}) {
|
|
|
36
35
|
packageRoot: new URL("./", packageJSONUrl),
|
|
37
36
|
projectRoot: new URL("./", pnpmWorkspaceYAML),
|
|
38
37
|
projectAlias,
|
|
39
|
-
projectId
|
|
40
|
-
cwd
|
|
38
|
+
projectId
|
|
41
39
|
};
|
|
42
40
|
}
|
|
43
41
|
function getProjectAliasAndId({ default: defaultProjectId, ...projects }, project) {
|
|
@@ -70,4 +68,4 @@ function getProjectAliasAndId({ default: defaultProjectId, ...projects }, projec
|
|
|
70
68
|
throw new Error(`No project with alias or id ${project} found in .firebaserc`);
|
|
71
69
|
}
|
|
72
70
|
|
|
73
|
-
export {
|
|
71
|
+
export { resolveProjectConfig };
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED