@blocklet/pages-kit-runtime 0.1.1
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/LICENSE +13 -0
- package/lib/cjs/block-studio/build-lib.js +95 -0
- package/lib/cjs/block-studio/generate-wrapper-code.js +123 -0
- package/lib/cjs/block-studio/init-resource-router.js +166 -0
- package/lib/cjs/block-studio/plugins/_theme.js +7 -0
- package/lib/cjs/block-studio/plugins/index.js +19 -0
- package/lib/cjs/block-studio/plugins/vite-plugin-block-studio.js +176 -0
- package/lib/cjs/block-studio/plugins/vite-plugin-html-transform.js +245 -0
- package/lib/cjs/block-studio/plugins/vite-plugin-remote-script-localizer.js +211 -0
- package/lib/cjs/block-studio/utils.js +53 -0
- package/lib/cjs/client.js +24 -0
- package/lib/cjs/components/create-resource.js +32 -0
- package/lib/cjs/components/index.js +17 -0
- package/lib/cjs/index.js +2 -0
- package/lib/cjs/tsconfig.tsbuildinfo +1 -0
- package/lib/cjs/types/index.js +5 -0
- package/lib/cjs/utils/index.js +1 -0
- package/lib/esm/block-studio/build-lib.js +89 -0
- package/lib/esm/block-studio/generate-wrapper-code.js +87 -0
- package/lib/esm/block-studio/init-resource-router.js +124 -0
- package/lib/esm/block-studio/plugins/_theme.js +4 -0
- package/lib/esm/block-studio/plugins/index.js +3 -0
- package/lib/esm/block-studio/plugins/vite-plugin-block-studio.js +140 -0
- package/lib/esm/block-studio/plugins/vite-plugin-html-transform.js +241 -0
- package/lib/esm/block-studio/plugins/vite-plugin-remote-script-localizer.js +175 -0
- package/lib/esm/block-studio/utils.js +43 -0
- package/lib/esm/client.js +17 -0
- package/lib/esm/components/create-resource.js +29 -0
- package/lib/esm/components/index.js +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/tsconfig.tsbuildinfo +1 -0
- package/lib/esm/types/index.js +2 -0
- package/lib/esm/utils/index.js +1 -0
- package/lib/types/block-studio/build-lib.d.ts +3 -0
- package/lib/types/block-studio/generate-wrapper-code.d.ts +5 -0
- package/lib/types/block-studio/init-resource-router.d.ts +5 -0
- package/lib/types/block-studio/plugins/_theme.d.ts +1 -0
- package/lib/types/block-studio/plugins/index.d.ts +3 -0
- package/lib/types/block-studio/plugins/vite-plugin-block-studio.d.ts +6 -0
- package/lib/types/block-studio/plugins/vite-plugin-html-transform.d.ts +5 -0
- package/lib/types/block-studio/plugins/vite-plugin-remote-script-localizer.d.ts +8 -0
- package/lib/types/block-studio/utils.d.ts +14 -0
- package/lib/types/client.d.ts +11 -0
- package/lib/types/components/create-resource.d.ts +7 -0
- package/lib/types/components/index.d.ts +1 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -0
- package/lib/types/types/index.d.ts +39 -0
- package/lib/types/utils/index.d.ts +0 -0
- package/package.json +169 -0
- package/tsconfig.json +13 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2018-2020 ArcBlock
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
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.buildLib = buildLib;
|
|
16
|
+
/* eslint-disable no-await-in-loop */
|
|
17
|
+
/* eslint-disable no-console */
|
|
18
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
19
|
+
const child_process_1 = require("child_process");
|
|
20
|
+
const utils_1 = require("./utils");
|
|
21
|
+
function buildLib(options) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
const workingDir = (options === null || options === void 0 ? void 0 : options.cwd) || process.cwd();
|
|
25
|
+
// Scan for all index files
|
|
26
|
+
const allBlocks = (0, utils_1.findComponentFiles)({ cwd: workingDir }).map((entry) => {
|
|
27
|
+
return entry.blockName;
|
|
28
|
+
});
|
|
29
|
+
const filterModules = process.argv.includes('--filter')
|
|
30
|
+
? (_a = process.argv[process.argv.indexOf('--filter') + 1]) === null || _a === void 0 ? void 0 : _a.split(',')
|
|
31
|
+
: ((_b = process.env.BLOCK_FILTER) === null || _b === void 0 ? void 0 : _b.split(',')) || null;
|
|
32
|
+
const ignoreViteLog = false; // process.argv.includes('--log') ? false : process.env.BLOCK_LOG !== 'true';
|
|
33
|
+
const multiMode = process.argv.includes('--multi') || process.env.BLOCK_MULTI === 'true';
|
|
34
|
+
const libDir = 'lib';
|
|
35
|
+
const blocks = allBlocks.filter((name) => !filterModules || filterModules.includes(name || ''));
|
|
36
|
+
if (!blocks.length) {
|
|
37
|
+
console.log(chalk_1.default.yellow('No blocks founds'));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// Clean up the lib directory
|
|
41
|
+
yield (0, child_process_1.execSync)(`rm -rf ${libDir}`, { cwd: workingDir });
|
|
42
|
+
console.log(chalk_1.default.gray('Clean up the lib directory'));
|
|
43
|
+
// Start to build
|
|
44
|
+
console.log(chalk_1.default.cyan(`Start to build ${blocks.length} blocks in parallel\n`));
|
|
45
|
+
const canBuildBlocks = multiMode ? blocks : [blocks.join(',')];
|
|
46
|
+
const configFile = 'vite-lib.config';
|
|
47
|
+
const hasConfig = (0, child_process_1.execSync)(`ls ${configFile}.* 2>/dev/null || true`, {
|
|
48
|
+
cwd: workingDir,
|
|
49
|
+
encoding: 'utf-8',
|
|
50
|
+
}).trim() !== '';
|
|
51
|
+
try {
|
|
52
|
+
yield Promise.all(canBuildBlocks.map((blockName) => {
|
|
53
|
+
console.log(chalk_1.default.blue(`Building ${blockName} Block...`));
|
|
54
|
+
return new Promise((resolve, reject) => {
|
|
55
|
+
const build = (0, child_process_1.spawn)('vite', [
|
|
56
|
+
'build',
|
|
57
|
+
'--filter',
|
|
58
|
+
`"${blockName}"`,
|
|
59
|
+
'--outDir',
|
|
60
|
+
libDir,
|
|
61
|
+
'--emptyOutDir=false',
|
|
62
|
+
hasConfig ? `--config ${configFile}.*` : '',
|
|
63
|
+
multiMode ? '--multi' : '',
|
|
64
|
+
], {
|
|
65
|
+
stdio: ignoreViteLog ? ['inherit', 'ignore', 'ignore'] : 'inherit',
|
|
66
|
+
shell: true,
|
|
67
|
+
cwd: workingDir,
|
|
68
|
+
});
|
|
69
|
+
build.on('close', (code) => {
|
|
70
|
+
if (code === 0) {
|
|
71
|
+
console.log(chalk_1.default.green(`Build ${blockName} successfully`));
|
|
72
|
+
resolve();
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
reject(new Error(`Build failed with code ${code}`));
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}));
|
|
80
|
+
console.log(chalk_1.default.green(`\nBuild ${blocks.length} blocks successfully`));
|
|
81
|
+
console.log(chalk_1.default.gray(`Generate the ${libDir} directory successfully`));
|
|
82
|
+
process.exit(0);
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
console.error(chalk_1.default.red('Build failed:'), err);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
const cwdArg = process.argv.indexOf('--cwd');
|
|
91
|
+
const cwd = cwdArg !== -1 ? process.argv[cwdArg + 1] : undefined;
|
|
92
|
+
buildLib({ cwd }).catch((err) => {
|
|
93
|
+
console.error(chalk_1.default.red('Build failed:'), err);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.generateWrapperCode = generateWrapperCode;
|
|
46
|
+
function generateWrapperCode(_a) {
|
|
47
|
+
return __awaiter(this, arguments, void 0, function* ({ project, state }) {
|
|
48
|
+
const projectName = (project.name || project.id).toLowerCase().replaceAll(/[^a-z0-9]/g, '_');
|
|
49
|
+
const packageName = `@pages-kit-project/${projectName}`;
|
|
50
|
+
const packageJson = JSON.stringify({
|
|
51
|
+
name: packageName,
|
|
52
|
+
version: '0.0.1',
|
|
53
|
+
main: 'index.cjs',
|
|
54
|
+
module: 'index.js',
|
|
55
|
+
types: 'index.d.ts',
|
|
56
|
+
peerDependencies: {
|
|
57
|
+
'@blocklet/pages-kit-runtime': 'latest',
|
|
58
|
+
},
|
|
59
|
+
dependencies: {
|
|
60
|
+
'@blocklet/pages-kit-runtime': 'latest',
|
|
61
|
+
'@blocklet/pages-kit': 'latest',
|
|
62
|
+
},
|
|
63
|
+
exports: {
|
|
64
|
+
'.': {
|
|
65
|
+
require: './index.cjs',
|
|
66
|
+
import: './index.js',
|
|
67
|
+
types: './index.d.ts',
|
|
68
|
+
},
|
|
69
|
+
'./client': {
|
|
70
|
+
require: './client.cjs',
|
|
71
|
+
import: './client.js',
|
|
72
|
+
types: './client.d.ts',
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
}, null, 2);
|
|
76
|
+
const index = `\
|
|
77
|
+
import { ProjectRuntime } from '@blocklet/pages-kit-runtime/client';
|
|
78
|
+
|
|
79
|
+
window.__PAGE_STATE__ = ${JSON.stringify(state, null, 2)};
|
|
80
|
+
window.__PROJECT_ID__ = "${project.id}";
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
const ${projectName} = new ProjectRuntime({
|
|
84
|
+
state: window.__PAGE_STATE__,
|
|
85
|
+
projectId: window.__PROJECT_ID__,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
export default ${projectName}
|
|
89
|
+
`;
|
|
90
|
+
const client = index;
|
|
91
|
+
const tsFiles = [
|
|
92
|
+
{ fileName: 'index.ts', content: index },
|
|
93
|
+
{ fileName: 'client.ts', content: client },
|
|
94
|
+
];
|
|
95
|
+
const ts = yield Promise.resolve().then(() => __importStar(require('typescript')));
|
|
96
|
+
const result = (yield Promise.all(tsFiles.map((_a) => __awaiter(this, [_a], void 0, function* ({ fileName, content }) {
|
|
97
|
+
const cjs = ts.transpileModule(content, {
|
|
98
|
+
fileName,
|
|
99
|
+
compilerOptions: { module: ts.ModuleKind.CommonJS },
|
|
100
|
+
});
|
|
101
|
+
const esm = ts.transpileModule(content, {
|
|
102
|
+
fileName,
|
|
103
|
+
compilerOptions: { module: ts.ModuleKind.ESNext },
|
|
104
|
+
});
|
|
105
|
+
return [
|
|
106
|
+
{
|
|
107
|
+
fileName: fileName.replace(/\.ts$/, '.cjs'),
|
|
108
|
+
content: cjs.outputText,
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
fileName: fileName.replace(/\.ts$/, '.js'),
|
|
112
|
+
content: esm.outputText,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
fileName: fileName.replace(/\.ts$/, '.d.ts'),
|
|
116
|
+
content,
|
|
117
|
+
},
|
|
118
|
+
];
|
|
119
|
+
})))).flat();
|
|
120
|
+
return [...result, { fileName: 'package.json', content: packageJson }];
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
exports.default = generateWrapperCode;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.initResourceRouter = void 0;
|
|
49
|
+
exports.copyFile = copyFile;
|
|
50
|
+
exports.copyDirectory = copyDirectory;
|
|
51
|
+
exports.copyRecursive = copyRecursive;
|
|
52
|
+
const component_1 = require("@blocklet/sdk/lib/component");
|
|
53
|
+
const child_process_1 = require("child_process");
|
|
54
|
+
const express_1 = require("express");
|
|
55
|
+
const fs_1 = __importDefault(require("fs"));
|
|
56
|
+
const path_1 = __importStar(require("path"));
|
|
57
|
+
const utils_1 = require("./utils");
|
|
58
|
+
const DID = 'z2qa7rr3eUyVnWp2PCxEVARuUfLFh6cE5V2xV';
|
|
59
|
+
const RESOURCE_TYPE = 'block';
|
|
60
|
+
const allTag = '@ALL_COMPONENTS';
|
|
61
|
+
function copyFile(src, dest) {
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
const readStream = fs_1.default.createReadStream(src);
|
|
64
|
+
const writeStream = fs_1.default.createWriteStream(dest);
|
|
65
|
+
readStream.on('error', reject);
|
|
66
|
+
writeStream.on('error', reject);
|
|
67
|
+
writeStream.on('finish', resolve);
|
|
68
|
+
readStream.pipe(writeStream);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function copyDirectory(src, dest) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
yield fs_1.default.promises.mkdir(dest, { recursive: true });
|
|
74
|
+
const entries = yield fs_1.default.promises.readdir(src, { withFileTypes: true });
|
|
75
|
+
for (const entry of entries) {
|
|
76
|
+
const srcPath = path_1.default.join(src, entry.name);
|
|
77
|
+
const destPath = path_1.default.join(dest, entry.name);
|
|
78
|
+
if (entry.isDirectory()) {
|
|
79
|
+
yield copyDirectory(srcPath, destPath);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
yield copyFile(srcPath, destPath);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function copyRecursive(src, dest) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
const srcStats = yield fs_1.default.promises.stat(src);
|
|
90
|
+
if (srcStats.isDirectory()) {
|
|
91
|
+
yield copyDirectory(src, dest);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
yield copyFile(src, dest);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
const getExportDir = (projectId, releaseId) => {
|
|
99
|
+
const exportDir = (0, component_1.getResourceExportDir)({ projectId, releaseId });
|
|
100
|
+
const dir = (0, path_1.join)(exportDir, DID, RESOURCE_TYPE);
|
|
101
|
+
return dir;
|
|
102
|
+
};
|
|
103
|
+
exports.initResourceRouter = (0, express_1.Router)();
|
|
104
|
+
exports.initResourceRouter.get('/resources', (_req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
|
+
const resources = [];
|
|
106
|
+
const rootDir = process.cwd();
|
|
107
|
+
const files = (0, utils_1.findComponentFiles)({ cwd: rootDir });
|
|
108
|
+
for (const file of files) {
|
|
109
|
+
// const filePath = path.join(rootDir, file);
|
|
110
|
+
// const fileContent = fs.readFileSync(filePath, 'utf8');
|
|
111
|
+
const { blockName } = file;
|
|
112
|
+
resources.push({
|
|
113
|
+
id: blockName,
|
|
114
|
+
name: blockName,
|
|
115
|
+
description: '',
|
|
116
|
+
images: [],
|
|
117
|
+
url: '',
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
res.json({
|
|
121
|
+
resources: [
|
|
122
|
+
{
|
|
123
|
+
id: allTag,
|
|
124
|
+
name: 'All Blocks',
|
|
125
|
+
description: 'Select All Blocks',
|
|
126
|
+
images: [],
|
|
127
|
+
url: '',
|
|
128
|
+
children: resources,
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
});
|
|
132
|
+
}));
|
|
133
|
+
exports.initResourceRouter.post('/resources', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
134
|
+
const { resources, projectId, releaseId } = req.body;
|
|
135
|
+
// ignore all tag
|
|
136
|
+
const componentIds = resources.filter((resource) => resource.id !== allTag);
|
|
137
|
+
try {
|
|
138
|
+
// Execute build command with filtered components
|
|
139
|
+
const buildProcess = (0, child_process_1.spawn)('pnpm', ['run', 'build-lib'], {
|
|
140
|
+
stdio: 'inherit',
|
|
141
|
+
shell: true,
|
|
142
|
+
env: Object.assign(Object.assign({}, process.env), { FORCE_COLOR: '1', BLOCK_FILTER: componentIds.join(',') }),
|
|
143
|
+
});
|
|
144
|
+
yield new Promise((resolve, reject) => {
|
|
145
|
+
buildProcess.on('close', (code) => {
|
|
146
|
+
if (code === 0)
|
|
147
|
+
resolve(null);
|
|
148
|
+
else
|
|
149
|
+
reject(new Error(`Build process exited with code ${code}`));
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
const dir = getExportDir(projectId, releaseId);
|
|
153
|
+
fs_1.default.rmSync(dir, { recursive: true, force: true });
|
|
154
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
155
|
+
const rootDir = process.cwd();
|
|
156
|
+
const tmpPackage = (0, path_1.join)(rootDir, 'lib');
|
|
157
|
+
yield copyRecursive(tmpPackage, dir);
|
|
158
|
+
fs_1.default.rmSync(tmpPackage, { recursive: true, force: true });
|
|
159
|
+
res.json({ success: true });
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
console.error('Build failed:', error);
|
|
163
|
+
res.status(500).json({ error: 'Build failed' });
|
|
164
|
+
}
|
|
165
|
+
}));
|
|
166
|
+
exports.default = exports.initResourceRouter;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./vite-plugin-block-studio"), exports);
|
|
18
|
+
__exportStar(require("./vite-plugin-html-transform"), exports);
|
|
19
|
+
__exportStar(require("./vite-plugin-remote-script-localizer"), exports);
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.initBlockStudioPlugins = initBlockStudioPlugins;
|
|
46
|
+
// eslint-disable-next-line import/no-unresolved
|
|
47
|
+
// import typescript from '@rollup/plugin-typescript';
|
|
48
|
+
const fs_1 = require("fs");
|
|
49
|
+
const path = __importStar(require("path"));
|
|
50
|
+
const vite_plugin_react_pages_1 = __importStar(require("vite-plugin-react-pages"));
|
|
51
|
+
const utils_1 = require("../utils");
|
|
52
|
+
const vite_plugin_html_transform_1 = require("./vite-plugin-html-transform");
|
|
53
|
+
// import initRemoteScriptLocalizerPlugin from './vite-plugin-remote-script-localizer';
|
|
54
|
+
function initBlockStudioPlugins(options) {
|
|
55
|
+
const workingDir = (options === null || options === void 0 ? void 0 : options.cwd) || process.cwd();
|
|
56
|
+
const entryFilesPattern = (options === null || options === void 0 ? void 0 : options.entryFilesPattern) || (0, utils_1.getBlockEntryFilesPattern)();
|
|
57
|
+
(0, utils_1.setBlockEntryFilesPattern)(entryFilesPattern);
|
|
58
|
+
// fallback to __dirname if _theme.tsx not exists
|
|
59
|
+
const pagesDir = (0, fs_1.existsSync)(path.join(workingDir, '_theme.tsx')) ? workingDir : __dirname.replace('cjs', 'esm');
|
|
60
|
+
utils_1.logger.log('initBlockStudioPlugins options', {
|
|
61
|
+
cwd: workingDir,
|
|
62
|
+
entryFilesPattern: (0, utils_1.getBlockEntryFilesPattern)(),
|
|
63
|
+
pagesDir,
|
|
64
|
+
});
|
|
65
|
+
return [
|
|
66
|
+
// {
|
|
67
|
+
// name: 'vite-plugin-block-studio-dev',
|
|
68
|
+
// enforce: 'pre',
|
|
69
|
+
// transformIndexHtml(html) {
|
|
70
|
+
// // Ensure required content exists in index.html
|
|
71
|
+
// if (!html.includes('<div id="root"></div>')) {
|
|
72
|
+
// html = html.replace(/<body[^>]*>/, '$&<div id="root"></div>');
|
|
73
|
+
// }
|
|
74
|
+
// if (!html.includes('/@pages-infra/main.js')) {
|
|
75
|
+
// html = html.replace('</body>', '<script type="module" src="/@pages-infra/main.js"></script></body>');
|
|
76
|
+
// }
|
|
77
|
+
// return html;
|
|
78
|
+
// },
|
|
79
|
+
// },
|
|
80
|
+
{
|
|
81
|
+
name: 'vite-plugin-block-studio-build',
|
|
82
|
+
enforce: 'pre',
|
|
83
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
84
|
+
config(_config) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
var _a;
|
|
87
|
+
const filterModules = process.argv.includes('--filter')
|
|
88
|
+
? (_a = process.argv[process.argv.indexOf('--filter') + 1]) === null || _a === void 0 ? void 0 : _a.split(',')
|
|
89
|
+
: null;
|
|
90
|
+
const multiMode = !!process.argv.includes('--multi');
|
|
91
|
+
const name = yield Promise.resolve(`${`${workingDir}/package.json`}`).then(s => __importStar(require(s))).then((res) => res.name).catch(() => 'MyLib');
|
|
92
|
+
return {
|
|
93
|
+
build: {
|
|
94
|
+
cssCodeSplit: false,
|
|
95
|
+
lib: {
|
|
96
|
+
name,
|
|
97
|
+
entry: Object.assign({}, Object.fromEntries((0, utils_1.findComponentFiles)({ cwd: workingDir })
|
|
98
|
+
.map((entry) => {
|
|
99
|
+
const { blockName } = entry;
|
|
100
|
+
const { isHtml } = entry;
|
|
101
|
+
const { file } = entry;
|
|
102
|
+
if (isHtml) {
|
|
103
|
+
return [blockName, `${vite_plugin_html_transform_1.VIRTUAL_MODULE_ID}?dir=${path.dirname(file)}`];
|
|
104
|
+
}
|
|
105
|
+
return [blockName, path.resolve(workingDir, file)];
|
|
106
|
+
})
|
|
107
|
+
.filter(Boolean)
|
|
108
|
+
.filter(([blockName]) => !filterModules || filterModules.includes(blockName || '')))),
|
|
109
|
+
// multiMode not support umd
|
|
110
|
+
formats: ['es', multiMode ? 'umd' : 'cjs'],
|
|
111
|
+
fileName: (format, entryName) => `${format}/${entryName}.js`,
|
|
112
|
+
},
|
|
113
|
+
rollupOptions: {
|
|
114
|
+
// make sure to externalize deps that shouldn't be bundled
|
|
115
|
+
// into your library
|
|
116
|
+
external: ['react', 'crypto'],
|
|
117
|
+
output: {
|
|
118
|
+
// Provide global variables to use in the UMD build
|
|
119
|
+
globals: {
|
|
120
|
+
react: 'React',
|
|
121
|
+
},
|
|
122
|
+
paths: {
|
|
123
|
+
// Redirect 'react' imports to '@blocklet/pages-kit/builtin/react'
|
|
124
|
+
// react: '@blocklet/pages-kit/builtin/react',
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
// @ts-ignore
|
|
134
|
+
(0, vite_plugin_react_pages_1.default)({
|
|
135
|
+
pagesDir,
|
|
136
|
+
pageStrategy: new vite_plugin_react_pages_1.DefaultPageStrategy({
|
|
137
|
+
extraFindPages: (_pagesDir, helpers) => __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
helpers.watchFiles(workingDir, (0, utils_1.getBlockEntryFilesPattern)(), function fileHandler(file, api) {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
const { relative, path: filePath } = file;
|
|
141
|
+
const isHtml = relative.endsWith('.html');
|
|
142
|
+
const blockName = (0, utils_1.getBlockName)(relative);
|
|
143
|
+
const pageId = `/${blockName}`;
|
|
144
|
+
api.addPageData({
|
|
145
|
+
pageId,
|
|
146
|
+
dataPath: isHtml ? `${vite_plugin_html_transform_1.VIRTUAL_MODULE_ID}?dir=${path.dirname(filePath)}` : filePath,
|
|
147
|
+
staticData: isHtml
|
|
148
|
+
? {
|
|
149
|
+
isHtmlPreview: true,
|
|
150
|
+
dataPath: filePath,
|
|
151
|
+
blockName,
|
|
152
|
+
}
|
|
153
|
+
: Object.assign(Object.assign({}, (yield helpers.extractStaticData(file))), { code: (0, fs_1.readFileSync)(file.path, 'utf-8'), dataPath: filePath, blockName }),
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}),
|
|
158
|
+
}),
|
|
159
|
+
}),
|
|
160
|
+
// https://github.com/rollup/plugins/tree/master/packages/typescript#noforceemit
|
|
161
|
+
// typescript({
|
|
162
|
+
// declaration: true,
|
|
163
|
+
// emitDeclarationOnly: true,
|
|
164
|
+
// noForceEmit: true,
|
|
165
|
+
// declarationDir: path.resolve(workingDir, 'lib/types'),
|
|
166
|
+
// rootDir: path.resolve(workingDir),
|
|
167
|
+
// }),
|
|
168
|
+
(0, vite_plugin_html_transform_1.initHtmlPreviewTransformPlugin)(),
|
|
169
|
+
// initRemoteScriptLocalizerPlugin({
|
|
170
|
+
// tempDir: 'temp/remote-scripts', // 可选,默认值
|
|
171
|
+
// maxConcurrent: 5, // 可选,默认值
|
|
172
|
+
// timeout: 30 * 1000, // 可选,默认值 30 秒
|
|
173
|
+
// }),
|
|
174
|
+
];
|
|
175
|
+
}
|
|
176
|
+
exports.default = initBlockStudioPlugins;
|